![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
saeed
Joined: 07 Mar 2017 Posts: 10
|
multiple interrupt problem[solved] |
Posted: Sat Mar 18, 2017 11:37 pm |
|
|
Hi
I'm trying to use int_rb(for 4x4 keypad) and int_rda(for sim900a module) in my project. int_rda works well when int_rb is "not" present and i can send/receive data between mcu and gsm module. but when i enable int_rb, i receive garbage from gsm module.
int_rb works well when int_rda is present.
rows of keypad connected to rb4,....,rb7 and columns connected to rc0,...,rc3
Thanks in advance
MCU: pic18f452
CCS: v5.049
here is my code:
Code: |
#include <18f452.h>
#use delay(clock = 12000000)
#use rs232(baud=19200,xmit=PIN_C6,RCV=PIN_C7,parity=N,bits=8,ERRORS)
#fuses hs,nowdt
#include <lcd.c>
#define use_portd_lcd true
#define size_buffer 32
int1 rda,rb;
char receive[size_buffer];
int rda_counter;
#int_rda
void rda_isr(){
receive[rda_counter] = getc();
rda_counter = (rda_counter + 1)%size_buffer;
rda = true;
}
#int_rb
void rb_isr(){
clear_interrupt(int_rb);
rb = true;
delay_ms(10);
}
void main(){
lcd_init();
set_tris_b(0xFF);
set_tris_c(0b10000000);
output_low(PIN_C0);
output_low(PIN_C1);
output_low(PIN_C2);
output_low(PIN_C3);
enable_interrupts(int_rb);
enable_interrupts(int_rda);
enable_interrupts(global);
while(true){
printf("ATI\r"); // check gsm module model
delay_ms(100);
lcd_putc("\f");
lcd_gotoxy(1,1);
for(int i=0;i<size_buffer;i++){ // show received data from rs232
printf(lcd_putc,"%c",receive[i]);
}
if(rb){
rb = false;
lcd_putc("\fKey Pressed");
delay_ms(200);
}
delay_ms(20);
}
}
|
Last edited by saeed on Sun Mar 19, 2017 3:20 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19381
|
|
Posted: Sun Mar 19, 2017 1:39 am |
|
|
You cannot clear int_rb!!!.....
In fact this is unnecessary. The compiler clears interrupts when the handler is left, unless you specify 'NOCLEAR' in the interrupt definition.
However the point is that INT_RB _cannot be cleared, _until PortB is read_.
INT_RB is an interrupt saying that the PortB 'read latch' does not match the contents of PortB. This 'read Latch' is set whenever PortB is read.
So you _must_ read PortB, to set this latch, or INT_RB will keep resetting for ever.
Also, separately you have the problem of putting a delay in an interrupt. Don't....
First, remember that at 19200bps, a 10mSec delay is 20 character times. Once you are in an interrupt handler another interrupt cannot trigger.
Then with a delay in the interrupt, you will be getting a warning 'interrupts disabled to prevent re-entrancy', on the delay in the main code.
So two major problems... |
|
![](templates/subSilver/images/spacer.gif) |
saeed
Joined: 07 Mar 2017 Posts: 10
|
|
Posted: Sun Mar 19, 2017 3:19 am |
|
|
Thank you Ttelmah
I remove the delay in int_rb and code is working now.
![Very Happy](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|