GPIO_PortSet & GPIO_PortClear Behaviour

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

GPIO_PortSet & GPIO_PortClear Behaviour

跳至解决方案
940 次查看
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)

 

 

 

标签 (1)
0 项奖励
回复
1 解答
918 次查看
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.

 

在原帖中查看解决方案

2 回复数
919 次查看
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.

 

898 次查看
scruffmeister
Contributor II

Thank you, that makes perfect sense.

0 项奖励
回复