Hello.
I spent a entire afternoon in trying to get en interrupt on a PIC18F4420 on portb,2 working.
At portb,2 I have the IRQ pin of an nRF24L01 attached. So, this pin drives low when data is received and I would like that the program jumps to the void interrupt(void) routine.
For test purpose the program stays for ever in the interrupt function.
With my code the int2if flag gets high before a change of portb,2 occurs, but the idea is that the interrupt happens if the pin is pulled down.
To configure the PIC I made an init function:
.
void init(){
osccon = 01110000b; // internal oscillator at 8 MHz.
while (!iofs); // iofs OSCCON stable bit.
adcon1 |= 0x0F; // All digital IO's, no analog ports required.
trisb = 00000100b; // PortB, RB2 In, used to provoke an interrupt.
intcon = INTCON_CONF; // 11101000b, GIE/PEIE enabled, PortB interrupt on change enabled, TMR0IE enabled,
rcon = RCON_CONF; // 00011100b, interrupt priority disabled.
intcon3 = INTCON3_CONF; // 10010000b INT2IP enabled, RB2, INT2IE, enabled.
intcon2 = INTCON2_CONF; // 00000001b Pullup enabled, Interrupt RB2 falling edge, High priority.
}
void interrupt(void){
char aux = portb;
if (int2if){ // to see if something happens.
while(1);
}
}
Thanks Martin
Interrupt_on Portb.c