ATMEGA644, GCC Compiler. I can't get this test program working. The Interrupt does not appear to be firing. The value of NumChanges is alway equal to 0x00.
I have a function generator and scope on PA0 so I know the pin is physically changing.
I may be setting up the interrupt wrong? Any help would be greatly appreciate. Thanks.
// THIS CODE *DOES NOT* WORK PROPERLY #include#include #define F_CPU 20000000UL volatile unsigned int NumChanges; ISR(PCINT0_vect) { NumChanges = NumChanges + 1; } int main (void) { // PORTA // Pin40, PA0: Input, // Pin39, PA1: Output, // Pins: 76543210 // Values: 00000010 0x02 DDRA = 0x02; // PORTB // Pin1, PB0: Output, LED // Pins: 76543210 // Values: 00000001 0x01 DDRB = 0x01; //Enable Pin Change Interrupt on TxIn Pin PA1 PCMSK0 |= (PCMSK0 << PCINT0); PCICR |= (PCICR << PCIE0); sei(); while(NumChanges < 50) { //Collect Data } cli(); NumChanges = NumChanges; //For Testing and Debugging. } //end main
Below is the revised code that DOES work properly per JS's post below.
// THIS CODE *DOES* WORK PROPERLY #include#include #define F_CPU 20000000UL volatile unsigned int NumChanges; ISR(PCINT0_vect) { NumChanges = NumChanges + 1; } int main (void) { // PORTA // Pin40, PA0: Input, // Pin39, PA1: Output, // Pins: 76543210 // Values: 00000010 0x02 DDRA = 0x02; // PORTB // Pin1, PB0: Output, LED // Pins: 76543210 // Values: 00000001 0x01 DDRB = 0x01; //Enable Pin Change Interrupt on TxIn Pin PA1 PCMSK0 |= (1 << PCINT0); //Fixed/Revised This Line PCICR |= (1 << PCIE0); //Fixed/Revised This Line sei(); while(NumChanges < 50) { //Collect Data } cli(); NumChanges = NumChanges; //For Testing and Debugging. } //end main