Forum: Mikrocontroller und Digitale Elektronik toggle über den User-Butto


von ABKH (Gast)


Lesenswert?

Hallo,

Kann jemand mir sagen, warum werden die LEDs nicht ON gehen, wenn der 
User-Button gedruckt wird. Ich experementiere mit STM32F4-Descovery 
Board und hier ist mein Code:

#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"




int main (void)
{

GPIO_InitTypeDef GPIO_InitDef;


/*LED section*/

/*1)To be able to work with pin, I have to enable pin clock
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);


/*2) I have to set the options of the pins, which I use*/
//A) determine the affected Pins
GPIO_InitDef.GPIO_Pin= GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14 | 
GPIO_Pin_15;
//B) select the Mode of Pins Operation.( Output Mode)
GPIO_InitDef.GPIO_Mode= GPIO_Mode_OUT;
//C) I specialize the Output Mode for Push-Pull output type
GPIO_InitDef.GPIO_OType= GPIO_OType_PP;
//D) Output Mode without Pull resistor
GPIO_InitDef.GPIO_PuPd= GPIO_PuPd_NOPULL;
//E) I have to determine the Speed of the Pins
GPIO_InitDef.GPIO_Speed= GPIO_Speed_50MHz;

//At the Ende comes the Initialization on the Port D
GPIO_Init(GPIOD, &GPIO_InitDef);

/*3) I turn ON the LEDs by setting the Pins HIGH
GPIO_SetBits(GPIOD, GPIO_Pin_13 | GPIO_Pin_14);


Bis hier hat das Code funktioniert, Nach kompilieren und Laden auf das 
µC waren die LED tatsächlich ON

um die Leds über den User-Button leuchten zu lassen, habe ich das Code 
so ergänzt:


/*********************************************************************** 
*/
/*User Button sections*/
/*1)To be able to work with pin, I have enabled pin clock 
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

/*2) Now I set the options of the PA0 as following:*/
//A) determine the affected Pin
GPIO_InitDef.GPIO_Pin= GPIO_Pin_0;
//B) I initialize the pin for input Mode
GPIO_InitDef.GPIO_Mode= GPIO_Mode_IN;
//C) I specialize the Input Mode
GPIO_InitDef.GPIO_OType= GPIO_OType_PP;
//D) with Pull down Resistor
GPIO_InitDef.GPIO_PuPd= GPIO_PuPd_DOWN;
//E) I have to determine the Speed of the Pins
GPIO_InitDef.GPIO_Speed= GPIO_Speed_50MHz;

//At the Ende comes the Initialization on the Port A
GPIO_Init(GPIOA, &GPIO_InitDef);


/*3) To read the Value on PA0: returns pin state (1 for High, 0 for 
Low)*/
if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0))
  {
    GPIO_SetBits(GPIOD, GPIO_Pin_13 | GPIO_Pin_14);

  }

}

Nach dem Ich den Teil von User_button mitkompiliert, zwar das Code 
Fehlerfrei kopmiliert wurde, aber wenn ich den Button drucke leuchten 
die Leds nicht. Mit Osci habe ich das Signal geprüft, und ich sah, wie 
Buttonsignal auf High ging, wenn ich den Button gedruckt habe. Aber die 
Leds leuchten nicht.

Für Feedback wäre ich sehr bedankbar.

von ABKH (Gast)


Lesenswert?

Danke, ich habe den Fehler gefunden.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.