2022-11-28 12:46 AM
My idea is, to implement a timer (TIM1 in this case).
Given a certain key pressed, I want to fire it up, let it count down causing an interrupt.
This are the parameters I gave it in the init procedure. (STM32F103C8T6)
static void MX_TIM1_Init(void)
{
/* USER CODE BEGIN TIM1_Init 0 */
/* USER CODE END TIM1_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM1_Init 1 */
/* USER CODE END TIM1_Init 1 */
htim1.Instance = TIM1;
htim1.Init.Prescaler = 7200;
htim1.Init.CounterMode = TIM_COUNTERMODE_DOWN;
htim1.Init.Period = 5000;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_OnePulse_Init(&htim1, TIM_OPMODE_SINGLE) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM1_Init 2 */
/* USER CODE END TIM1_Init 2 */
}
1\ How to I start the timer?
2\ where do I find the IR service routine?
2022-12-18 02:47 AM
@AScha.3 :
> >which callback would I have to implement?
> why add and take callbacks now? use for...what?
Use for what? To do something when the pulse duration has finished, which is normally done effectively by an ISR.
>>BTW, is the logic reversed ? :
> your logic .. ?
You are using my question to build ironical or insulting constructs against me?
Is this conformant with the guidelines of this forum? Moderator please?
I was asking and posting the HAL code, because I was wondering about e.g.:
#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
htim->CommutationCallback(htim);
#else
HAL_TIMEx_CommutCallback(htim);
so, if USE_HAL_TIM_REGISTER_CALLBACKS==1 (true), the code
htim->CommutationCallBack(htim); is executed, but isn't
HAL_TIMEx_CommutCallback(htim); the HAL_TIM_REGISTER_CALLBACK(s)?
2022-12-18 03:29 AM
seem we dont understand each other, so i stop trying to help you. just ignore, what i wrote.
2022-12-18 06:05 AM
> What is the interrupt that is fired, when the timer reaches 65536 (overflow). Is it the Tim1_BREAK interrupt? Or is it the Capture_Compare Interrupt?
These and other questions about configuration are trivial and are explained very well in the reference manual and application notes. Clearly you haven't read any of those. There is a simple truth - using the broken bloatware (HAL) doesn't cancel the reading of documentation for understanding how the hardware works. What you are doing now, is effectively: "I don't want to read the documentation, therefore I will ask other people to read it for me and write code and click CubeMX for me."
> is the logic reversed ?
Maybe analyze what that feature does? Ironically the HAL is used by the people, who do not understand it, because the ones, who go deep enough to understand it, eventually realize it's a junk and stop using it.
You say you are using the HAL, but then the code does something ridiculous with the GPIOx_ODR register directly instead of just using the HAL. You say that you are using TIM1, but then show an ISR for TIM4. You didn't understood that an example is just an example. (How can one fail at that?) Again probably because you think that forum is a place where other people should do the trivial things for you just because you don't want to read the documentation. And, of course, everyone, who criticizes such attitude, should be banned...