From 3ad71d5be0964a8ecf2db2c2cafb0b56127b7a28 Mon Sep 17 00:00:00 2001 From: steffen Date: Wed, 13 Jun 2018 14:23:29 +0200 Subject: [PATCH] atmega_common/gpio.c Fixes GPIO interrupt fixes the GPIO_LOW interrupt on the atmega platform. It results from trying to shift GPIO_LOW. Since it is 0, it is not shiftable and will not be set correctly. There were more issues with the other flanks too, as they are 0b01 or 0b00. If 0b11 was set as a flank before it would not be able to switch to any other mode anymore. Now the bits get cleared before the new flank will be written. --- cpu/atmega_common/periph/gpio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpu/atmega_common/periph/gpio.c b/cpu/atmega_common/periph/gpio.c index 233ae29509..f86067c31b 100644 --- a/cpu/atmega_common/periph/gpio.c +++ b/cpu/atmega_common/periph/gpio.c @@ -174,10 +174,12 @@ int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, /* apply flank to interrupt number int_num */ if (int_num < 4) { + EICRA &= ~(0x3 << (int_num * 2)); EICRA |= (flank << (int_num * 2)); } #if defined(EICRB) else { + EICRB &= ~(0x3 << ((int_num % 4) * 2)); EICRB |= (flank << ((int_num % 4) * 2)); } #endif