Hallo,
ich bin hier gerade kurz vorm durchdrehen!!! Ich möchte gerade eine LED
Blinken lassen in COOCOX dafür habe ich einen Code geschrieben, der auch
funktioniert:
1 | #include "stm32f4xx_conf.h"
|
2 | #include "stm32f4xx.h"
|
3 | #include "stm32f4xx_rcc.h"
|
4 | #include "misc.h"
|
5 | #include "stm32f4xx_gpio.h"
|
6 | #include "stm32f4xx_spi.h"
|
7 |
|
8 |
|
9 | uint32_t Ticks=0;
|
10 |
|
11 |
|
12 | void SysTick_Handler(void){
|
13 |
|
14 | if (Ticks !=0)
|
15 | Ticks--;
|
16 |
|
17 | }
|
18 |
|
19 | void Delay(uint16_t cycles ){
|
20 |
|
21 | Ticks = cycles;
|
22 | while (Ticks);
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 | void GPIO_Conf(){
|
28 |
|
29 | GPIO_InitTypeDef GPIO_InitStructure;
|
30 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
31 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
32 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
33 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
34 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
35 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
36 |
|
37 | }
|
38 |
|
39 | int main(void)
|
40 | {
|
41 |
|
42 | SystemInit();
|
43 | SysTick_Config(SystemCoreClock/ 1000);
|
44 | //GPIO_Conf();
|
45 | GPIO_InitTypeDef GPIO_InitStructure;
|
46 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
47 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
48 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
49 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
50 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
51 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
52 |
|
53 | while(1)
|
54 | {
|
55 | GPIO_WriteBit(GPIOA, GPIO_Pin_8, RESET);
|
56 | Delay(500);
|
57 | GPIO_WriteBit(GPIOA, GPIO_Pin_8, SET);
|
58 | Delay(500);
|
59 |
|
60 | }
|
61 | }
|
Das komische ist jetzt, dass wenn ich die Initialisierung vom GPIO in
eine Funktion auslagere, denn funktioniert es auf einmal nicht mehr...
1 | #include "stm32f4xx_conf.h"
|
2 | #include "stm32f4xx.h"
|
3 | #include "stm32f4xx_rcc.h"
|
4 | #include "misc.h"
|
5 | #include "stm32f4xx_gpio.h"
|
6 | #include "stm32f4xx_spi.h"
|
7 |
|
8 |
|
9 | uint32_t Ticks=0;
|
10 |
|
11 |
|
12 | void SysTick_Handler(void){
|
13 |
|
14 | if (Ticks !=0)
|
15 | Ticks--;
|
16 |
|
17 | }
|
18 |
|
19 | void Delay(uint16_t cycles ){
|
20 |
|
21 | Ticks = cycles;
|
22 | while (Ticks);
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 | void GPIO_Conf(){
|
28 |
|
29 | GPIO_InitTypeDef GPIO_InitStructure;
|
30 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
31 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
32 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
33 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
34 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
35 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
36 |
|
37 | }
|
38 |
|
39 | int main(void)
|
40 | {
|
41 |
|
42 | SystemInit();
|
43 | SysTick_Config(SystemCoreClock/ 1000);
|
44 | GPIO_Conf();
|
45 | //GPIO_InitTypeDef GPIO_InitStructure;
|
46 | //RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
47 | //GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
48 | //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
49 | //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
50 | //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
51 | //GPIO_Init(GPIOA, &GPIO_InitStructure);
|
52 |
|
53 | while(1)
|
54 | {
|
55 | GPIO_WriteBit(GPIOA, GPIO_Pin_8, RESET);
|
56 | Delay(500);
|
57 | GPIO_WriteBit(GPIOA, GPIO_Pin_8, SET);
|
58 | Delay(500);
|
59 |
|
60 | }
|
61 | }
|
Woran kann das liegen?