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

Change Pin from Input to Output in runtime?

Hi, i have nrf52 and sdk13.1. Is this possible. I get NRF_ERROR_INVALID_STATE.

Parents
  • This is an answer to stealth's comment above, and will hopefully help with schef's original question as well.

    In the infocenter we can find that the NRF_ERROR_INVALID_STATE is returned if the driver is not initialized or the pin is already used. In your case the error is returned because the pin is used.
    When calling the function

    err_code = nrf_drv_gpiote_in_init(BUTTON_0, &configInButton, my_gpio_handler);
    

    the pin will be used, and therefore you should try to uninitialize the pin using the nrf_drv_gpiote_in_uninit() before you can initialize it again as an output pin.

    Kind regards
    Joakim

Reply
  • This is an answer to stealth's comment above, and will hopefully help with schef's original question as well.

    In the infocenter we can find that the NRF_ERROR_INVALID_STATE is returned if the driver is not initialized or the pin is already used. In your case the error is returned because the pin is used.
    When calling the function

    err_code = nrf_drv_gpiote_in_init(BUTTON_0, &configInButton, my_gpio_handler);
    

    the pin will be used, and therefore you should try to uninitialize the pin using the nrf_drv_gpiote_in_uninit() before you can initialize it again as an output pin.

    Kind regards
    Joakim

Children
Related