2020-05-26 07:00 AM
Hi all,
I'm running an application where I got to initialize an UART (by interruption) transmission at power up . So I'm a initializing like this :
HAL_UART_MspInit(&huart5);
MX_UART5_Init();
There are the basic functions from STM32 Cube MX...
When the product has power up, I need to send data immediatly.
To send the data, I am using a buffer, before I send something I reset the buffer then I fill it with my data.
The problem is that when I power up my product, I have a random byte sent in the UART (this byte can be 0xFF, 0xBF, 0xFD) and then my buffer is sent. The failure rate is around 5% on 1000 tries. Can someone help me or explain me why it happens ?
I know this problem exists from this post https://github.com/RIOT-OS/RIOT/issues/8045 but I still don't know how to solve it.
Thanks in advance.
2020-05-26 08:37 AM
You need to ensure the line stays high until data is sent. If the line drops during initialization, the receiving end thinks there is a byte and tries to interpret it. Putting a small delay before starting the transmission can help.
What board? External pullup on the line?
2020-05-26 08:48 AM
Hi TDK,
Firstly, thanks for your answer.
My board is a STM32F405RGT6. There is no external pullup on the Tx line from my MCU, I got an internal pullup (see below) :
GPIO_InitStruct.Pin = D_UART_TX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF8_UART5;
HAL_GPIO_Init(D_UART_TX_GPIO_Port, &GPIO_InitStruct);
What do you mean by "small" delay, has it to be around 10 ms or less ?
2020-05-26 09:53 AM
Put a delay of several bits. So at 115200 baud, 26us should be enough. The exact value might depend on the receiving end.
The problem is that when there is no external pullup, the line is low, which is not a valid UART signal. Adding the delay after the line is high but before the first start bit will allow the receiver to recover.
Use a logic analyzer on the line to see its behavior. Or if you don't have one, think about what the line is doing.
2020-05-29 12:11 AM
Hello TDK,
I have tried to initialize my Tx GPIO as an input pullup at startup then when I initialize UART I do a 500ms hard delay between initialization and first frame sent but I could easily reproduce the problem after 4 tries ...
Am I missing something ?
Thanks for your help !
2020-05-29 12:22 AM
Look at the line on a logic analyzer to see what's happening. I don't believe the UART sends out a character without being asked to do so. Perhaps the problem is in how you're calling the function.
2020-05-29 03:01 AM
I don't got a logic analyzer at home due to quarantine so here is what I got.
I didn't catched an error after 500 retries but I got this at startup. The signal goes down of 2V during 250µs.
It is how it is represented with startup, delay and my normal frame.
I still don't know if it can be enough to generate fake messages in some cases.
2020-05-29 03:02 AM