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

GPIOTE INPUT simple use with SDK 11.0.0

Hi, everyone.

I have read the nRF5 SDK --> GPIOTE part in the infocenter. However, I have not get anything useful.

I just want to recieve a interrupt from an external sensor and do something in a handler function. So I tried some code like this:

static void event(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    i = 1;
}


int main(void)
{
    uint32_t err_code;
    bool erase_bonds;
    
    const nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);

    timers_init();
    buttons_leds_init(&erase_bonds);
    twi_init();
    nrf_drv_gpiote_init();
    
    nrf_drv_gpiote_in_init(13, &config, event);
    
    ble_stack_init();
    device_manager_init(erase_bonds);
    gap_params_init();
    advertising_init();
    services_init();
    conn_params_init();

    
    application_timers_start();
    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);

    
    for (;;)
    {
        power_manage();
    }
}

But when I run it on PCA10028 and press the Button 1, event function will never be executed. So I just want to ask why I'm wrong and how to use the GPIOTE input event?

Parents
  • Firstly I recommend you to test peripheral without the SoftDevice first. Secondly I recommend checking the returned error codes of functions calls. Anyways:

    On PCA10028 Button 1 is not connected to pin 13, but pin 17.

    Pin 17 will be high when the button is not pushed, and it will be low when the button is pushed, so maybe you want to use HITOLO instead of LOTOHI.

    You should check the returned error code of nrf_drv_gpiote_in_init(), it will give an error because the BSP module has connected a GPIOTE channel to pin 17. Comment out buttons_leds_init() to avoid this.

    You need to enable the in event for the pin.

    You should have something like this:

    //buttons_leds_init(&erase_bonds);
    
    const nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    
    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
    
    err_code = nrf_drv_gpiote_in_init(17, &config, event);
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_gpiote_in_event_enable(17, true);  
    
  • Thank you. So it means that the event function I wrote is in the right type, is it?

Reply Children
No Data
Related