Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

STM32F4 TIM3 interrup problem

[es] :: Elektronika :: Mikrokontroleri :: STM32F4 TIM3 interrup problem

[ Pregleda: 2176 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

zivadin_despot
Živadin Despotović
Novi Sad

Član broj: 175438
Poruke: 704
*.dynamic.isp.telekom.rs.



+5 Profil

icon STM32F4 TIM3 interrup problem15.12.2014. u 00:02 - pre 96 meseci
Pozdrav svima imam problem sa tajmer interaptom, pa ako moze mala pomoc. Naime ne menja mi stanje diode, tj tajmer 3 ne odlazi u interapt. Ne znam gde je greska u konfiguraciji...
Code:

#include <stdio.h>
#include "diag/Trace.h"

#include "stm32f4xx.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_rcc.h"
#include "stm32f4xx_hal_gpio.h"
#include "stm32f4xx_hal_tim.h"


#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#pragma GCC diagnostic ignored "-Wreturn-type"

static void SystemClock_Config(void)
{
    /**
      * @brief  System Clock Configuration
      *         The system Clock is configured as follow :
      *            System Clock source            = PLL (HSE)
      *            SYSCLK(Hz)                     = 168000000
      *            HCLK(Hz)                       = 168000000
      *            AHB Prescaler                  = 1
      *            APB1 Prescaler                 = 4
      *            APB2 Prescaler                 = 2
      *            HSE Frequency(Hz)              = 8000000
      *            PLL_M                          = 8
      *            PLL_N                          = 336
      *            PLL_P                          = 2
      *            PLL_Q                          = 7
      *            VDD(V)                         = 3.3
      *            Main regulator output voltage  = Scale1 mode
      *            Flash Latency(WS)              = 5
      * @param  None
      * @retval None
      */

  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_OscInitTypeDef RCC_OscInitStruct;

  /* Enable Power Control clock */
  __PWR_CLK_ENABLE();

  /* The voltage scaling allows optimizing the power consumption when the device is
     clocked below the maximum system frequency, to update the voltage scaling value
     regarding system frequency refer to product datasheet.  */
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /* Enable HSE Oscillator and activate PLL with HSE as source */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 7;

  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
     clocks dividers */
  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
//opis je na strani 551 knjige sa opisom HAL driver-a
}

void GPIO_Init()
{
    //led dioda na PD12=======================
    __GPIOD_CLK_ENABLE(); //omogucen klok za GPIOD
    GPIO_InitTypeDef GpioStructure;
    //konfiguracija pina
    GpioStructure.Pin=GPIO_PIN_12;
    GpioStructure.Mode=GPIO_MODE_OUTPUT_PP;
    GpioStructure.Pull=GPIO_PULLUP;
    GpioStructure.Speed=GPIO_SPEED_FAST;
    HAL_GPIO_Init(GPIOD, &GpioStructure);
    //========================================
}

TIM_HandleTypeDef TIM_Handle; //glavna struktura

void TMR_Init()
{
    __TIM3_CLK_ENABLE(); //omogucen klok za tajmer 3
    
    TIM_ClockConfigTypeDef sClockSourceConfig;
    //klok tajmera source====================================
    sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
    HAL_TIM_ConfigClockSource(&TIM_Handle, &sClockSourceConfig);
    //======================================================
    //konfiguracija tajmera 3=========================
    TIM_Handle.Instance=TIM3;
    TIM_Handle.Init.ClockDivision=TIM_CLOCKDIVISION_DIV1;
    TIM_Handle.Init.CounterMode=TIM_COUNTERMODE_UP;
    TIM_Handle.Init.Period=1000;
    TIM_Handle.Init.Prescaler=16000;
    HAL_TIM_Base_Init(&TIM_Handle);
    //=================================================
    //omoguci interapt========================
    HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0); //najnizi prioritet
    HAL_NVIC_EnableIRQ(TIM3_IRQn); //omogucen interapt
    //========================================
}
//hendler prekida za tmr3
void TIM3_IRQHandler()
{
    HAL_TIM_IRQHandler(&TIM_Handle);
}
//interapt za tmr3
void HAL_TIM_PeriodElapsedCallback (TIM_HandleTypeDef *htim)
{
     HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
}

int
main(int argc, char* argv[])
{
  HAL_Init(); //inicijalizacija HAL drajvera
  SystemClock_Config();
  GPIO_Init();
  TMR_Init();

  HAL_TIM_Base_Start_IT(&TIM_Handle); //pokreni tajmer 3 u interapt modu

  while (1)
    {

    }
}

#pragma GCC diagnostic pop

Radjeno u Eclipse (Luna) + GCC-ARM + GNUARMEclipse + OpenOCD
U pitanju je plocica Discovery sa kontrolerom STM32F407VGT6

Ovo je kod za eksterni interrupt koji radi:

Code:

#include <stdio.h>
#include "diag/Trace.h"

#include "stm32f4xx.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_rcc.h"
#include "stm32f4xx_hal_gpio.h"


#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#pragma GCC diagnostic ignored "-Wreturn-type"

static void SystemClock_Config(void)
{
    /**
      * @brief  System Clock Configuration
      *         The system Clock is configured as follow :
      *            System Clock source            = PLL (HSE)
      *            SYSCLK(Hz)                     = 168000000
      *            HCLK(Hz)                       = 168000000
      *            AHB Prescaler                  = 1
      *            APB1 Prescaler                 = 4
      *            APB2 Prescaler                 = 2
      *            HSE Frequency(Hz)              = 8000000
      *            PLL_M                          = 8
      *            PLL_N                          = 336
      *            PLL_P                          = 2
      *            PLL_Q                          = 7
      *            VDD(V)                         = 3.3
      *            Main regulator output voltage  = Scale1 mode
      *            Flash Latency(WS)              = 5
      * @param  None
      * @retval None
      */

  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_OscInitTypeDef RCC_OscInitStruct;

  /* Enable Power Control clock */
  __PWR_CLK_ENABLE();

  /* The voltage scaling allows optimizing the power consumption when the device is
     clocked below the maximum system frequency, to update the voltage scaling value
     regarding system frequency refer to product datasheet.  */
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /* Enable HSE Oscillator and activate PLL with HSE as source */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 7;

  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
     clocks dividers */
  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
//opis je na strani 551 knjige sa opisom HAL driver-a
}

void GPIO_Init()
{
    //led dioda na PD12=======================
    __GPIOD_CLK_ENABLE();
    GPIO_InitTypeDef GpioStructure;

    GpioStructure.Pin=GPIO_PIN_12;
    GpioStructure.Mode=GPIO_MODE_OUTPUT_PP;
    GpioStructure.Pull=GPIO_PULLUP;
    GpioStructure.Speed=GPIO_SPEED_FAST;
    HAL_GPIO_Init(GPIOD, &GpioStructure);
    //========================================
    //plavi taster za eksterni interapt=======
    __GPIOA_CLK_ENABLE();
    GPIO_InitTypeDef GpioStructure2;

    GpioStructure2.Pin=GPIO_PIN_0;
    GpioStructure2.Mode=GPIO_MODE_IT_RISING;
    GpioStructure2.Pull=GPIO_NOPULL;
    GpioStructure2.Speed=GPIO_SPEED_FAST;
    HAL_GPIO_Init(GPIOA, &GpioStructure2);
    //omoguci interapt========================
    HAL_NVIC_SetPriority(EXTI0_IRQn, 2, 0);
    HAL_NVIC_EnableIRQ(EXTI0_IRQn);
    //========================================

}

void EXTI0_IRQHandler(void)
{
  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0); //hendler cuva zahtev za prekid
}


void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) //funkcija dobija poziv za prekid
{

  if(GPIO_Pin==GPIO_PIN_0)
  {
      HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
  }

}


int
main(int argc, char* argv[])
{
  HAL_Init();
  SystemClock_Config();
  GPIO_Init();
  
  while (1)
    {


    }
}

#pragma GCC diagnostic pop


Hvala na pomoci...
 
Odgovor na temu

zivadin_despot
Živadin Despotović
Novi Sad

Član broj: 175438
Poruke: 704
*.dynamic.isp.telekom.rs.



+5 Profil

icon Re: STM32F4 TIM3 interrup problem15.12.2014. u 00:08 - pre 96 meseci
Ovde je pdf sa opisom HAL driver-a...
 
Odgovor na temu

zivadin_despot
Živadin Despotović
Novi Sad

Član broj: 175438
Poruke: 704
*.dynamic.isp.telekom.rs.



+5 Profil

icon Re: STM32F4 TIM3 interrup problem15.12.2014. u 00:44 - pre 96 meseci
Pozdrav, reseno je... Evo koda gde su konfigurisana dva tajmera i kontrolisu zelenu i crvenu diodu na plocici.

Code:

#include <stdio.h>
#include "diag/Trace.h"

#include "stm32f4xx.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_rcc.h"
#include "stm32f4xx_hal_gpio.h"
#include "stm32f4xx_hal_tim.h"


#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#pragma GCC diagnostic ignored "-Wreturn-type"

static void SystemClock_Config(void)
{
    /**
      * @brief  System Clock Configuration
      *         The system Clock is configured as follow :
      *            System Clock source            = PLL (HSE)
      *            SYSCLK(Hz)                     = 168000000
      *            HCLK(Hz)                       = 168000000
      *            AHB Prescaler                  = 1
      *            APB1 Prescaler                 = 4
      *            APB2 Prescaler                 = 2
      *            HSE Frequency(Hz)              = 8000000
      *            PLL_M                          = 8
      *            PLL_N                          = 336
      *            PLL_P                          = 2
      *            PLL_Q                          = 7
      *            VDD(V)                         = 3.3
      *            Main regulator output voltage  = Scale1 mode
      *            Flash Latency(WS)              = 5
      * @param  None
      * @retval None
      */

  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_OscInitTypeDef RCC_OscInitStruct;

  /* Enable Power Control clock */
  __PWR_CLK_ENABLE();

  /* The voltage scaling allows optimizing the power consumption when the device is
     clocked below the maximum system frequency, to update the voltage scaling value
     regarding system frequency refer to product datasheet.  */
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /* Enable HSE Oscillator and activate PLL with HSE as source */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 7;

  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
     clocks dividers */
  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
//opis je na strani 551 knjige sa opisom HAL driver-a
}

void GPIO_Init()
{
    //led dioda na PD12=======================
    __GPIOD_CLK_ENABLE(); //omogucen klok za GPIOD
    GPIO_InitTypeDef GpioStructure;
    //konfiguracija pina
    GpioStructure.Pin=GPIO_PIN_12 | GPIO_PIN_14;
    GpioStructure.Mode=GPIO_MODE_OUTPUT_PP;
    GpioStructure.Pull=GPIO_PULLUP;
    GpioStructure.Speed=GPIO_SPEED_FAST;
    HAL_GPIO_Init(GPIOD, &GpioStructure);
    //========================================
}

TIM_HandleTypeDef TIM_Handle; //glavna struktura
TIM_HandleTypeDef htim4;
/*
Prescaler = (TIM3CLK / TIM3 counter clock) - 1
Prescaler = ((SystemCoreClock /2) /TIM3 counter clock) - 1
*/

void TMR3_Init()
{
    __TIM3_CLK_ENABLE(); //omogucen klok za tajmer 3

    //konfiguracija tajmera 3=========================
    TIM_Handle.Instance=TIM3;
    TIM_Handle.Init.ClockDivision=TIM_CLOCKDIVISION_DIV1;
    TIM_Handle.Init.CounterMode=TIM_COUNTERMODE_UP;
    TIM_Handle.Init.Period=1000;
    TIM_Handle.Init.Prescaler=16000;
    HAL_TIM_Base_Init(&TIM_Handle);
    //=================================================
    //omoguci interapt========================
    HAL_NVIC_SetPriority(TIM3_IRQn, 2, 0); //najnizi prioritet
    HAL_NVIC_EnableIRQ(TIM3_IRQn); //omogucen interapt
    //========================================
}
void TMR4_Init()
{
    __TIM4_CLK_ENABLE(); //omogucen klok za tajmer 4

    //konfiguracija tajmera 3=========================
    htim4.Instance=TIM4;
    htim4.Init.ClockDivision=TIM_CLOCKDIVISION_DIV1;
    htim4.Init.CounterMode=TIM_COUNTERMODE_UP;
    htim4.Init.Period=2000;
    htim4.Init.Prescaler=16000;
    HAL_TIM_Base_Init(&htim4);
    //=================================================
    //omoguci interapt========================
    HAL_NVIC_SetPriority(TIM4_IRQn, 0, 0); //najnizi prioritet
    HAL_NVIC_EnableIRQ(TIM4_IRQn); //omogucen interapt
    //========================================
}
//hendler prekida za tmr3 i 4
void TIM3_IRQHandler()
{
    HAL_TIM_IRQHandler(&TIM_Handle);
}
void TIM4_IRQHandler()
{
    HAL_TIM_IRQHandler(&htim4);
}
//interapt za tmr3 i 4
void HAL_TIM_PeriodElapsedCallback (TIM_HandleTypeDef *htim)
{
     if(htim->Instance==TIM_Handle.Instance) HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
     if(htim->Instance==htim4.Instance) HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_14);
}

int
main(int argc, char* argv[])
{
  HAL_Init(); //inicijalizacija HAL drajvera
  SystemClock_Config();
  GPIO_Init();
  TMR3_Init();
  TMR4_Init();

  HAL_TIM_Base_Start_IT(&TIM_Handle); //pokreni tajmer 3 u interapt modu
  HAL_TIM_Base_Start_IT(&htim4);

  while (1)
    {

    }
}

#pragma GCC diagnostic pop


Obrisan je samo klok sors

Code:

   //klok tajmera source====================================
    sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
    HAL_TIM_ConfigClockSource(&TIM_Handle, &sClockSourceConfig);
    //======================================================

 
Odgovor na temu

[es] :: Elektronika :: Mikrokontroleri :: STM32F4 TIM3 interrup problem

[ Pregleda: 2176 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.