Skip to main content
Indois
Associate III
May 15, 2021
Question

Periodical data transmit configuration

  • May 15, 2021
  • 3 replies
  • 874 views

Hello,

I am using STM32L0 MCU and trying to write a code which would include:

  1. Periodically transmitting data1 to UART.
  2. Constantly waiting for data2 (period value) from UART.
  3. If data2 (period value) is received from UART, change value of data1 transmission period to data2.

The problem is that if I use HAL_Delay function for periodical transmission of data1, then program is blocked from constant waiting for data2.

Now I am using timer for periodical transmission every second but I do not know how to change timer period value to other which is received from UART.

I would like to have opportunity to change time periods to 1, 5, 10 or 30 minutes.

Maybe you have some thoughts how such program could be implemented?

This topic has been closed for replies.

3 replies

waclawek.jan
Super User
May 15, 2021

Tuner period is given by TIMx_ARR, you can simply rewrite it, but use preload (TIMx_CR1.ARPE=1) to avoid problem with setting it lower than the current CNT.

Use an appropriate prescaler to allow the range you want to achieve.

JW

Indois
IndoisAuthor
Associate III
May 16, 2021

Thank you for the answer, I will try to rewrite timer period.

Indois
IndoisAuthor
Associate III
May 17, 2021

Now I noticed that a problem occurs when data1 (which I periodically send to UART) consists of two symbols, for example 'AA' or '10'. In such case reception of data2 is blocked and does not not work untill I reprogram/reconnect my STM32 MCU.

I use LL API to accomplish USART communication. Here are lines for periodical data transmit and constant reception mode:

0693W00000AOVjKQAX.png 

In such case data reception is blocked because number 10 is transmitted. When I change 10 to 9, everything works well. Could you help me to solve this problem?