cancel
Showing results for 
Search instead for 
Did you mean: 

Help with PC8 blinking LED - STM32F051

miriam
Associate II
Posted on September 28, 2016 at 04:36

I try to run the following program on KEIL MDK 5.0:

&sharpinclude ''stm32f0xx.h''

int main(void){

volatile unsigned int i=0;

RCC -> AHBENR |= (i<<19);

GPIOC ->MODER |= (i<<16); // mode

GPIOC ->ODR |= (i<<8); // output data is ON

  while (1)  {

for (i=0; i<1000000; i++)

GPIOC ->ODR |= (i<<8); // output data is ON

for (i=0; i<1000000; i++)

GPIOC ->ODR &= (i<<8); // output data is OFF

  }

  }

From some reason I don't see the BLUE LED blinking.

Anyone know why?

Thanks,

Miri

#stm32f051-stm32-stm32f0
16 REPLIES 16
miriam
Associate II
Posted on September 29, 2016 at 18:16

I tried this as well:

GPIOC ->ODR |= 1;

GPIOC ->ODR |= 0;

But nothing happen with the leds.

Posted on September 29, 2016 at 18:27

GPIOC ->ODR |= 1;

 

GPIOC ->ODR |= 0;

Is PC0 connected to an LED, and configured as an output?

Or'ing something with zero isn't going to do anything useful.

GPIOC ->ODR |= 256; // PC8 Set

GPIOC ->ODR &= ~256; // PC8 Clear

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
miriam
Associate II
Posted on September 29, 2016 at 18:33

I want to use the onboard led PC8 or PC9.

I changed it to:

GPIOC ->ODR |= 256; // PC8 Set

GPIOC ->ODR &= ~256; // PC8 Clear

But nothing happen.

miriam
Associate II
Posted on September 29, 2016 at 18:40 What is a good configuration of PC8 to output?

GPIOC ->MODER |= (1<<
16
); // mode Output

or
GPIOC ->MODER |= 256
; // mode Output
Posted on September 29, 2016 at 18:41

Perhaps you could use the debugger and step through the code whilst looking at the Peripheral Registers in the viewer?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 29, 2016 at 18:49

What is a good configuration of PC8 to output?

 

GPIOC ->MODER |= (1<<16); // mode Output

 

or

 

GPIOC ->MODER |= 256; // mode Output

If you look at the Reference Manual, it indicates that there are two bits for each pin, which is why it shifts the 1 by 16 and not 8.

If you choose to program at the register level you're going to have to be very familiar with the manual and the descriptions of the registers at a bit level. Consider using the Standard Peripheral Library (SPL)

You might need some additional delay between enabling the GPIOC clock, and writing to the peripheral.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Walid FTITI_O
Senior II
Posted on September 29, 2016 at 20:04

Hi miri, 

To start developping STM32 application you can use either standard peripherals library (you can download STM32F0xx standard peripheral library from this

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32048.html

) or you can use the Hal library called STM32Cube ( you can download STM32CubeF0 from this 

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef0.html

).

For GPIO toggling follow these path:

* In standard peripherals library:  STM32F0xx_StdPeriph_Lib_V1.5.0\Projects\STM32F0xx_StdPeriph_Examples\GPIO\GPIO_IOToggle

* In STM32CubeF0: projects are classified per board : for example for the STM32F030R8-Nucleo follow this example path:

STM32Cube_FW_F0_V1.6.0\Projects\STM32F030R8-Nucleo\Examples\GPIO\GPIO_IOToggle

-Hannibal-