943,712 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1084
  • C RSS
Jun 8th, 2009
0

8052 Serial Interrupt

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
grandalf62 is offline Offline
8 posts
since Apr 2009
Jun 8th, 2009
0

Re: 8052 Serial Interrupt

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Jun 8th, 2009
0

Re: 8052 Serial Interrupt

You're not trying to call printf() INSIDE the ISR are you?
Because that's a really bad idea.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jun 8th, 2009
0

Re: 8052 Serial Interrupt

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);
Reputation Points: 78
Solved Threads: 22
Posting Whiz
Colin Mac is offline Offline
327 posts
since Sep 2006
Jun 9th, 2009
0

Re: 8052 Serial Interrupt

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
grandalf62 is offline Offline
8 posts
since Apr 2009
Jun 9th, 2009
0

Re: 8052 Serial Interrupt

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.
Reputation Points: 78
Solved Threads: 22
Posting Whiz
Colin Mac is offline Offline
327 posts
since Sep 2006
Jun 10th, 2009
0

Re: 8052 Serial Interrupt

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
grandalf62 is offline Offline
8 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: parsing word by word based on condition
Next Thread in C Forum Timeline: Concatenate in C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC