I have a custom board with 5 buttons, and a status LED, using the nrf52832_xxaa chip. 2 of the 5 buttons never trigger an interrupt. It seems like this is because nrf_gpio_pin_read always returns 0 for those 2 pins.
The pins are below:
constexpr uint32_t kButton0 = 15; constexpr uint32_t kButton1 = 12; constexpr uint32_t kButton2 = 7; constexpr uint32_t kButton3 = 9; constexpr uint32_t kResetButton = 10; constexpr uint32_t kStatusLed = 14
Button 0-2 trigger correctly, but Button3 and Reset button never trigger. Here's how I set them up:
constexpr nrf_drv_gpiote_in_config_t kGpioteConfig = { sense : NRF_GPIOTE_POLARITY_HITOLO, pull : NRF_GPIO_PIN_NOPULL, is_watcher : false, hi_accuracy : true, }; void ButtonsInit() { APP_ERROR_CHECK(nrf_drv_gpiote_init()); APP_ERROR_CHECK( nrf_drv_gpiote_in_init(kButton0, &kGpioteConfig, &Button0Interrupt)); APP_ERROR_CHECK( nrf_drv_gpiote_in_init(kButton1, &kGpioteConfig, &Button1Interrupt)); APP_ERROR_CHECK( nrf_drv_gpiote_in_init(kButton2, &kGpioteConfig, &Button2Interrupt)); APP_ERROR_CHECK( nrf_drv_gpiote_in_init(kButton3, &kGpioteConfig, &Button3Interrupt)); APP_ERROR_CHECK(nrf_drv_gpiote_in_init(kResetButton, &kGpioteConfig, &ResetButtonInterrupt)); nrf_drv_gpiote_in_event_enable(kButton0, true); nrf_drv_gpiote_in_event_enable(kButton1, true); nrf_drv_gpiote_in_event_enable(kButton2, true); nrf_drv_gpiote_in_event_enable(kButton3, true); nrf_drv_gpiote_in_event_enable(kResetButton, true); nrf_gpio_cfg_output(kStatusLed); }
The ButtonNInterrupt functions basically put a function onto the scheduler that logs a log statement. I also put a log statement at the beginning of GPIOTE_IRQHandler in nrf_drv_gpiote.c, and it only triggers when I press Buttons 0-2, so the interrupt itself is not being called.
The interrupts all trigger on HITOLO. I probed the buttons, and they were held high when not pressed (~3.3V), and correctly went low when pressed (~0V). The whole board is powered from a 3.3V supply, so this seems correct. But, when I repeatedly read kResetButton's state using nrf_gpio_pin_read, it always returns 0.
I also read the PIN_CNF to see if anything changed, but they all look the same...
// Read PIN_CNF sstl::vector<uint32_t, 10> buttons = {kButton0, kButton1, kButton2, kButton3, kResetButton}; for (const auto& b : buttons) { LOG_I("PIN_CNF[%d]=%d", b, NRF_GPIO->PIN_CNF[b]); } // Output is... 00> <info> app: PIN_CNF[15]=0 00> <info> app: PIN_CNF[12]=0 00> <info> app: PIN_CNF[7]=0 00> <info> app: PIN_CNF[9]=0 00> <info> app: PIN_CNF[10]=0
I also tried removing init of buttons 0-2, to see if some buffer was overflowing after 3 buttons, but Button3 and ResetButton still don't trigger.
What could be causing these two buttons to not trigger?
Edit Jan 1 2020:
I am using SDK 14.2, and using C++17 with the Arm GCC toolchain.