|
|
View previous topic :: View next topic |
Author |
Message |
koirnaos
Joined: 23 Dec 2009 Posts: 6
|
interrupts problem |
Posted: Tue Jan 25, 2011 9:20 am |
|
|
I want to use timer0 in my code and i got this warning:
Code: | Interrupts disabled during call to prevent re-entrancy |
Here is my code:
Code: |
#include <16F877A.h>
#include <stdio.h>
#include <string.h>
#fuses XT,NOWDT,PUT,NOBROWNOUT,NOLVP
#use delay(clock=4000000)
#define INTS_PER_SECOND 15
#byte PORTB = 0x06
#byte PORTA = 0x05
#include <lcd_flex.c>
#include <flex_kbrd_test.h>
int count = INTS_PER_SECOND;
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#int_timer0
void timer0isr(){
count--;
if(count==0) {
count = INTS_PER_SECOND;
if(initial==ans[1]){
gsm();
}
if(s==ans[0]){
printf("AT+CMGD=%c", car);
putc(0x0D);
for(i=0;i<16;i++){
res1[i]=getc();
}
output_low(PIN_A4);
output_low(PIN_A4);
//delay_ms(1200);
}
}
}
void main() {
char input = 0;
lcd_init();
lcd_putc( LOGIN_TEXT );
initial=ans[0];
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
while(TRUE) {
input = kbd_getc();
if( input != 0 )
handleInput( input );
}
} |
Is there another way to use the gsm function in my interrupt without having this warning?
I tried making gsm() function an inline one but it didn't work, same warning.
Then I made another function gsm_isr(), copied the gsm() function inside the new one and call it in the timer0_isr, same problem.
What am I doing wrong? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Jan 25, 2011 10:47 am |
|
|
At the end of the day, set a flag, get out of the interrupt, and do just about _everything_ you have in the interrupt, outside.
Your print for example, will take just on 9mSec to execute.
Then you put another character. 1mSec.
Then you wait for 16 characters. _Even if these are arriving without pause_, another 16mSec.
The odds are that the GSM module will take significant time to reply, making this even worse.
If you want to fire a trigger string to the module from the timer, then use interrupt buffered serial transmit and receive code. In the interrupt, just put the 'send' bytes into the output code, then have the receive code set a flag when 16 characters are in the RX buffer. In your main, process the string, when this is seen
However always 'beware' of just character counting. Remember things can be missed. As currently shown, if there are not 16 characters after the transmission, the code would hang for ever....
As for the error, I'd guess (since you don't show it), that the 'gsm' routine, calls something else, that is also used in your main, or in HandleInput. This is the reason for the error message, but the fundamental 'problem' is trying to do far to much in the interrupt handler...
Best Wishes |
|
|
|
|
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
|