LED Blinking with STM32F030F4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-09 4:57 AM
Hi,
I'm using STM32F030F4 MCU for LED blinking function. I used below code with Keil IDE.
But I'm not able to get the output. Boot0 pin pulled low for internal flash boot loader.Added Corresponding ST pheripheral library(gpio,misc,rcc file), CMSIS(core_cm3,system_stm32f0xx) and Startup file.LED connected to Port A_Pin_9. I'm using ST link/v2 for programming. Do I missed anything? or any issue with code?#include <stm32f0xx.h>#include <stm32f0xx_gpio.h>#include <stm32f0xx_rcc.h>GPIO_InitTypeDef Gp;#define GreenLED_Pin GPIO_Pin_9#define LED_GPIO GPIOAvoid delay(unsigned int time) { for(time=0;time>0;time--); } int main(void){ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); Gp.GPIO_Pin=GreenLED_Pin; Gp.GPIO_Mode=GPIO_Mode_OUT; Gp.GPIO_OType=GPIO_OType_OD; Gp.GPIO_Speed=GPIO_Speed_Level_1; GPIO_Init(LED_GPIO,&Gp); while(1) { GPIO_SetBits(LED_GPIO,GreenLED_Pin); delay(10000); GPIO_ResetBits(LED_GPIO,GreenLED_Pin); delay(10000); }}Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-11 6:40 AM
Yes, but there's no VSSA on the TSSOP20 package.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-09 5:33 AM
I'd probably make the time variable volatile so Keil doesn't optimize away the loop.
Try using the debugger to step the code. Try without a delay between them, and just step the two GPIO Set/Reset functions.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-09 1:16 PM
Hi!
void delay(unsigned int time)
{ for(time=0;time>0;time--); }time is unsigned
at first loop (time>0) is false and exits
so the delay until zero is too low
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-09 2:04 PM
Additionally, make the pin as push pull in case the led terminals are swapped by mistake...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-10 12:33 AM
If not clear what Vangelis meant: when entering delay() variable time gets the parameter value (e.g. 10000), but
then for (time=0; erases this value. You may use for statement without initial setting (there is an empty semicolon!!)
like
for ( ; time>0; time--);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-10 12:56 AM
besides defining 'time' as volatile you could also add a few nops in the for-loop.
You could also set up a timer to use as delay comparator , or you can even easily use the internal systick timer and block waiting for it to reach a value.
btw:
in
for(time=0;time>0;time--);
time>0
condition will never be met as you are setting it as 0 in the loop initializer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-10 1:54 AM
Hi,
Yes I made a mistake in delay loop. And I have corrected that. Thanks for that.
Another thing I need to make sure is that, I'm not able to add core_cm3.c file from standard peripheral STM32F0xx library provided by ST. I'm able to add only the header file.
Is it enough? If not means how to get it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-10 4:51 AM
yes vangelis I got your point. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-10 5:34 AM
Hi
Devipriya
!!You use ARM Cortex M0 not M3.
So this file is not suitable for your MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-08-11 1:30 AM
Hi,
The above is my circuit and program. Hope added all library and everything. But I'm unable to make it work in STM32 MCU. Is there anything need to be done in addition to it?
