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

NRF GPIO Example OutPut Write

Hi,

To turn on and turn off the LED nrf SDK is using following code in sdk12.1.

#define LEDS_OFF(leds_mask) do { NRF_GPIO->OUTSET = (leds_mask) & (LEDS_MASK & LEDS_INV_MASK); \
NRF_GPIO->OUTCLR = (leds_mask) & (LEDS_MASK & ~LEDS_INV_MASK); } while (0)

#define LEDS_ON(leds_mask) do { NRF_GPIO->OUTCLR = (leds_mask) & (LEDS_MASK & LEDS_INV_MASK); \
NRF_GPIO->OUTSET = (leds_mask) & (LEDS_MASK & ~LEDS_INV_MASK); } while (0)

But why we are setting the OUTSET register for clearing the LED?,Why we are setting the OUTCLR register for turning on LED?. Should it be other way around? The code is working perfectly fine, but couldn't understand the logic behind it .

What is the difference between OUTSET, OUTCLR and OUT register?.

Parents
  • Hi,

    This depends on how the LEDs are connected. On our DKs, the LEDs are active low and are connected between the GPIO and VDD. This means that if the GPIO is set high (i.e. VDD), both nodes of the LED will have the same voltage potential and no current will flow through it. When the GPIO is cleared (i.e. GND), the voltage difference between the two nodes will create a current flow, lighting up the LED.

    It would also be possible to connect the LED between the GPIO and GND. In that case, you would use SET and CLR to turn on and off the LED as you expect. The main reason for using active low LEDs is that the GPIOs of the nRF5x ICs can sink (i.e. receive) more current than it can source (i.e. send out).

    Best regards,
    Jørgen

  • That is not configurable in SW, this is an HW decision that is made by the board designer. The LEDs are physically connected either between VDD and the GPIO or between GND and the GPIO.

Reply Children
No Data
Related