Dumme Frage:
Ich wollte den Timer2 konfigurieren und immer wenn es runtergezählt hat
sollte es in den TIM2_IRQHandler reingehen.
Dazu dachte ich wenn ich nur die TIM konfiguriere reicht das aus weil ja
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE) aufrufe.
Das ging natürlich nicht aber wenn ich die Interrupt service
routine(NVIC) noch mit definiere geht es prima.
Brauche ich immer dann den Interrupt mit zu definieren wenn ich einen
Timer haben will ? Kann mir da jemand mir bisschen das erläutern ?
1 | in Main:
|
2 |
|
3 |
|
4 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
5 | /* Configure Timer which is every 5 ms active*/
|
6 | TIM_DeInit(TIM2);
|
7 | TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
8 |
|
9 | /* Time base configuration */
|
10 | TIM_TimeBaseStructure.TIM_Prescaler = 16000 - 1; // 16 MHz / 16000 = 1 KHz
|
11 | TIM_TimeBaseStructure.TIM_Period = 1000 - 1; // 1 KHz / 1000 = 1 Hz;
|
12 | TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
13 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
14 | TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
|
15 |
|
16 | /* Enable TIM2 Update Interrupt */
|
17 | TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
|
18 |
|
19 | /* Enable TIM2 */
|
20 | TIM_Cmd(TIM2,ENABLE);
|
21 |
|
22 | /* Enable the Interrupt */
|
23 | NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; // configure the Timer2 interrupts
|
24 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // sets the priority group of the TIMER2 interrupts
|
25 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; // set the subpriority inside the group
|
26 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // TIMER2 interrupts are globally enabled
|
27 | NVIC_Init(&NVIC_InitStructure);
|
28 |
|
29 |
|
30 | außerhalb Main:
|
31 |
|
32 | void TIM2_IRQHandler(void)
|
33 | {
|
34 | static int TIM2_Tick = 0;
|
35 |
|
36 | LCD_DisplayStringLine(Line9, (uint8_t *)'c');
|
37 |
|
38 | UARTSend("CV", 1);
|
39 |
|
40 | if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
|
41 | {
|
42 | TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
|
43 |
|
44 | TIM2_Tick++;
|
45 |
|
46 | if (TIM2_Tick >= 60) // 1 Second
|
47 | {
|
48 | TIM2_Tick = 0;
|
49 | }
|
50 | }
|
51 | }
|