Custom made timer or ready made timer for STM32F103C8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-04 9:13 PM
Hi.
I am a beginner in STM32 development. I created a custom timer for STM32F103C8 blue pill in the While Loop which will execute a function to send AT Command to GSM modem as described below. In terms of cpu usage, is it better to create a custom timer or use ready made timers in the MCU? Thank you in advance.
uint32_t counter = 0;
while (1) {
if (counter == 8000000){
HAL_UART_Transmit(&huart1, (uint8_t *)"AT\r",sizeof("AT\r"), 50);
counter = 0;
}
counter++;
}
Solved! Go to Solution.
- Labels:
-
STM32F1 Series
-
TIM
-
UART-USART
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-05 6:54 AM
Also note that the compiler can optimize out the delay entirely because it has no other effect and the variables are not defined as volatile.
HAL_Delay would be a much better solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-04 11:45 PM
What you have created is a busy loop consuming 100% CPU time, this is *not* called a "timer". The simplest improvement would be using HAL_Delay instead of the counter, thereby freeing alot of CPU time. HAL_Delay uses a timer interrupt internally. Next step could be using a dedicated hardware timer and calling HAL_UART_Transmit from its interrupt handler. This also depends on the overall design of your code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-05 6:54 AM
Also note that the compiler can optimize out the delay entirely because it has no other effect and the variables are not defined as volatile.
HAL_Delay would be a much better solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-05 8:13 AM
Hi @TDK​ , @KnarfB​
Thank you for the feedback. HAL Delay is just what i need to estimate the timing for the AT command execution
