AnsweredAssumed Answered

New to STM32f4 Discovery and having some teething Issues

Question asked by Steve on Nov 17, 2012
Latest reply on Nov 17, 2012 by Steve
Hi All, 

I've been playing around with the STM32f4 Discovery board in Keils uVision. I've been trying to get the "user Button" to turn on an LED when pressed. 

Its my understanding that after iv initiated the peripherals clocks for port A and D, This allows me to use the GPIOs on those ports. 

So iam trying to read from from the Input Data Register on GPIOA to see the status off the Button. Its my understanding that the code below should light up an LED when button is pressed, for some reason i get no response, can anyone point out my errors?

#include <stm32f4xx.h>
 
int main (void)
{
    RCC->AHB1ENR = 0x9;             //IO PortD clock enable / port A clock enable
     
    //setup Port A ports
    GPIOA->MODER = 0xA8000000;                  // Set Port a Bit 0 Active input (the user button is on PA0)
    GPIOA->OTYPER = 0;         
    GPIOA->OSPEEDR = 0;        
    GPIOA->PUPDR = 0;                      
         
    // Port D setup
    GPIOD->MODER = 0x55000000;  //Set GPIOD 12/13/14/15 as outputs PIN
    GPIOD->OTYPER = 0;          //Set output as Push-Pull mode
    GPIOD->OSPEEDR = 0;         //Set output speed 2MHz low speed
    GPIOD->PUPDR = 0;           //Set no pull up and pull down
 
    GPIOD->ODR = 0x0000;        // Turn off all LEDs
    while(1)
        {
 
            if(GPIOA->IDR == 0x1)
            {      
                    GPIOD->ODR = 0x8000;
            }
                 
        }  
}


Many Thanks, 
Steve

Outcomes