I have a button matrix (2 rows, multiple columns) connected to an nRF52840. After driving the two row pins appropriately, the first column pin I read (regardless of actual pin #) gives me a phantom hit. Adding a 1µs delay between the config and the read solves the problem. I'd like to understand what, specifically, is causing this.
Config:
void buttons_init(void) { nrf_gpio_cfg(BUTTON_UP_ROW_PIN, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0D1, NRF_GPIO_PIN_NOSENSE); nrf_gpio_cfg(BUTTON_DOWN_ROW_PIN, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0D1, NRF_GPIO_PIN_NOSENSE); }
Reading:
//Read upper row. Set the upper row low, and the lower row floating. nrf_gpio_pin_clear(BUTTON_UP_ROW_PIN); nrf_gpio_pin_set(BUTTON_DOWN_ROW_PIN); nrfx_coredep_delay_us(1); // :-( // Up buttons for (uint8_t i = 0; i < BUTTON_SETS; i++) { if (!nrf_gpio_pin_read(buttons_pins[i])) { // If button is pushed ... } }
(And swap pin states to read other row)