简体   繁体   中英

Userbutton on STM32f4

I am trying to turn on the LEDs when the user button is pressed

I think I have enabled the peripheral clocks right and the right register. The button is on porta bit 0

Here is my code...any help would be great. Sorry if it is a bit simple, I am still learning the board.

int main (void)
{
RCC->AHB1ENR=0x9;           
GPIOA->MODER = 0x00000002; 
GPIOD->MODER = 0x55000000;  
GPIOD->OTYPER = 0;          
GPIOD->OSPEEDR = 0;         
GPIOD->PUPDR = 0;           
GPIOA->PUPDR = 0;
GPIOA->OTYPER = 0;
GPIOA->OSPEEDR = 0;

    while(1)
{
    if(GPIOA->IDR == 0x0001){
    GPIOD->ODR = 0xF000;                        
    }
    else{
        GPIOD->ODR = 0;         

        }   
    }   
}

I don't know the STM32f4 but I'm guessing that instead of

if(GPIOA->IDR == 0x0001)

You want

if ((GPIOA->IDR & 0x0001) != 0)

The original checks that the low bit is on AND all other bits are off while the new version just checks the low bit and ignores the rest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM