View previous topic :: View next topic |
Author |
Message |
Frank Guest
|
Service UART interrupts while inside a timer interrupt? |
Posted: Thu Nov 15, 2001 7:54 am |
|
|
Anyone know if it is possible to service UART interrupts while inside a timer interrupt?
Thanks
-Frank
___________________________
This message was ported from CCS's old forum
Original Post ID: 1122 |
|
|
RT Guest
|
Re: Service UART interrupts while inside a timer interrupt? |
Posted: Thu Nov 15, 2001 9:46 am |
|
|
:=Anyone know if it is possible to service UART interrupts while inside a timer interrupt?
:=
:=Thanks
:=
:=-Frank
I'm not positive, but I really don't think you can. I tried it with a scope to test the UART signals while in a really long TIMER2 ISR, and it didn't seem to transmit or receive.
___________________________
This message was ported from CCS's old forum
Original Post ID: 1124 |
|
|
Richard Henry Guest
|
Re: Service UART interrupts while inside a timer interrupt? |
Posted: Thu Nov 15, 2001 11:02 am |
|
|
:=Anyone know if it is possible to service UART interrupts while inside a timer interrupt?
:=
:=Thanks
:=
:=-Frank
If your timer interrupt is fast enough, you can eliminate the UART interrupts altogether. By "fast enough" I mean occur quicker than the character rate for the current UART settings. For 9600 bps, that is about one millisecond. What I have done in a similar situation is add a check of the UART status register at the end of the timer ISR, and call a service routine for the UART if needed. To keep the timing clean, whatever you do with the UART in that routine must not exceed the timer period less the time already expended in the timer ISR.
___________________________
This message was ported from CCS's old forum
Original Post ID: 1125 |
|
|
Tomi Guest
|
Re: Service UART interrupts while inside a timer interrupt? |
Posted: Thu Nov 15, 2001 11:16 am |
|
|
If you are talking about 12C/16C/16F devices the answer is no.
These devices have one-level IT and the Interrupt Enable bit is cleared automatically when an IT occurs.
Keep your ISR as short as possible.
However, if you need to use long-time ISRs (you don't have other way), you can use a "hand-made" method to poll the UART IF bit (the IT bits are set on the IT condition regardless of the state of the GIE bit):
/* you can call this function from both UART ISR and other */
#separate
void GetaByte()
{
ReadTheByte();
SaveItToAnArray();
ClearRCIFBit(); // extra instruction if ISR is executed
}
#int_rda
void __intrda()
{
GetaByte();
}
And you can poll sometimes the UART in your other ISR, e.g.:
#int_xxx
void __ISRxxx()
{
DoSomething();
OtherCode();
if (kbhit()) GetaByte();
MoreCode();
AndOthers();
if (kbhit()) GetaByte();
etc.
}
The time between the consecutive calls to GetaByte() and the time from the last call to the RETURN instruction must be less than the byte time (regarding from baud rate, e.g. cca. 1ms@9600Bd).
:=Anyone know if it is possible to service UART interrupts while inside a timer interrupt?
:=
:=Thanks
:=
:=-Frank
___________________________
This message was ported from CCS's old forum
Original Post ID: 1128 |
|
|
Frank Guest
|
Re: Service UART interrupts while inside a timer interrupt? |
Posted: Thu Nov 15, 2001 7:14 pm |
|
|
Thanks Tomi, that looks like a very good solution.
Also, I’m planning to use the PIC18C452.
-Frank
:=If you are talking about 12C/16C/16F devices the answer is no.
:=These devices have one-level IT and the Interrupt Enable bit is cleared automatically when an IT occurs.
:=Keep your ISR as short as possible.
:=However, if you need to use long-time ISRs (you don't have other way), you can use a "hand-made" method to poll the UART IF bit (the IT bits are set on the IT condition regardless of the state of the GIE bit):
:=/* you can call this function from both UART ISR and other */
:=#separate
:=void GetaByte()
:={
:=ReadTheByte();
:=SaveItToAnArray();
:=ClearRCIFBit(); // extra instruction if ISR is executed
:=}
:=
:=#int_rda
:=void __intrda()
:={
:=GetaByte();
:=}
:=
:=And you can poll sometimes the UART in your other ISR, e.g.:
:=
:=#int_xxx
:=void __ISRxxx()
:={
:=DoSomething();
:=OtherCode();
:=if (kbhit()) GetaByte();
:=MoreCode();
:=AndOthers();
:=if (kbhit()) GetaByte();
:=etc.
:=}
:=The time between the consecutive calls to GetaByte() and the time from the last call to the RETURN instruction must be less than the byte time (regarding from baud rate, e.g. cca. 1ms@9600Bd).
:=
:=:=Anyone know if it is possible to service UART interrupts while inside a timer interrupt?
:=:=
:=:=Thanks
:=:=
:=:=-Frank
___________________________
This message was ported from CCS's old forum
Original Post ID: 1134 |
|
|
Frank Guest
|
Re: Service UART interrupts while inside a timer interrupt? |
Posted: Thu Nov 15, 2001 7:17 pm |
|
|
RT, Thanks for the quick test
-Frank
:=:=Anyone know if it is possible to service UART interrupts while inside a timer interrupt?
:=:=
:=:=Thanks
:=:=
:=:=-Frank
:=
:=I'm not positive, but I really don't think you can. I tried it with a scope to test the UART signals while in a really long TIMER2 ISR, and it didn't seem to transmit or receive.
___________________________
This message was ported from CCS's old forum
Original Post ID: 1135 |
|
|
Frank Guest
|
Re: Service UART interrupts while inside a timer interrupt? |
Posted: Thu Nov 15, 2001 7:21 pm |
|
|
Richard, that’s a good idea but my serial data is to fast.
Thanks
-Frank
:=:=Anyone know if it is possible to service UART interrupts while inside a timer interrupt?
:=:=
:=:=Thanks
:=:=
:=:=-Frank
:=
:=If your timer interrupt is fast enough, you can eliminate the UART interrupts altogether. By "fast enough" I mean occur quicker than the character rate for the current UART settings. For 9600 bps, that is about one millisecond. What I have done in a similar situation is add a check of the UART status register at the end of the timer ISR, and call a service routine for the UART if needed. To keep the timing clean, whatever you do with the UART in that routine must not exceed the timer period less the time already expended in the timer ISR.
:=
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 1136 |
|
|
|