2020-03-25 12:06 PM
Hi
I am using a B-L072Z-LRWAN1 development board and I need to read data from a DTH22 sensor.
I am trying to use TIM6 to get a micro second delay, but it seems I am missing something.
The delay function :
void delay (uint16_t time)
{
/* change your code here for the delay in microseconds */
__HAL_TIM_SET_COUNTER(&htim6, 0);
while ((__HAL_TIM_GET_COUNTER(&htim6))<time);
}
The TIM6 initialization:
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 = 50-1;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 0xffff-1;
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
HAL_TIM_Base_Start(&htim6);
/* USER CODE BEGIN TIM6_Init 2 */
/* USER CODE END TIM6_Init 2 */
}
The timer TIM6 is not counting (__HAL_TIM_GET_COUNTER(&htim6) returns alaways 0.
BR
Gilberto
Solved! Go to Solution.
2020-03-25 12:16 PM
Need to make sure the TIM6 clock is enabled, __HAL_RCC_TIM6_CLK_ENABLE();
htim6.Init.Prescaler = 32-1; // If clocking at 32 MHz
htim6.Init.Period = 0xFFFF; // Count 0 thru 65535
The HAL_TIMEx_MasterConfigSynchronization() stuff shouldn't be necessary
2020-03-25 12:16 PM
Need to make sure the TIM6 clock is enabled, __HAL_RCC_TIM6_CLK_ENABLE();
htim6.Init.Prescaler = 32-1; // If clocking at 32 MHz
htim6.Init.Period = 0xFFFF; // Count 0 thru 65535
The HAL_TIMEx_MasterConfigSynchronization() stuff shouldn't be necessary
2020-03-25 01:28 PM
Hi
The clock was not enable. It is now working perfectly.
Thanks a lot!
BR
Gilberto