View previous topic :: View next topic |
Author |
Message |
Lorenzo
Joined: 23 Apr 2004 Posts: 14 Location: Pescara (Italy)
|
delay in a isr |
Posted: Tue Oct 12, 2004 3:59 am |
|
|
I use PCW 3.157 and I have a problem with interrupts:
these don't work if I add delay_ms() function in a isr.
This works:
Code: |
#int_RDA
isr_RDA(){
....
}
|
This doesn't work:
Code: |
#int_RDA
isr_RDA(){
....
delay_ms(1);
}
|
|
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Tue Oct 12, 2004 5:16 am |
|
|
The code produced by the CCS compiler is non reentrant. This means if delay_ms() is used in the program body, the interrupt handler cannot also call delay_ms. The way CCS handles this is with delay_ms() is if you have used in in the interrupt handler then it adds a disable interrupt into the delay_ms function called outside the interrupt handler.
Solution - do not use delay_ms() inside the interrupt handler |
|
|
Ttelmah Guest
|
|
Posted: Tue Oct 12, 2004 5:21 am |
|
|
asmallri wrote: | The code produced by the CCS compiler is non reentrant. This means if delay_ms() is used in the program body, the interrupt handler cannot also call delay_ms. The way CCS handles this is with delay_ms() is if you have used in in the interrupt handler then it adds a disable interrupt into the delay_ms function called outside the interrupt handler.
Solution - do not use delay_ms() inside the interrupt handler |
Also, adding a 1mSec delay in an serial receive ISR, assuming a reasonable data rate, like 9600bps, is asking for the UART to overrun. A general rule of thumb about ISR's, which applies on any processor, is to allways make the handler as fast as possible.
If you want to wait for 1mSec after a character is received, have the ISR, trigger a hardware timer, which itself interrupts 1mSec latter.
Best Wishes |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Oct 12, 2004 6:18 pm |
|
|
Quote: | Also, adding a 1mSec delay in an serial receive ISR, assuming a reasonable data rate, like 9600bps, is asking for the UART to overrun |
The overrun error that RJ is talking about will prevent further reception until the error is handled. This can be with the ERRORS parameter or by handling the CREN bit yourself (read the datasheet). |
|
|
|