Arm stm led blinking Help? - Page 1
Forum section: electronics / general

author: babe
author_rank: Contributor
timestamp: October 06, 2013, 04:26:37 pm
content: Hi, I want turning on LED on STM32f4 microcontroller at the first pressing swith (USER button) and keep it turned on till the next press, I want to turn-off LED at the next press. So how can I do this?what can I add within "while(1)" ??

author: dannyf
author_rank: Super Contributor
timestamp: October 06, 2013, 05:41:29 pm
content: Without knowing anything about your specific chip, environment, etc., it is hopeless to try to help you.

author: Hideki
author_rank: Frequent Contributor
timestamp: October 06, 2013, 05:48:52 pm
content: bool was_pressed = false;while (1){bool pressed = is_button_pressed();if (pressed && !was_pressed) // it's pressed now, and it wasn't pressed before{toggle_led(); // do your thingdelay(some_milliseconds); // simplistic debounce}was_pressed = pressed;}

author: babe
author_rank: Contributor
timestamp: October 06, 2013, 05:54:53 pm
content: Quote from: dannyf on October 06, 2013, 05:41:29 pmHi, my board is STM32F4 discovery, i use keil as ide. Thanks for your interest

author: babe
author_rank: Contributor
timestamp: October 06, 2013, 06:04:56 pm
content: Quote from: Hideki on October 06, 2013, 05:48:52 pmHow can i define it for discovery board?

author: dannyf
author_rank: Super Contributor
timestamp: October 06, 2013, 06:15:02 pm
content: QuoteYou have to ask yourself a few questions:1) do you want to use cmsis?2) do you want to use oem libraries?After that, you need to make sure that you can set up a project according to your answers to question 1+2 above.The simplest way is to start with one of the stock blinkies.The fastest way is to read the compiler manual.

author: babe
author_rank: Contributor
timestamp: October 06, 2013, 06:21:11 pm
content: Quote from: dannyf on October 06, 2013, 06:15:02 pm1)yes I want to use CMSIS inside Stm32f4 LibraryI did those blinkings as a start point. I need to solve that problem now... Please help me......

author: Hideki
author_rank: Frequent Contributor
timestamp: October 06, 2013, 06:31:31 pm
content: babe: You sent me code, twice, in private emails and not as a reply in the forum. I even told you how to change the "pressed" line once. What more you do need?

author: babe
author_rank: Contributor
timestamp: October 06, 2013, 06:35:35 pm
content: Quote from: Hideki on October 06, 2013, 06:31:31 pmI just did not understand bool structure ? is it possible to use it in my code?

author: Hideki
author_rank: Frequent Contributor
timestamp: October 06, 2013, 06:40:27 pm
content: "bool" is a standard C++ data type. If you don't understand it or use pure C code, just replace it with "int" like you already did for the other variable.

author: babe
author_rank: Contributor
timestamp: October 06, 2013, 06:46:42 pm
content: Quote from: Hideki on October 06, 2013, 06:40:27 pmThanks Ideki ........ Thanks all for your responds. Ideki, your logic worked well.. I found this forum site randomly. I am member, too anymoreI changed "int_pressed" part withint pressed = (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 1);but this did not work.... i needed to write code all over.

author: dannyf
author_rank: Super Contributor
timestamp: October 06, 2013, 06:51:47 pm
content: QuoteWhat problem is "that problem"?QuoteAt this point, you need to help others help you - a bad spot to be in.

author: Hideki
author_rank: Frequent Contributor
timestamp: October 06, 2013, 07:27:39 pm
content: Well, you don't seem to understand the importance of telling us the details. Because of that, I gave you pseudo-code.While we may some day all become high level telepaths, our mind reading skills are not yet fully developed.You don't need to declare it. Use the code you already had! (I assume that code was working?)int pressed = GPIOA->IDR & 0x000000001;Note that this isn't using CMSIS but is directly accessing the registers. The CMSIS version I already gave you in the mail (that you didn't read?) was:int pressed = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 1;

author: Hideki
author_rank: Frequent Contributor
timestamp: October 06, 2013, 07:35:50 pm
content: Did you just remove the part I was replying to? Sure looks like it... this thread just gets better and better