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
  • I have a similar case, so pardon me for hijacking the topic. I have pin 0.08 that I wanted to have as a dual-purpose pin - first a pushbutton, then a LED. Both are tied to the pin, in parallel, then grounded

    My init goes smoothly:

    #define GPIO_1 8
    
    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_gpiote_in_config_t configInButton = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    err_code = nrf_drv_gpiote_in_init(BUTTON_0, &configInButton, my_gpio_handler);
    APP_ERROR_CHECK(err_code);
    

    and my_gpio_handler works well. Once I'm done with the button I call a second method that does the following:

    nrf_drv_gpiote_out_config_t configOut = GPIOTE_CONFIG_OUT_SIMPLE(0);
    err_code = nrf_drv_gpiote_out_init(GPIO_1, &configOut);
    APP_ERROR_CHECK(err_code);
    

    That last APP_ERROR_CHECK throws an NRF_ERROR_INVALID_STATE.

    Did I skip a step somewhere?

Reply
  • I have a similar case, so pardon me for hijacking the topic. I have pin 0.08 that I wanted to have as a dual-purpose pin - first a pushbutton, then a LED. Both are tied to the pin, in parallel, then grounded

    My init goes smoothly:

    #define GPIO_1 8
    
    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_gpiote_in_config_t configInButton = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    err_code = nrf_drv_gpiote_in_init(BUTTON_0, &configInButton, my_gpio_handler);
    APP_ERROR_CHECK(err_code);
    

    and my_gpio_handler works well. Once I'm done with the button I call a second method that does the following:

    nrf_drv_gpiote_out_config_t configOut = GPIOTE_CONFIG_OUT_SIMPLE(0);
    err_code = nrf_drv_gpiote_out_init(GPIO_1, &configOut);
    APP_ERROR_CHECK(err_code);
    

    That last APP_ERROR_CHECK throws an NRF_ERROR_INVALID_STATE.

    Did I skip a step somewhere?

Children
No Data
Related