2023-07-13 07:28 AM
I modified the LoRaWAN_End_Node sample program for measuring the external pulses input to the COMP1. I register a task in the sequencer and set up the timer in timer server. It is no problem to run a test task by just toggle the LED. When I initialize the lptim1 timer to count the external pulse, the program jump to the while(1) loop in Error_Handler. Checking by breakpoints, it is because the LPTIM_WaitForFlag function resulted HAL_TIMOUT. Below is the code of lptim1 initialization.
void LPTIM1_Init(void)
{
hlptim1.Instance = LPTIM1;
hlptim1.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
hlptim1.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
hlptim1.Init.UltraLowPowerClock.Polarity = LPTIM_CLOCKPOLARITY_RISING;
hlptim1.Init.UltraLowPowerClock.SampleTime = LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION;
hlptim1.Init.Trigger.Source = LPTIM_TRIGSOURCE_6;
hlptim1.Init.Trigger.ActiveEdge = LPTIM_ACTIVEEDGE_RISING;
hlptim1.Init.Trigger.SampleTime = LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION;
hlptim1.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
hlptim1.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
hlptim1.Init.CounterSource = LPTIM_COUNTERSOURCE_EXTERNAL;
hlptim1.Init.Input1Source = LPTIM_INPUT1SOURCE_COMP1;
hlptim1.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
if (HAL_LPTIM_Init(&hlptim1) != HAL_OK)
{
Error_Handler();
}
// Start Counting
if (HAL_LPTIM_Counter_Start(&hlptim1, 0xFFFF)!= HAL_OK)
{
Error_Handler();
}
// lptim1 enable
hlptim1.Instance->CR |= 0x00000001;
// lptim1 continuous mode
hlptim1.Instance->CR |= 0x00000004;
}
I would be grateful if any expert can help to solve the problem.
Thanks
Solved! Go to Solution.
2023-07-14 08:30 AM
Hello @W.K. Tam and welcome to ST Community.
I suggest you to:
Also, you can try to increase the timeout value for LPTIM_WaitForFlag to see if that resolves the issue.
I hope this is helpful for you.
Issam
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-07-14 08:30 AM
Hello @W.K. Tam and welcome to ST Community.
I suggest you to:
Also, you can try to increase the timeout value for LPTIM_WaitForFlag to see if that resolves the issue.
I hope this is helpful for you.
Issam
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-07-18 07:57 PM
Hi @IIRHO.1 ,
Thanks for your help. I solved the problem by using STM32cubeMX to initialize the lptim. My problem may be caused by COMP1 which is not connected to the DAC input properly. Anyway, using STM32cubeMX to do the setting, it works well.
Thanks,
W.K. Tam
2023-07-19 11:20 PM
Hello again and thank you for your feedback.
If your question is answered, please close this topic by choosing "Accept as Solution". This will help other users find that answer faster.
Issam
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.