Hi, I am currently working on nRF52840-DK board and trying to implement simple programs. I want to toggle a LED(P0.13) on the press of a button(P0.11) but I dont want to use the SDK example where driver functions such as nrf_gpio_cfg_input are used but rather would like to modify registers to toggle leds on the press of a button.
This is the code I have come up with. I am not seeing the intended output. What things should I add and modify to enable interrupt?
#include "nrf52840.h" #include "nrf52840_bitfields.h" #include "nrf_delay.h" #include "nrf_gpio.h" #define LED 13 #define BUTTON 11 void GPIOTE_IRQHandler(void) { if(NRF_GPIOTE->EVENTS_IN[0] != 0) { NRF_GPIOTE->EVENTS_IN[0] = 0; // toggle LED NRF_GPIOTE->TASKS_OUT[1] = 1; } } int blinky() { /* Start LFCLK in low power mode driven by LFXO */ NRF_CLOCK->LFRCMODE = CLOCK_LFRCMODE_MODE_ULP; NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal; NRF_CLOCK->TASKS_LFCLKSTART = 1; // config button as an event NRF_GPIOTE->CONFIG[0] = (GPIOTE_CONFIG_MODE_Event << 0) | (BUTTON << 8) | (GPIOTE_CONFIG_POLARITY_HiToLo << 16) ; // config led as a task NRF_GPIOTE->CONFIG[1] = (GPIOTE_CONFIG_MODE_Task << 0) | (LED << 8) | (GPIOTE_CONFIG_POLARITY_Toggle << 16) | (GPIOTE_CONFIG_OUTINIT_Low << 20); // enable interrupt NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Set; NVIC_EnableIRQ(GPIOTE_IRQn); return 0; } int main(void) { blinky(); while (1) { nrf_delay_ms(1000); } }