8052 Serial Interrupt

Reply

Join Date: Apr 2009
Posts: 8
Reputation: grandalf62 is an unknown quantity at this point 
Solved Threads: 0
grandalf62 grandalf62 is offline Offline
Newbie Poster

8052 Serial Interrupt

 
0
  #1
Jun 8th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,375
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: 8052 Serial Interrupt

 
0
  #2
Jun 8th, 2009
That operating system and compiler are you using? In my MS-DOS 6.X days I had no conflicts between serial port interrups and printf(). I just wrote a serial port driver (supported 1 to 40 serial ports) that was TSR and the rest of the program ran normally, within the memory constraints of MS-DOS.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: 8052 Serial Interrupt

 
0
  #3
Jun 8th, 2009
You're not trying to call printf() INSIDE the ISR are you?
Because that's a really bad idea.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 327
Reputation: Colin Mac is on a distinguished road 
Solved Threads: 22
Colin Mac Colin Mac is offline Offline
Posting Whiz

Re: 8052 Serial Interrupt

 
0
  #4
Jun 8th, 2009
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.)
  1. while (!TI);
  2. TI = 0;
  3. return (SBUF = c);
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 8
Reputation: grandalf62 is an unknown quantity at this point 
Solved Threads: 0
grandalf62 grandalf62 is offline Offline
Newbie Poster

Re: 8052 Serial Interrupt

 
0
  #5
Jun 9th, 2009
Thanks guys,

It is Keil, and I am not calling printf from within the isr. Colin Mac, is this what you mean I could try.

[

while (!TI);
TI=0;
printf("blahblahblah");

]
And would I still need to clear TI in the isr?
Many thanks
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 327
Reputation: Colin Mac is on a distinguished road 
Solved Threads: 22
Colin Mac Colin Mac is offline Offline
Posting Whiz

Re: 8052 Serial Interrupt

 
0
  #6
Jun 9th, 2009
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.
Last edited by Colin Mac; Jun 9th, 2009 at 3:57 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 8
Reputation: grandalf62 is an unknown quantity at this point 
Solved Threads: 0
grandalf62 grandalf62 is offline Offline
Newbie Poster

Re: 8052 Serial Interrupt

 
0
  #7
Jun 10th, 2009
Again thank you for the advice. TI and RI are cleared in the interrupt, but it seems to make no difference. I have found that with software tidying up, I can poll RI reasonably quickly. Probably not ideal, but will see how it pans out in practice, may well be ok.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC