cancel
Showing results for 
Search instead for 
Did you mean: 

Turn LED on and off on homemade STM32F405 development board

pedro1
Associate II

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;
		}

1 ACCEPTED SOLUTION

Accepted Solutions
S.Ma
Principal

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

View solution in original post

3 REPLIES 3
S.Ma
Principal

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

pedro1
Associate II

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 😀

pedro1
Associate II

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

Working as I wanted. Cheers and Happy Easter.