Kylobeetle
Member
Hello guys... some of you have helped me in my 1st post some weeks ago, im very thankful with that.
While my work lets me, im studying and doing some lil practices and I have encounter this problem that i will show below.
Im trying to work with interrupt, specially talking about uart interrupt i have made this simply program and my scope was to stay in the while(1) until some character was recieved (in this case an "ok") and then excuse some leds combination, then come back to the loop. rinse and repeat .. My problem is that I was aware that the interrupts could queue and in effect when the leds code is being executed, if you type again "ok" it will "queue" as soon it finishes it will make valid that "ok" and if you spam it, the program will freeze. Im kind of aware about the buffer overflow , with my own logic i tried to prevent this issue like this
(im about to leave and not plenty of time, if needed i can provide it, in the meanwhile, connecting through usart, making the interrupt work and others wasnt a problem.
void interrupt ISR()
{
INTCON = 0x00; //disabling
PIE1 = 0x00; //disabling
UART_Read_Text(2); // reading "ok" or any other 2 characters word (at the end it will add \0)
UART_Write_Text(rec); // print in my temrinal what it got to make myself clear that its working (this is working without problems)
__delay_ms(1000);
PORTB = 0b00000001; //leds combination just for test.
__delay_ms(1000);
PORTB = 0b00000010;
__delay_ms(1000);
PORTB = 0b00000100;
__delay_ms(1000);
PORTB = 0b00000111;
__delay_ms(1000);
PORTB = 0b00000000;
}
int main() {
TRISB = 0x00; // B as output
PORTB = 0x01; // B0 "on" for pilot purposes
OPTION_REG = 0X07;
usart_init(); // UART init module
while(1){
PORTB = 0x01;
RCREG = buff; // my try to empty the register
RCREG = buff; // my try to empty the register
__delay_ms(300);
INTCON = 0b11000000; //enabling my interrupts flags
PIE1 = 0b00100000; // //enabling my interrupts flags
PORTB = 0b00000000; // //enabling my interrupts flags
}
}
so i wanted to know how can i interrupt via usart and while the program is in process or running , how prevent the interrupt to queue again while the 1st interrupt hasnt finished yet .. i tried to keep alive the flags in the while(1) until the ISR is called to turn them off to prevent further interrupts but is not working, they are queuing . thanks in advance!
for the record i have tried to look for a similar problem with no results. I used PIC16F877A with MPLAB X XC8 compiler (last version), 4Mhz, and its configuration bits. i just tried to resume it to focus on the concept of the interrupts.
While my work lets me, im studying and doing some lil practices and I have encounter this problem that i will show below.
Im trying to work with interrupt, specially talking about uart interrupt i have made this simply program and my scope was to stay in the while(1) until some character was recieved (in this case an "ok") and then excuse some leds combination, then come back to the loop. rinse and repeat .. My problem is that I was aware that the interrupts could queue and in effect when the leds code is being executed, if you type again "ok" it will "queue" as soon it finishes it will make valid that "ok" and if you spam it, the program will freeze. Im kind of aware about the buffer overflow , with my own logic i tried to prevent this issue like this
(im about to leave and not plenty of time, if needed i can provide it, in the meanwhile, connecting through usart, making the interrupt work and others wasnt a problem.
void interrupt ISR()
{
INTCON = 0x00; //disabling
PIE1 = 0x00; //disabling
UART_Read_Text(2); // reading "ok" or any other 2 characters word (at the end it will add \0)
UART_Write_Text(rec); // print in my temrinal what it got to make myself clear that its working (this is working without problems)
__delay_ms(1000);
PORTB = 0b00000001; //leds combination just for test.
__delay_ms(1000);
PORTB = 0b00000010;
__delay_ms(1000);
PORTB = 0b00000100;
__delay_ms(1000);
PORTB = 0b00000111;
__delay_ms(1000);
PORTB = 0b00000000;
}
int main() {
TRISB = 0x00; // B as output
PORTB = 0x01; // B0 "on" for pilot purposes
OPTION_REG = 0X07;
usart_init(); // UART init module
while(1){
PORTB = 0x01;
RCREG = buff; // my try to empty the register
RCREG = buff; // my try to empty the register
__delay_ms(300);
INTCON = 0b11000000; //enabling my interrupts flags
PIE1 = 0b00100000; // //enabling my interrupts flags
PORTB = 0b00000000; // //enabling my interrupts flags
}
}
so i wanted to know how can i interrupt via usart and while the program is in process or running , how prevent the interrupt to queue again while the 1st interrupt hasnt finished yet .. i tried to keep alive the flags in the while(1) until the ISR is called to turn them off to prevent further interrupts but is not working, they are queuing . thanks in advance!
for the record i have tried to look for a similar problem with no results. I used PIC16F877A with MPLAB X XC8 compiler (last version), 4Mhz, and its configuration bits. i just tried to resume it to focus on the concept of the interrupts.