| | |
8052 Serial Interrupt
![]() |
•
•
Join Date: Apr 2009
Posts: 8
Reputation:
Solved Threads: 0
This may be be a silly question, but its baffling me. If I set up a receive interrupt, process the data and clear the flag. All works well. The problem is I need to use printf. I realize that this will of course also generate an interrupt, I handle this within the interrupt with if(TI)TI=0; hoping at worst it will just slow down printing. However this does not work, as soon as I try to print, all manner of strange erratic things happen. I had thought of disabling serial interrupt before a print statement, and re-enabling after, but at 300 baud (3-4 Secs) I could possibly miss a character. I cannot use full blown interrupt driven coms, due to lack of memory, rtos is also ruled out for the same reason. Any advice most gratefully received.
•
•
Join Date: Sep 2006
Posts: 327
Reputation:
Solved Threads: 22
Depends how printf is implemented in your compiler. In Keil, TI must
be set before printf is called. The is because of how putchar is implemented (which is called by printf.)
be set before printf is called. The is because of how putchar is implemented (which is called by printf.)
C Syntax (Toggle Plain Text)
while (!TI); TI = 0; return (SBUF = c);
•
•
Join Date: Sep 2006
Posts: 327
Reputation:
Solved Threads: 22
What I posted is a segment of code from putchar.c which you can find in the lib folder.
printf won't work the way you posted because TI needs to be set before calling printf. You usually set TI once at the beginning of the program and then not worry about it again.
I'm pretty sure you won't be able to use a receive interrupt and call printf as is throughout the program because the ISR will execute over and over if TI or RI is not cleared in the ISR. You will have to come up with something yourself.
printf won't work the way you posted because TI needs to be set before calling printf. You usually set TI once at the beginning of the program and then not worry about it again.
I'm pretty sure you won't be able to use a receive interrupt and call printf as is throughout the program because the ISR will execute over and over if TI or RI is not cleared in the ISR. You will have to come up with something yourself.
Last edited by Colin Mac; Jun 9th, 2009 at 3:57 pm.
![]() |
Similar Threads
- reading data using serial port (Visual Basic 4 / 5 / 6)
- Reading data from a serial port (Legacy and Other Languages)
- C serial com port terminal program (C)
- Serial Port (C++)
- IDE (Ultra ATA) to Serial ATA Adapter..How/Will it work. (Storage)
- Serial Console to work on FreeBSD (*nix Hardware Configuration)
- Serial ATA Raid (Apple Hardware)
Other Threads in the C Forum
- Previous Thread: parsing word by word based on condition
- Next Thread: Concatenate in C
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf open openwebfoundation owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling segmentationfault send sequential shape socket socketprograming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h






