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

gpiote limmited to 8 interrupt pins

hello Nordic

i am using nrf52832, sdk 16.0, 

i have a system which need to react to multiple external interrupts on multiple pins

i see that when ' nrf_drv_gpiote_in_init( ... )' is called more then 8 times i fall because the ' channel_port_alloc(..)' returns 'channel_id = -1

if i understand correctly then the GPIOTE register is one byte so limited to 8 possible pins

how can i use more then 8 pins as external input interrupt pins ?

if i understand correctly, then there is a way to define gpios as input and then use the event port so no additional GPIOTE channel is taken but the GPIOTE interrupt vector table is used .. its all great if thats the solution but how is it done ???

is there a code example somewhere for using multiple gpios as external interrupts (all inputs) ??

one more thing, can this 2 below work together with no unexpected issues ?

#include "nrf_drv_gpiote.h"
#include "app_gpiote.h"

best regards

Ziv

Parents
  • Hi Ziv

    There are essentially two ways to register interrupts from pins in the nRF52 series:

    1) One way is to use the PORT event of the GPIOTE which connects to any pin with SENSE enabled. The advantage of this method is that all the pins in the device can act as wakeup/interrupt sources, but all of them will trigger the same event. This means that you have to manually read the state of the pins to see which of them was actually activated, which is impractical if you expect very frequent pin activations. 

    2) The second way is to use one of the GPIOTE IN channels to connect to one pin specifically, which gives you a unique event for this pin only. This allows you to more easily track pins that can change rapidly, but limits you to the number of GPIOTE channels in your device (8 for the nRF52832). 

    For a complete description of this please have a look at the GPIOTE specification in the product specification

    When using the GPIOTE driver choosing between method 1 and 2 is as easy as setting the hi_accuracy field in the config struct. Setting it to true uses a dedicated IN channel, while setting this false means you will be using the PORT event. 

    For any pin where you expect less rapid changes (like a button) you can set hi_accuracy to false, while up to 8 pins that are more rapidly used can be set true. 

    one more thing, can this 2 below work together with no unexpected issues ?

    #include "nrf_drv_gpiote.h"
    #include "app_gpiote.h"

    You can include both of them, but if you are using the functions defined in app_gpiote.h you should not call any of the nrf_drv_gpiote functions defined in nrf_drv_gpiote.h. 

    The app_gpiote module uses the nrf_drv_gpiote module under the hood, and you could get unpredictable behavior if you use both modules from the application. 

    Best regards
    Torbjørn

  • hi Ovrebekk

    thanks for replay

    1. Regarding using the PORT, i have read all the theory but i can not find a code example or the correct API to use to do that

    2. i want to use 6 pins as GPIOTE with a channel for each pin cause i may get a lot of rapid interrupts on those pins 

    i have another 4 pins which will probably not cause to many interrupts and i would like to use those with the PORT, so i did not understand from your replay if i can combine the 2 methods ??

    and how can i implement or see an implementation of the using of PORT method with several pins ??

    best Regards

    Ziv

  • Hi Ziv

    1. As I mentioned below, when you use the GPIOTE driver the only difference between initializing a pin for a PORT or IN event is whether or not you set the hi_accuracy field in the config to true or not. 

    When using the config macros it is even easier. Below I put an example of configuring to use either the PORT or IN event:

    nrf_drv_gpiote_in_config_t config_port = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
    err_code = nrf_drv_gpiote_out_init(10, &config_port);
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_gpiote_in_config_t config_in = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
    err_code = nrf_drv_gpiote_out_init(11, &config_in);
    APP_ERROR_CHECK(err_code);

    2. Yes, you can combine up to 8 high accuracy pins with as many low accuracy (PORT) pins as you like. 

    To enable several PORT pins just initialize several pins with hi_accuracy set to false, like shown in my code above. 

    Best regards
    Torbjørn

  • ok great 

    thanks Ovrebekk

    one last question on this matter, in the enable gpiote function:

     nrf_drv_gpiote_in_event_enable(SOME_PIN, true);

    what is the meaning of the second argument true/false ?

    best regards

    Ziv

  • Hi Ziv

    The second argument enables interrupt on this pin, which triggers the callback function you can register when calling the nrf_drv_gpiote_in_init(..) function. 

    In other words, if you want to run some code as a result of this pin getting activated you can use this function. 

    Best regards
    Torbjørn

Reply Children
No Data
Related