Hallo,
auf einem STM32F1 Board (kein Discovery) ohne externen Quartz versuche
ich einen LED mit 500ms Verzögerung zu toggeln. Dabei stimmt der Delay
nicht.
Wenn ich die SysTick_Config(SystemCoreClock / 1400) so setze, stimmt
Delay so ungefähr.
Weiss jemand, woran das liegt?
Danke!
1 | #include "stm32f10x.h"
|
2 |
|
3 | static __IO uint32_t TimingDelay;
|
4 | void Delay(uint32_t nTime);
|
5 | void TimingDelay_Decrement(void);
|
6 |
|
7 |
|
8 | int main(void)
|
9 | {
|
10 | GPIO_InitTypeDef GPIO_InitStructure;
|
11 |
|
12 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
13 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
14 |
|
15 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
16 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
17 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
18 | GPIO_Init(GPIOB, &GPIO_InitStructure);
|
19 |
|
20 | GPIO_SetBits(GPIOB, GPIO_Pin_2);
|
21 |
|
22 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
23 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
|
24 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
25 | GPIO_Init(GPIOC, &GPIO_InitStructure);
|
26 |
|
27 | SysTick_Config(SystemCoreClock / 1000);
|
28 |
|
29 | while (1)
|
30 | {
|
31 | GPIO_ResetBits(GPIOB, GPIO_Pin_2);
|
32 | GPIO_ResetBits(GPIOC, GPIO_Pin_13);
|
33 |
|
34 | Delay(500);
|
35 |
|
36 | GPIO_SetBits(GPIOB, GPIO_Pin_2);
|
37 | GPIO_SetBits(GPIOC, GPIO_Pin_13);
|
38 |
|
39 | Delay(500);
|
40 | }
|
41 | }
|
42 |
|
43 | void Delay(uint32_t nTime)
|
44 | {
|
45 | TimingDelay = nTime;
|
46 |
|
47 | while(TimingDelay != 0);
|
48 | }
|
49 |
|
50 |
|
51 | void TimingDelay_Decrement(void)
|
52 | {
|
53 | if (TimingDelay != 0x00)
|
54 | {
|
55 | TimingDelay--;
|
56 | }
|
57 | }
|
58 |
|
59 |
|
60 | #ifdef USE_FULL_ASSERT
|
61 |
|
62 | void assert_failed(uint8_t* file, uint32_t line)
|
63 | {
|
64 | /* User can add his own implementation to report the file name and line number,
|
65 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
66 |
|
67 | /* Infinite loop */
|
68 | while (1)
|
69 | {
|
70 | }
|
71 | }
|
72 |
|
73 | #endif
|