u/Fast_General2301

Help me debug this circuit to glow an led on pressing the button

Help me debug this circuit to glow an led on pressing the button

I just started learning electronics and I'm not sure how to debug this circuit. The led glows even without pressing the button. I'm currently using STM32F401RE nucleo board .The code gets built succesfully. I will include my code as well :

//GPIOA PA5 -> LED OUTPUT

	`RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;`

	`RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;`



	`GPIOA->MODER |= GPIO_MODER_MODER5_0;`

	`GPIOA->MODER &= ~GPIO_MODER_MODER5_1;`



	`GPIOA->OTYPER &= ~(GPIO_OTYPER_OT5);`



	`GPIOA->OSPEEDR &= ~(GPIO_OSPEEDR_OSPEED5_0);`

	`GPIOA->OSPEEDR &= ~(GPIO_OSPEEDR_OSPEED5_1);`



	`GPIOA->OSPEEDR &= ~(GPIO_OSPEEDR_OSPEED5_0);`

	`GPIOA->OSPEEDR &= ~(GPIO_OSPEEDR_OSPEED5_1);`



	`//GPIOB PB6 -> BUTTON INPUT`

	`GPIOB->MODER &= ~(GPIO_MODER_MODER6_0);`

	`GPIOB->MODER &= ~(GPIO_MODER_MODER6_1);`



	`GPIOB->PUPDR &= ~(GPIO_PUPDR_PUPDR6);`

while (1)

{

  `if(GPIOB->IDR & GPIO_IDR_IDR_6){`

GPIOA->BSRR |= GPIO_BSRR_BS5;

  `}`

  `else{`

GPIOA->BSRR |= GPIO_BSRR_BR5;

  `}`

}

Kindly give me your suggestions :>

u/Fast_General2301 — 8 days ago
▲ 151 r/stm32f4+1 crossposts

Help me debug the circuit

I've tried to use a button as input to glow an led. I'm a beginner in electronics, so I could'nt find the error here. This is STM32F401re board. The circuit is not working and I'm not sure why. Kindly give your corrections!! :)

u/Fast_General2301 — 8 days ago

Suggest me some beginner friendly projects to understand my STM32 nucleo board.

Hi guys!! I'm new to electronics. I'm currently in my semester holiday. So suggest me a beginner friendly project using my stm32f401re nucleo board which will help me to understand and learn about baremetal programming.

reddit.com
u/Fast_General2301 — 19 days ago