Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrfx_gpiote same pin register more than GPIOTE control?

I take the external PWM signal, I directly used the method of controlling the GPIOTE register to be successful. 

But I can't achieve the same effect using the program in the standard SDK.

An error occurs when I declare using the standard SDK. Is there a way to program using the standard SDK? 

PS: SDK version: nRF 16.0.0

there is successful

    NRF_GPIOTE->CONFIG[PWM_INPUT_GPIOTE_RISE_EDGE_CH] = GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos | 
                                         GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos | 
                                         pin_number << GPIOTE_CONFIG_PSEL_Pos | 
                                         GPIOTE_CONFIG_OUTINIT_Low << GPIOTE_CONFIG_OUTINIT_Pos;    // ignored when gpio is set to event mode

    NRF_GPIOTE->CONFIG[PWM_INPUT_GPIOTE_FALL_EDGE_CH] = GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos | 
                                         GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos | 
                                         pin_number << GPIOTE_CONFIG_PSEL_Pos | 
                                         GPIOTE_CONFIG_OUTINIT_High << GPIOTE_CONFIG_OUTINIT_Pos;    // ignored when gpio is set to event mode

there is failure

    err_code = nrfx_gpiote_in_init(pin_number, &gpiote_LoToHi_cfg, PWM_emtpy_handler); //Low to High edge
    APP_ERROR_CHECK(err_code);

    err_code = nrfx_gpiote_in_init(pin_number, &gpiote_HiToLo_cfg, PWM_emtpy_handler); //High to low edge
    APP_ERROR_CHECK(err_code);

Parents Reply
  • Hi!

    You can't initialize the same pin twice, the nrfx_gpiote_in_init function checks if the pin_number is already initialized and returns an error. However, when you write directly to the registers, you just overwrite whatever was there from before without getting an error code.

    This is why the first example "succeeds" while the second fails. I put succeeds in quotation marks because you are just overwriting the initial command, not executing both.

    If what you want to do is set the pin to toggle mode, and then get an interrupt every time the pin changes state I would suggest something like 

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
    in_config.pull = NRF_GPIO_PIN_PULLUP;
    
    err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_gpiote_in_event_enable(PIN_IN, true); 

    Best regards,

    Heidi

Children
Related