Cannot configure Port 1 Pin 8

Hello,

I need to use Port 1 pin 8 as an interrupt pin:

#define INT_PIN  NRF_GPIO_PIN_MAP(1, 8)

nrf_drv_gpiote_in_config_t int_pin_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
int_pin_config.pull = NRF_GPIO_PIN_PULLUP;
ret_code_t err_code = nrf_drv_gpiote_in_init(INT_PIN, &int_pin_config, int_pin_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(INT_PIN, true);

This results in the error NRF_ERROR_INVALID_STATE, when nrf_drv_gpiote_in_init() is called. Everything works fine, if I use a port 0 pin. What can be the problem with using port 1?

I'm using the nRF52832, SDK 17.1.0, SoftDevice S132 7.2.0, and a custom board.

  • Hi,

    nrf_drv_gpiote_in_init() will return NRFX_ERROR_INVALID_STATE if the pin is already used (Only one GPIOTE channel can be assigned to one physical pin), so I suspect that is what you are seeing.

    Which SDK version are you using? (To double check I took the pin changed interrupt example form SDK 17.1.0 and changed the input pin to P1.08, and that worked as expected, so there does not seem to be a bug with port 1 specifically in that version, at least.)

  • Hi,

    Thanks for your reply! I'm using SDK 17.1.0. I've tried it with an other pin at port 1 and it works. This is my board definitions:

    #ifndef CUSTOM_BOARD_H
    #define CUSTOM_BOARD_H
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    #include "nrf_gpio.h"
    
    #define BUTTONS_NUMBER 2
    
    #define BUTTON_1       NRF_GPIO_PIN_MAP(0, 3)
    #define BUTTON_2       NRF_GPIO_PIN_MAP(0, 28)
    #define BUTTON_PULL    NRF_GPIO_PIN_PULLUP
    
    #define BUTTONS_ACTIVE_STATE 0
    
    #define BUTTONS_LIST { BUTTON_1, BUTTON_2 }
    
    #define SCL_PIN             	NRF_GPIO_PIN_MAP(0, 24)
    #define SDA_PIN             	NRF_GPIO_PIN_MAP(0, 25)
    #define INT_PIN				    NRF_GPIO_PIN_MAP(1, 8)
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif // CUSTOM_BOARD_H

    Port 1 pin 8 isn't defined anywhere else, so I don't know how it could be already in use. Is there anything else in the SDK, which has to do with pin definitions?

  • Some examples define pins outside of the board file, but I cannot say what is the case in your code without seeing it. Do you use your INT_PIN anywhere else? If you cannot find it, perhaps you can add some code in the implementation of nrf_drv_gpiote_in_init() that checks if pin P1.8 (40) is initiated, and set a breakpoint on it? That way you could check the stack trace to see where it comes from.

  • No, this pin is not used anywhere else. It works with other pins, so it might be some "hidden" configuration or project related problem. I'll try it with a clean example project as well.

  • I've tested it with a clean Blinky example project using my custom board and a clean Blinky example project using the PCA10040 dev kit (same SoC on both boards). Same error in all cases with port 1 pin. All works with a port 0 pin. Can there be something with the Blinky example? Can you also verify, that the Blinky example works/fails with a port 1 pin configured for GPIOTE?

    (I'm using the nRF52832, SDK 17.1.0, SoftDevice S132 7.2.0)

Related