GPIO_PortSet & GPIO_PortClear Behaviour

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GPIO_PortSet & GPIO_PortClear Behaviour

Jump to solution
929 Views
scruffmeister
Contributor II

The board.h file in the led_blinky SDK example for the LPC824 uses 'GPIO_PortClear' to turn an output port HIGH, and 'GPIO_PortSet' to turn an output port LOW.

I have been trying to understand why 'clearing' results in a HIGH output (when it feels like it should result in LOW to me), but have not been able to find my answer in the processor manual. I know I am missing something, please could someone explain?

 

#define LED_RED_ON()                                             \                 
    GPIO_PortClear(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT,  \                  
                   1U << BOARD_LED_RED_GPIO_PIN)                 
                                                
#define LED_RED_OFF()                                            \                
    GPIO_PortSet(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT,    \
                 1U << BOARD_LED_RED_GPIO_PIN)

 

 

 

Labels (1)
0 Kudos
Reply
1 Solution
907 Views
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @scruffmeister,

This "inverted logic" is due to the physical connection of the LED on the LPCXpresso824MAX board: 

EdwinHz_0-1725658025431.png

The LEDs require anode to be high and the cathode to be low to turn ON.

In the schematic we can see that the anodes are already connected to 3.3V, while the cathodes are connected to the GPIO pins.

Therefore, if we set the GPIO pins to HIGH, there will be no potential difference between anode and cathode and the LED will remain OFF. If the GPIO are cleared to LOW, the potential difference will be present, and the LED will turn ON.

I hope this clears things up.

BR,
Edwin.

 

View solution in original post

2 Replies
908 Views
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @scruffmeister,

This "inverted logic" is due to the physical connection of the LED on the LPCXpresso824MAX board: 

EdwinHz_0-1725658025431.png

The LEDs require anode to be high and the cathode to be low to turn ON.

In the schematic we can see that the anodes are already connected to 3.3V, while the cathodes are connected to the GPIO pins.

Therefore, if we set the GPIO pins to HIGH, there will be no potential difference between anode and cathode and the LED will remain OFF. If the GPIO are cleared to LOW, the potential difference will be present, and the LED will turn ON.

I hope this clears things up.

BR,
Edwin.

 

887 Views
scruffmeister
Contributor II

Thank you, that makes perfect sense.

0 Kudos
Reply