Forum: Mikrocontroller und Digitale Elektronik Mal wieder Blinkschwierigkeiten beim STM32.


von STTS (Gast)


Lesenswert?

Hallo liebes Forum,

aller Anfang ist schwer, so auch beim STM32. Nachdem ich jetzt mehrere 
Blinkprogramme ausprobiert habe, und es auch geschafft hab, eine Led 
anzumachen, klappt das Ganze aber nicht mit dem Blinkten. Ich verwende 
einen STM32F103VC mit einer LED an PinB0. Als IDE verwende ich CooCox.

Was läuft da schief?
1
#include <stm32f10x_conf.h>
2
3
4
void delayLoop() {
5
  volatile uint32_t delayCount = 100000000000; // volatile, um "Wegoptimieren" zu vermeinden
6
                                                //(http://en.wikipedia.org/wiki/Volatile_variable)
7
  while (delayCount > 0) {
8
    delayCount--;
9
  }
10
}
11
12
13
14
15
int main(void)
16
{
17
  GPIO_InitTypeDef GPIO_InitStructure;
18
19
  SystemInit();
20
21
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
22
23
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
24
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
25
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
26
  GPIO_Init(GPIOB, &GPIO_InitStructure);
27
28
  while(1)
29
  {
30
    GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_SET);
31
    delayLoop();
32
    GPIO_WriteBit(GPIOB, GPIO_Pin_0, Bit_RESET);
33
    delayLoop();
34
  }
35
}

von 12V DC (Gast)


Lesenswert?

Bei mir (STM32F4) war es so, das die delay-Funktio nicht funktionierte. 
Ich würde es mit einem SysTickTimer machen, wobei ich mir nicht sicher 
bin, ob das dein Controller auch kann. Ich kenne -wie gesagt- nur den 
STM32F4xx. Schau mal hier: http://www.mystm32.de/doku.php
Sonst google mal Systick STM32F10 und geh die Ergebnisse durch. Wenn du 
da nix findest google mal delay STM32F10.

von Andreas (Gast)


Lesenswert?

Hallo,

der Werte delayCount = 100.000.000.000 ist etwas zu groß.
Wenn die MCU mit 50MHz läuft sollte es bei 50.000.000 mit ca. 1/s 
blinken.

Andreas

von Matthias S. (Firma: matzetronics) (mschoeldgen)


Lesenswert?

So habe ich bei mir den Systicker auf dem VL Discovery konfiguriert:
1
static __IO uint32_t TimingDelay;
2
/**
3
  * @brief  Inserts a delay time.
4
  * @param  nTime: specifies the delay time length, in milliseconds.
5
  */
6
void Delay(uint32_t nTime)
7
{ 
8
  TimingDelay = nTime;
9
  while(TimingDelay != 0);
10
}
11
/**
12
  * @brief  Decrements the TimingDelay variable.
13
  */
14
void TimingDelay_Decrement(void)
15
{
16
  if (TimingDelay != 0x00) TimingDelay--;
17
}
18
void SysTick_Handler(void)
19
{
20
  TimingDelay_Decrement();
21
}
Und dann in main:
1
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
2
  /* Setup SysTick Timer for 100 usec interrupts  */
3
  if (SysTick_Config(SystemCoreClock / 1000))
4
  { 
5
    /* Capture error */ 
6
    while (1);
7
  }
Benutzen dann so:
1
Delay(4000); // Warte 4 Sekunden

Ich benutze Atollic TS, kleine Anpassungen könnten evtl. nötig sein?

: Bearbeitet durch User
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.