Basic timer 6 for time counting using interrupt
Dear ST Hello
I am using timer 6 to calculate the time for timer interrupt triggering,
I am using the example for the board from the cube BSP folder,
\STM32Cube\Repository\STM32Cube_FW_F4_V1.27.1\Projects\STM32F429I-Discovery\Examples\BSP\SW4STM32\STM32F429I-Discovery
In this project, I disable some functions and want to add an interrupt using timer 6.
I generated the code using another project for the interrupt and timer configuration and I integrated the hal timer and timer ex to build the project, I also defined the HAL_TIM_MODULE_ENABLED.
here is the code:
/* Configure USER Button */
//BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
MX_TIM6_Init();
/*##-1- Initialize the LCD #################################################*/
/* Initialize the LCD */
//BSP_LCD_Init();
/* Initialize the LCD Layers */
//BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER);
//Display_DemoDescription();
HAL_TIM_Base_Start_IT(&htim6);
static void MX_TIM6_Init(void)
{
/* USER CODE BEGIN TIM6_Init 0 */
/* USER CODE END TIM6_Init 0 */
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM6_Init 1 */
/* USER CODE END TIM6_Init 1 */
htim6.Instance = TIM6;
htim6.Init.Prescaler = 90-1;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 10000-1;
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM6_Init 2 */
/* USER CODE END TIM6_Init 2 */
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim == &htim6)
{
//toggel an led
BSP_LED_Toggle(LED3);
BSP_LED_Toggle(LED4);
}
}
void TIM6_DAC_IRQHandler(void)
{
/* USER CODE BEGIN TIM6_DAC_IRQn 0 */
/* USER CODE END TIM6_DAC_IRQn 0 */
HAL_TIM_IRQHandler(&htim6);
/* USER CODE BEGIN TIM6_DAC_IRQn 1 */
/* USER CODE END TIM6_DAC_IRQn 1 */
}When I was in the timer init function, I couldn't see the configuration I set for timer 6 in the expression watch, it look all zeros.
In the init function there is a function called HAL_TIM_Base_MspInit(htim);
I am not sure that this function is being called correctly because there is a _weak function and the compilation is done without any error.
Do I have to enable anything cause I am not using the CubeMx?
Thank you in advance,
:)
