CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Service UART interrupts while inside a timer interrupt?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Frank
Guest







Service UART interrupts while inside a timer interrupt?
PostPosted: Thu Nov 15, 2001 7:54 am     Reply with quote

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?
PostPosted: Thu Nov 15, 2001 9:46 am     Reply with quote

:=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?
PostPosted: Thu Nov 15, 2001 11:02 am     Reply with quote

:=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?
PostPosted: Thu Nov 15, 2001 11:16 am     Reply with quote

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?
PostPosted: Thu Nov 15, 2001 7:14 pm     Reply with quote

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?
PostPosted: Thu Nov 15, 2001 7:17 pm     Reply with quote

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?
PostPosted: Thu Nov 15, 2001 7:21 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group