Skip to main content
pedro1
Associate III
Apr 20, 2019 4:33 AM UTC
Solved

Turn LED on and off on homemade STM32F405 development board

I have a simple switch on an LED project on a homemade STM32F405 development board. I am using STM32 Cube-MX and It is all working OK and turns an LED on and off via a momentary switch on subsequent button presses. The problem is that on starting the program the externally connected LED starts off in the on state whereas I would like it to start in the off state. Here is the relevant section of my main.c code and I was wondering how I can change it to make this happen please? I am hoping that this code snippet is where it can be changed but I can post the whole main.c if required.

while (1)
 {
		// https://www.youtube.com/watch?v=sWe4kvzLMjY
		
		if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_3) && tempVar)
		{
			// wait 5 ms
			HAL_Delay(5);
			
			HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
		 tempVar = false;
		}
		else if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_3)==GPIO_PIN_RESET)
		{
			// wait 5 ms
			HAL_Delay(5);
			
			tempVar = true;
		}

This topic has been closed for replies.
S.Ma
S.MaBest answer
Principal
Apr 20, 2019 7:14 AM UTC

It's not there, it's when the GPIO is configured as output that you shall set its output level prior.

3 replies

S.Ma
S.MaBest answer
Principal
Apr 20, 2019 7:14 AM UTC

It's not there, it's when the GPIO is configured as output that you shall set its output level prior.

pedro1
pedro1Author
Associate III
Apr 20, 2019 7:48 AM UTC

Thanks for the reply but exactly where please? In the configuration UI of STM32 Cube-MX is it.

I am only learning this so I really need specific information please :grinning_face:

pedro1
pedro1Author
Associate III
Apr 20, 2019 8:51 AM UTC

Update - this post and the micro :grinning_face: I found the config setting here https://imgur.com/a/gnV21Z9 thanks KIC8462852 EPIC204278916

Working as I wanted. Cheers and Happy Easter.