Reputation: 11
I have an ATTiny 1626 on a PCB which I program by using SerialUPDI. I want to increase the value of a variable in an interrupt service routine, triggered by a button press. The problem is, that the ISR does not get called at all.
My Code is:
// Global:
volatile short operation_mode = 1; // Track operation mode
void setup() {
cli();
PORTA.PIN2CTRL |= PORT_PULLUPEN_bm; // Enable pin A2 pull-up resistor
PORTA.PIN2CTRL |= PORT_ISC_FALLING_gc; // Enable pin A2 falling edge interrupts
PORTA.DIRSET &= ~PIN2_bm; // Set pin A2 as INPUT -> Internal pull-up required for async button interrupt
sei();
}
void loop() {
ADC0_CTRLA |= ADC_ENABLE_bm; // Turn on ADC
delay(10);
// [...]
ADC0_CTRLA &= ~ADC_ENABLE_bm; // Turn off ADC
set_sleep_mode(SLEEP_MODE_STANDBY); // Set standby sleep mode
sleep_enable(); // Enable sleeping
sleep_cpu(); // Sleep until woken up by ISR
}
// The ISR:
ISR(PORTA_PORT_vect) {
if ((PORTA.INTFLAGS & PIN2_bm) == 0) {
operation_mode = (operation_mode + 1) % 3;
}
PORTA.INTFLAGS |= PIN2_bm; // Clear interrupt flag
}
I wonder if there is something wrong with my code or if my setup is flawed. Maybe a capacitor, which has too much capacitance causes the falling edge to be less steep and makes the uC not detect it? I am a bit out of ideas, help is highly appreciated!
Upvotes: 1
Views: 277