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
michaelc.barton9
Associate II
Posted on September 28, 2016 at 10:19

I'll just hightlight a bit of your code:

volatile unsigned int i=0;

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

etc

I realise the Std Peripheral Library is no longer supported, but it really is quite useful and makes the code far more readable eg:

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

miriam
Associate II
Posted on September 28, 2016 at 13:02

Thank you Michael,

Where can I find a list of all supported commands?

michaelc.barton9
Associate II
Posted on September 28, 2016 at 14:28

I'm not sure if there is a complete list of commands per se...

for starting, I would recommend downloading the

http://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-eval-tools/stm32-mcu-eval-tools/stm32-mcu-discovery-kits/stm32f0discovery.html

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

(link at bottom of page)

This has a good range of example code and should be easy to adapt for most other F0 boards

to force the compiler to use the libraries, USE_STDPERIPH_DRIVER needs to be defined in:

stm32f0xx.h

and the Std peripheral files to be included in a project (you can selectvely en/disable them in the

stm32f0xx_conf.h file but I usually just leave them all enabled)

Usefully, there's also a compiled help-file: stm32f0xx_stdperiph_lib_um.chm

Posted on September 28, 2016 at 14:58

Missing a tilde, the code you had won't clear the bit

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

Consider using a debugger and stepping the code to understand where it fails.

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 17:19

From some reason I can't find the ''

stm32f0xx.h'' file in my computer.

I have the 

STM32F0xx_hal.h.

where can it be downloaded?

Where should I locate it?

Is it neccesary to 

STM32F051R8 ?

Posted on September 29, 2016 at 17:41

It is part of the Standard Peripheral Library, to which a link was posted earlier

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

Get Software (v1.5.0) bottom of the page.

I unpack them in the \Keil\ARM\Examples\ST directory

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:03

I found the correct command for the clock.

However he led still not blinking.

What else can be wrong with:

 

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

Posted on September 29, 2016 at 18:08

Why are you using i (letter) for these shifts instead of 1 (one)? It makes no sense.

Pay attention to what the GPIO registers get set to, and that they are configured correctly. Review the manual, look at the registers in the debugger.

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:14

#include ''stm32f0xx.h''
int main(void){
volatile unsigned int i=0;
RCC -> AHBENR |= (1<<
19
); // GPIOC
GPIOC ->MODER |= (1<<
16
); // mode 01b Output
GPIOC ->ODR |= (1<<
8
); // output data is ON
while (1) {
for (
i
=
0
; i<1000000; i++); // delay
GPIOC ->ODR |= (1<<
8
); // output data is ON
for (
i
=
0
; i<1000000; i++); // delay
GPIOC ->ODR &= ~(1<<8); // output data is OFF 
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..