Skip to main content
Cl.1
Associate III
April 6, 2020
Question

Question about the LED of STM32F407

  • April 6, 2020
  • 3 replies
  • 1251 views

This is my code.

GPIO_PinState boButton_state ;

printf (" Hello �?� Cruel �?� World \n"); 

while (1)

{

boButton_state = HAL_GPIO_ReadPin ( B1_GPIO_Port , B1_Pin ); 

HAL_GPIO_WritePin ( LD6_GPIO_Port , LD6_Pin , boButton_state );

HAL_GPIO_TogglePin ( LD3_GPIO_Port , LD3_Pin );

HAL_Delay ( TENTH_SEC );

In the code show that the LED(LD3) will toggle every 10th of a second as an indication that the code is running.

At the same moment the LED(LD6) will turn on when i pushbutton User(B1).

Now i need to write the explain about this situation, can i explain will the HAL code inverts the logic so the LED(LD6) normally is off and only will turn on when i push the button?

Thanks in advance.

This topic has been closed for replies.

3 replies

TDK
Super User
April 6, 2020

Yes, HAL_GPIO_TogglePin will toggle LD3 and LD6 will reflect the state of B1.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
April 6, 2020

Thing to remember is that buttons often have a pull-up and ground to zero when pressed. LEDs too can be wired either way, to VCC via a resistor or too GND via a resistor. When the former is used in Open-Drain mode, setting the pin LOW turns ON the LED

Trying using ! to reverse the state if you want other way around

HAL_GPIO_WritePin ( LD6_GPIO_Port , LD6_Pin , !boButton_state );

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Cl.1
Cl.1Author
Associate III
April 7, 2020

Awesome! Learned! Thank you!