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

GPIOTE using Pin13-16 on 52DK and BMD-300

I'm using a pin for trigger switch input with the following codes

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

My foundation is the characteristics tutorial. I just added above lines to set up interrupt. I tried a few pins other than 13-16, the application seemed to be running. But when I used any of the above 4 pins, there was no advertising at all. I tried on both 52DK and BMD-300 module. I realized those 4 pins are connected to 4 push buttons on 52DK. I have 2 questions:

  1. Is there any way to reuse those 4 pins on 52DK?
  2. There are no buttons connected by default on BMD-300 module, why couldn't I use those 4 pins either? Is there any setting in the code?

Thanks

  • Hello xr0428

    In the characteristics tutorial the function buttons_leds_init() is called from main. This in turn calls

    uint32_t err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), bsp_event_handler);
    

    This function is part of the board support (bsp) module, and it configures the buttons and leds of the board you are using. For the 52832DK the board defines are found in the pca10040.h header file. The bsp_init function configures the button pins as GPIOTE inputs with low power events.

    When you add your code for pins 13-16 you are trying to initialize GPIOTE for the same pins as the bsp_init function do. This will then trigger the NRF_ERROR_INVALID_STATE error.

    If you are using a custom board you can create a header file called custom_board.h, and remove pca10040.h from the include list. You can place this file in the same directory as the main.c file, as this path is already added. Then remove BOARD_PCA10040 from the preprocessor symbols and add BOARD_CUSTOM (as defined in boards.h). Your custom_board.h should then contain all pin defines similar to what pca10040.h does.

    Alternatively you can remove BSP_INIT_BUTTONS from the bsp_init() arguments. The function will then not configure the buttons, and you can configure them yourself as you please.

    Best regards

    Jørn Frøysa

  • Hi Jørn, Thanks for the reply. Creating a custom.h and changing button definition solved the issue.

    But the other approach, removing BSP_INIT_BUTTONS from the bop_init() didn't seem to work. Here is the code I have

    uint32_t err_code = bsp_init(BSP_INIT_LED,APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), bsp_event_handler);
    

    Another question is do I have to call buttons_leds_init() in the first place? If I comment this function out, I couldn't see advertising as well.

  • The following code

    uint32_t err_code = bsp_init(BSP_INIT_LED,APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),bsp_event_handler);
    

    Should only initialize the LEDS present on the board, as defined in the board header file. It is only necessary to call if you want to keep the functionality offered by the bsp module in regards of led indication of current state. If you cannot see the device advertising it might be because there are additional problems generating an error. You could try to debug and see if the function returns an error code.

  • Hi Jørn, removing BSP_INIT_BUTTONS from the bop_init() gets the following error:

    Name : m_error_data

    Details:{fault_id = 16385, pc = 0, error_info = 536936404, p_assert_info = 0x0, p_error_info = 0x2000ffd4, err_code = 8, line_num = 1177, p_file_name = 0x2be6c "../../../main.c"}

    What's the issue here?

  • I would need to see all your main code to assess this I think. I just removed BSP_INIT_BUTTONS from the unchanged characteristic tutorial code and it works as expected. I suspect there is something else in your code that generates that error. If your code is confidential you can create a mypage case at nordicsemi.com, and refer to this case. If it isn't confidential you can just upload your main.c file to your original question here.

Related