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

Migration to SDK15.1: NRFX GPIOTE IN EVENT

Hello,

I base on migration guide:

http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.1.0%2Fnrfx_migration_user_guide.html&cp=4_0_0_2_5

My board is nrf52840.

I have strange problem with migration to new NRFX drivers fo GPIOTE. I did the following:

1. I deleted all legacy layers' defines in sdk_config.h,

2. I defined NRFX_GPIOTE_ENABLED

This is my code:

void init_gpiote()
{
  if(not nrfx_gpiote_is_init())
  {
    nrfx_gpiote_init();
  }
}

void init_digital_simple_output(nrfx_gpiote_pin_t pin, nrfx_gpiote_port_t port)
{
  nrfx_gpiote_out_config_t config_out = NRFX_GPIOTE_CONFIG_OUT_SIMPLE(true);
  nrfx_err_t err_code = nrfx_gpiote_out_init(NRF_GPIO_PIN_MAP(port, pin), &config_out);
  if(err_code != NRFX_SUCCESS)
  {
    // Error during initialization: NRFX_ERROR_INVALID_STATE or NRFX_ERROR_NO_MEM
  }
}

void blink_led(nrfx_gpiote_pin_t pin, nrfx_gpiote_port_t port)
{
  for(uint8_t i = 0; i < 4; ++i)
  {
    nrfx_gpiote_out_set(NRF_GPIO_PIN_MAP(port, pin));
    for(int i = 0; i < 1000000; ++i);
    nrfx_gpiote_out_clear(NRF_GPIO_PIN_MAP(port, pin));
    for(int i = 0; i < 1000000; ++i);
  }
}

void in_event_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
  nrfx_gpiote_out_toggle(NRF_GPIO_PIN_MAP(0, 13));
}

void init_digital_input(nrfx_gpiote_pin_t pin, nrfx_gpiote_port_t port)
{
  if(not nrfx_gpiote_in_is_set(NRF_GPIO_PIN_MAP(port, pin)))
  {
    nrfx_gpiote_in_config_t config_in = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
    config_in.pull = NRF_GPIO_PIN_PULLUP;
    nrfx_err_t err_code = nrfx_gpiote_in_init(NRF_GPIO_PIN_MAP(port, pin), &config_in, in_event_handler);
    if(err_code != NRFX_SUCCESS)
    {
      // Error during initialization: NRFX_ERROR_INVALID_STATE or NRFX_ERROR_NO_MEM
    }
    nrfx_gpiote_in_event_enable(NRF_GPIO_PIN_MAP(port, pin), true);
    blink_led(13, 0);
  }
}

And here the main loop:

void main(void) {
  static const nrfx_gpiote_port_t PORT_LED1 = 0;
  static const nrfx_gpiote_pin_t PIN_LED1 = 13;
  static const nrfx_gpiote_port_t PORT_BUTTON1 = 0;
  static const nrfx_gpiote_pin_t PIN_BUTTON1 = 3;

  init_gpiote();
  init_digital_simple_output(PIN_LED1, PORT_LED1);
  init_digital_input(PIN_BUTTON1, PORT_BUTTON1);

  while(true)
  {
  }
}

When I debug the code I see that everything behave as expected - all peripherals are initiated properly. Unfortunately, I am not able to detect any event on IN pin. I have been struggling for a long time with this simple migration but still without result. Did I forget about some detail? 

I can add that when I did not delete legacy defines in sdk_config.h it also did not work at all. It works only when I use nrf_drv* drivers but I really want to use new drivers as they will be supported in the future, thus it is important to me to use the new ones. I would really appreciate if someone can help me.

Best regards,

Pawel

Parents
  • Hi, 

    Please insert the code below into your project and check if it works. You can change LED_4 and  BUTTON_1 to match the pinout of your board. 

    #include <stdbool.h>
    #include <stdint.h>
    #include "nrf.h"
    #include "nrf_gpiote.h"
    #include "nrf_gpio.h"
    #include "boards.h"
    #include "nrf_drv_gpiote.h"
    #include "app_error.h"
    
    
    void gpiote_callback(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        if (pin == BUTTON_1)
        {
            nrfx_gpiote_out_task_trigger(LED_4); //toggle output on button press - can be done through PPI
        }
    }
    
    
    void gpiote_init()
    {
        uint32_t                 err_code;
        nrfx_gpiote_out_config_t config_out = NRFX_GPIOTE_CONFIG_OUT_TASK_TOGGLE(true);
        nrfx_gpiote_in_config_t  config_in = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    
        config_in.pull = NRF_GPIO_PIN_PULLUP;
    
        err_code = nrfx_gpiote_init();
        APP_ERROR_CHECK(err_code);
        
        err_code = nrfx_gpiote_out_init(LED_4, &config_out);
        APP_ERROR_CHECK(err_code);
    
        nrfx_gpiote_out_task_enable(LED_4);
    
        err_code = nrfx_gpiote_in_init(BUTTON_1, &config_in, gpiote_callback);
        APP_ERROR_CHECK(err_code);
    
        nrfx_gpiote_in_event_enable(BUTTON_1, true);
        
    }
    
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
       
        gpiote_init();
    
    
        while (true)
        {
            // Do Nothing - GPIO can be toggled without software intervention.
        }
    }

  • Thank you for your fast response. Unfortunately, the code behaves as before. I included banch of libraries but there is no difference. I used also unchanged sdk_config.h. 

    I guess that I do not define something and this cause the problems even though program compiles. Could you please describe what is indispensible to make the program work on nrfx drivers? I mainly mean every needed defines because as I see the code is rather error-free?

Reply
  • Thank you for your fast response. Unfortunately, the code behaves as before. I included banch of libraries but there is no difference. I used also unchanged sdk_config.h. 

    I guess that I do not define something and this cause the problems even though program compiles. Could you please describe what is indispensible to make the program work on nrfx drivers? I mainly mean every needed defines because as I see the code is rather error-free?

Children
No Data
Related