Author Topic: Arm stm led blinking Help?  (Read 4514 times)

0 Members and 1 Guest are viewing this topic.

Offline babe

  • Contributor
  • Posts: 17
  • Country: it
Arm stm led blinking Help?
« on: October 06, 2013, 04:26:37 pm »
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)" ??
« Last Edit: October 06, 2013, 06:12:45 pm by babe »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Arm stm led blinking Help?
« Reply #1 on: October 06, 2013, 05:41:29 pm »
Without knowing anything about your specific chip, environment, etc., it is hopeless to try to help you.
================================
https://dannyelectronics.wordpress.com/
 

Offline Hideki

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: Arm stm led blinking Help?
« Reply #2 on: October 06, 2013, 05:48:52 pm »
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 thing
      delay(some_milliseconds); // simplistic debounce
   }
   was_pressed = pressed;
}
 

Offline babe

  • Contributor
  • Posts: 17
  • Country: it
Re: Arm stm led blinking Help?
« Reply #3 on: October 06, 2013, 05:54:53 pm »
Without knowing anything about your specific chip, environment, etc., it is hopeless to try to help you.
Hi, my board is STM32F4 discovery, i use keil as ide. Thanks for your interest
 

Offline babe

  • Contributor
  • Posts: 17
  • Country: it
Re: Arm stm led blinking Help?
« Reply #4 on: October 06, 2013, 06:04:56 pm »
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 thing
      delay(some_milliseconds); // simplistic debounce
   }
   was_pressed = pressed;
}


How can i define it for discovery board?
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Arm stm led blinking Help?
« Reply #5 on: October 06, 2013, 06:15:02 pm »
Quote
my board is STM32F4 discovery, i use keil as ide.

You 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.
================================
https://dannyelectronics.wordpress.com/
 

Offline babe

  • Contributor
  • Posts: 17
  • Country: it
Re: Arm stm led blinking Help?
« Reply #6 on: October 06, 2013, 06:21:11 pm »
Quote
my board is STM32F4 discovery, i use keil as ide.

You 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.

1)yes I want to use CMSIS inside Stm32f4 Library

I did those blinkings as a start point. I need to solve that problem now... Please help me......
 

Offline Hideki

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: Arm stm led blinking Help?
« Reply #7 on: October 06, 2013, 06:31:31 pm »
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? :)
 

Offline babe

  • Contributor
  • Posts: 17
  • Country: it
Re: Arm stm led blinking Help?
« Reply #8 on: October 06, 2013, 06:35:35 pm »
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? :)

I just did not understand bool structure ? is it possible to use it in my code?
 

Offline Hideki

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: Arm stm led blinking Help?
« Reply #9 on: October 06, 2013, 06:40:27 pm »
"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.
 

Offline babe

  • Contributor
  • Posts: 17
  • Country: it
Re: Arm stm led blinking Help?
« Reply #10 on: October 06, 2013, 06:46:42 pm »
"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.

Thanks Ideki ........ Thanks all for your responds. Ideki, your logic worked well.. I found this forum site randomly. I am member, too anymore

I changed "int_pressed" part with
int pressed = (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 1);

but this did not work.... i needed to write code all over.
« Last Edit: October 06, 2013, 07:44:57 pm by babe »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8229
  • Country: 00
Re: Arm stm led blinking Help?
« Reply #11 on: October 06, 2013, 06:51:47 pm »
Quote
I need to solve that problem now...

What problem is "that problem"?

Quote
Please help me......

At this point, you need to help others help you - a bad spot to be in.
================================
https://dannyelectronics.wordpress.com/
 

Offline Hideki

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: Arm stm led blinking Help?
« Reply #12 on: October 06, 2013, 07:27:39 pm »
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;

 

Offline Hideki

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: Arm stm led blinking Help?
« Reply #13 on: October 06, 2013, 07:35:50 pm »
Did you just remove the part I was replying to? Sure looks like it...  this thread just gets better and better  :wtf:
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf