ATMega1284p External Interrupt 2 Setup
2012-03-13 by Chuck Hackett
I am trying to enable external interrupt 2 to trigger on a falling edge on an ATMega1284p but I am unable to get the proper bits in the EICRA register. I'm using the following: (1) EIMSK &= ~_BV( INT2 ); // Disable external interrupt 2 (2) EICRA &= ~(_BV( ISC21 ) | _BV( ISC20 )); // Clear the external interrupt 2 control bits (3) EICRA |= (_BV( ISC21 ) /*| _BV( ISC20 )*/); // Setup interrupt 2 for interrupt on falling edge (4) EIFR |= _BV( INTF2 ); // Clear any pending interrupt (5) EIMSK |= _BV( INT2 ); // Enable external interrupt 2 (Yes, I know that lines 2 & 3 can be combined but I split them in an attempt to diagnose the problem) A JTAG breakpoint at line 4 shows the EICRA register unchanged from its initial value of 0x00 ... ISC21 has a value of "5" ... Even if I replace line 3 with "EICRA = 32" the register remains unchanged ... When I look at the disassembled code it appears to be storing to location 0x69 (the EICRA reg) ... It is as though there is some control bit that I have to turn on to enable changes to the EICRA register ... Note: at this time Global Interrupt Enable happens to be disabled (it is enabled later in the code). This is code that is being converted from an ATMega32 where it is working fine just using: GICR |= _BV( INT2 ); // Enable interrupt on (default) falling edge of external interrupt 2 I know that this has to be something simple and I've read the datasheet section on external interrupts over and over. Can someone point out where I'm going wrong? Cheers, Chuck Hackett "Good judgment comes from experience, experience comes from bad judgment" 7.5" gauge Union Pacific Northern (4-8-4) 844 http://www.whitetrout.net/Chuck