This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Working with buttons

Hello) Please, tell me what I'm doing wrong. I want to make the LED (PE1) work when the (PB13) button is pressed, but it does not work, as I understand that I am not correctly initializing the mode of the button port, there must be Input mode, but I don’t understand how to do it. I just have an LED on, but nothing happens when the button is pressed. My board is stm32h743zi. Can you please tell me what I'm doing wrong, I checked all the sites, but I couldn't find anything. p.s. I tried to write the same thing through HAL, everything naturally works there, but I want to understand how to work with a button without HAL.

#include "stm32h7xx.h"

void GPIO_Init(void);

int main(void) {

GPIO_Init();

if((GPIOC->IDR & GPIO_IDR_ID13) != 0) {

GPIOE->BSRR |= GPIO_BSRR_BR1;

}else{

GPIOE->BSRR |= GPIO_BSRR_BS1;

}

}

void GPIO_Init ()

{

RCC->AHB4ENR |= RCC_AHB4ENR_GPIOEEN;

RCC->AHB4ENR |= RCC_AHB4ENR_GPIOCEN;

GPIOE->MODER = GPIO_MODER_MODE1_0;

GPIOC->MODER &= ~GPIO_MODER_MODE13;

}