2016-09-27 07:36 PM
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-stm32f02016-09-28 01:19 AM
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);2016-09-28 04:02 AM
2016-09-28 05:28 AM
I'm not sure if there is a complete list of commands per se...
for starting, I would recommend downloading the (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.chm2016-09-28 05:58 AM
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.2016-09-29 08:19 AM
From some reason I can't find the ''
stm32f0xx.h'' file in my computer.
I have theSTM32F0xx_hal.h.
where can it be downloaded?Where should I locate it?Is it neccesary toSTM32F051R8 ?
2016-09-29 08:41 AM
It is part of the Standard Peripheral Library, to which a link was posted earlier
Get Software (v1.5.0) bottom of the page.I unpack them in the \Keil\ARM\Examples\ST directory2016-09-29 09:03 AM
GPIOC ->ODR |= (i<<8); // output data is ON.
2016-09-29 09:08 AM
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.2016-09-29 09:14 AM
#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
}
}