cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with GPIO

ivitro
Associate II
Posted on July 02, 2011 at 16:15

Hello, I try turn on and turn off a led when i press the button user1 but can not to do that, So i don´t understand my mistake.

I m using Keil with stm32_init.c, i config GPIOA.PIN1 like floating input...

the main code is:

int main (void)

{

      stm32_Init ();  

    GPIOC->BSRR =  (1 <<9);     

    GPIOC->BSRR =  (1 <<8);   

    while(1)

    {

        if (!((GPIOA->IDR & 0x0001) == 0 ))              // Check if S2 is not pressed

        { 

            GPIOC->BSRR =  (1 <<8);          

           

                  

        }

        else

        {

            if (((GPIOA->IDR & 0x0001) == 0 ))              // Check if S2 is pressed

            {            

                  GPIOC->BSRR =  (1 <<24);   

            }

           }

    }

          

                      

            

   // end while

} // end main

can help?

3 REPLIES 3
ivitro
Associate II
Posted on July 02, 2011 at 19:29

the keil give me a HardFault_Handler

why?

Posted on July 03, 2011 at 16:15

Check that you are enabling the clocks and GPIO's correctly.

For the Hard Fault, check first you are targeting the right CPU in your project. Hard faults typically occur because you're touching the wrong memory. Try debugging be stepping through the code until the fault occurs, or get the hard fault handler instrumented to provide details of the core state, and where in your code it faulted. Try looking for the example provided by Joseph Yiu.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
eejaz
Associate II
Posted on September 18, 2011 at 18:46

This is because you have not configured RCC. I had the same problem.