View previous topic :: View next topic |
Author |
Message |
metin
Joined: 14 Jul 2008 Posts: 1
|
multiple interrupts Help ! #int_timer0 and #int_rda |
Posted: Wed Jul 16, 2008 3:55 pm |
|
|
Hi;
I try to use #int_timer0 and #int_rda in serial communication ,
I use #int_timer0 interrupt for flash the led it is work well, and serial communication work well but when I start to write string from PC, led is stop to flashing,
how can I use multiple interrupts #int_timer0 and #int_rda, the led can be flashing when #int_rda was working! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 16, 2008 4:01 pm |
|
|
I suspect that you have copied some bad newbie code that you found
on this forum. In this typical newbie code, they use a for() loop or the
gets() function within the #int_rda routine. When they get the first
interrupt, they stay inside the interrupt routine for a long time. That's
not the correct way to do it. Just get one character during each
interrupt. See the CCS example file, Ex_sisr.c for an example of how
to get one character per interrupt, and save the characters in a circular
buffer. |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Thu Jul 17, 2008 3:45 pm |
|
|
Better still, make the timer your only interrupt. Set it up so that it occurs faster than characters can ever arrive on the serial port, and poll the character-waiting (RCIF) flag in the interrupt and read the port if necessary. If you want a slower clock rate to flash an LED, divide your fast clock down appropriately. That way, you've got a rock-solid timer running, which won't have deviations when characters come in on the serial port. Oh yeah, either plan on processing each character really fast, or buffer them and deal with the buffer in your main() routine, outside the interrupt. I do this all the time and I think it saves a lot of hassle. |
|
|
|