This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How should I use the GPIO of NRF52840 to capture a interruption of the falling edge and trigger it?

hi everyone!

I am developing NRF52840 with the Development Kit.

I am trying to use a GPIO to o capture a external HIGH-TO-LOW signal and then trigger a LED.

I I learned the examp called pin_change_int.

But i find it's easy to capture a button signal on the board.Hard to capture the external HIGH-TO-LOW signal in my code.

Maybe u can give me some guidance.

Below is my NRF52840 Development Kit  and my code.

Thanks very much!!!

#define PIN_IN   NRF_GPIO_PIN_MAP(0,1)
#ifdef BSP_LED_1
    #define PIN_OUT BSP_LED_1
#endif
#ifndef PIN_OUT
    #error "Please indicate output pin"
#endif

void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
	UNUSED_PARAMETER(pin);
	UNUSED_PARAMETER(action);
	nrf_drv_gpiote_out_toggle(PIN_OUT);
	dataReady = 1;
}

static void gpio_init(void)
{
   ret_code_t err_code;

    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);

    err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
	in_config.is_watcher_GPIO_PIN_NOPULL;

    err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code); = true;
    in_config.pull = NRF

    nrf_drv_gpiote_in_event_enable(PIN_IN, true);
}

int main(void)
{
    bsp_board_init(BSP_INIT_LEDS);
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();
    APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));		
    NRF_LOG_INFO("CODE BEGIN.");
    gpio_init();
    while (1)
    {
        if (dataReady) {}
    }
}
    

Parents Reply Children
No Data
Related