2024-02-15 01:59 AM
I found that LPTIM works at an irregular time delay, it often takes 30-40 seconds
to start counting. Also, when l read the current counter, sometimes the LPTIM drops
(or l think the counter seems to be restarted) before it reaches the counter period(as shown in the
the figure, when reaching the period should print "Hello World!", but in the figure,
the number sometimes drops (or restarts) before printing).
The core code is shown in the following:
int _write(int file, char *ptr, int len){
HAL_UART_Transmit(&huart2,(uint8_t*)ptr,len,HAL_MAX_DELAY);
return len;
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
int timerValue;
int a=0;
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_LPTIM2_Init();
MX_LPUART1_UART_Init();
/* USER CODE BEGIN 2 */
HAL_LPTIM_TimeOut_Start_IT(&hlptim2, Period, Timeout);
HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON,PWR_STOPENTRY_WFI);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
timerValue = HAL_LPTIM_ReadCounter(&hlptim2);
printf("Current: %d\r\n",timerValue);
HAL_Delay(500);
}
/* USER CODE END 3 */
}
2024-02-15 06:59 AM
Please include your chip number in the post.
> HAL_PWR_EnterSTOPMode
Wonder if this is having an effect.
Probably some other code is messing with the timer somewhere.
2024-02-15 07:16 AM
Thanks for your reply. My chip number is nucleo-G071RB. Even if l delete HAL_PWR_EnterSTOPMode, the LPTIM still doesn't work.