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

What is the use of the OUT register of GPIO in nRF52?

In the very first blinky example from the nRF52_SDK_0.9.1:

#include "stdint.h"  
 #include "stdint.h"  
 #include "nrf_delay.h"  
 #include "nrf_gpio.h"  
 #include "boards.h"  
 #include "nrf.h"  

const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;  

/**
 * @brief Function for application main entry.
 */  
int main(void)  
{  
    // Configure LED-pins as outputs.  
    LEDS_CONFIGURE(LEDS_MASK);  
    // Toggle LEDs.  
    while (true)  
    {  
        for (int i = 0; i < LEDS_NUMBER; i++)  
        {  
            LEDS_INVERT(1 << leds_list[i]);  
            nrf_delay_ms(500);  
        }  
    }  
}  

For this one:

LEDS_INVERT(1 << leds_list[i]);  

In the board.h you could find the #define here:

#define LEDS_INVERT(leds_mask) do { uint32_t gpio_state = NRF_GPIO->OUT;      \  
                              NRF_GPIO->OUTSET = ((leds_mask) & ~gpio_state); \  
                              NRF_GPIO->OUTCLR = ((leds_mask) & gpio_state); } while (0)  

The first line means that, give the value in the OUT register of the GPIO to the variable gpio_state.
You could find the related #define in the nrf52.h and nrf51_to_nrf5.h
And these are the result I print out about the gpio_state value:
gpio_state is: 20060
gpio_state is: 60060
gpio_state is: e0060
gpio_state is: 1e0060
gpio_state is: 1c0060
gpio_state is: 180060
gpio_state is: 100060
gpio_state is: 60
gpio_state is: 20060
gpio_state is: 60060
...

Here is my question: which part of this function changes the value in the OUT register of GPIO? Why it would be change like this way?
Thank you all.

Parents Reply Children
No Data
Related