| | |
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 * ansi array arrays asterisks binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop function getlogicaldrivestrin givemetehcodez grade gtkwinlinux histogram homework i/o ide inches include infiniteloop input interest intmain() iso keyboard km license linked linkedlist linux list looping lowest matrix meter microsoft mysql number oddnumber open opendocumentformat openwebfoundation pdf pointer posix power probleminc process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing scheduling segmentationfault send sequential single socket socketprogramming stack standard strchr string suggestions systemcall test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






