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

delay in a isr

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



Joined: 23 Apr 2004
Posts: 14
Location: Pescara (Italy)

View user's profile Send private message

delay in a isr
PostPosted: Tue Oct 12, 2004 3:59 am     Reply with quote

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: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Oct 12, 2004 5:16 am     Reply with quote

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







PostPosted: Tue Oct 12, 2004 5:21 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue Oct 12, 2004 6:18 pm     Reply with quote

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).
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