STM32 HAL TMR

Gast #4343534
Lesenswert?

Guten Morgen,

ist hier jemand fit mit STM32 und HAL?
Ich versuche verzweifelt den timer2 mittels HAL so zu konfigurieren, 
dass dieser Periodisch einen IRQ auslöst.

Folgenden noch nicht funktionsfähigen Code habe ich erstellt.
Toolchain ist IAR
1
#include "1283_tmr2.h"
2

3
TIM_HandleTypeDef htim2;
4

5
void tmr2_init (void){
6
  
7
  htim2.Instance = TIM2;
8
  
9
  htim2.Init.Prescaler = 0x00FF;
10
  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
11
  htim2.Init.Period = 0x00FF;
12
  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
13
  //htim2.Init.RepetitionCounter = // only Timer 1 and 8
14
  //htim2.Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
15
  
16
  HAL_TIM_Base_Init(&htim2);
17
  HAL_TIM_Base_MspInit(&htim2);
18
  //HAL_TIM_Base_Start(&htim2);
19
  HAL_TIM_Base_Start_IT(&htim2);
20
  
21
  HAL_NVIC_SetPriority(TIM2_IRQn, 0, 1); 
22
  HAL_NVIC_EnableIRQ(TIM2_IRQn);
23
    
24
  HAL_TIM_IRQHandler(&htim2);
25
  
26
}
27

28
void TIM2_IRQHandler(void)
29
{
30
    if (__HAL_TIM_GET_FLAG(&htim2, TIM_FLAG_UPDATE) != RESET)      //In case other interrupts are also running
31
    {
32
        if (__HAL_TIM_GET_ITSTATUS(&htim2, TIM_IT_UPDATE) != RESET)
33
        {
34
            __HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_UPDATE);
35
            
36
            HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_2);
37
        }
38
    }
39
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren