cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H753: Can't receive the data the controller is sending

jhi
Senior

I'm using the UART (USART5) with RS485 and I have enabled the read to be on also when sending. I need to read back the data that was sent to see if it is correct. The problem is, that I do not receive what was sent. But if I send the same data from other device (without changing any code), I will receive the data. So the receive works, but not the same time with sending.

Initialization - FIFO is also enabled.

 

BaudRate = PARALLEL_BAUD_RATE;
DataWidth = LL_USART_DATAWIDTH_8B;
Parity = LL_USART_PARITY_NONE;
StopBits = LL_USART_STOPBITS_1;
HardwareFlowControl = LL_USART_HWCONTROL_NONE;
OverSampling = LL_USART_OVERSAMPLING_16;
PrescalerValue = LL_USART_PRESCALER_DIV1;
TransferDirection = LL_USART_DIRECTION_TX_RX;

 

And data sending is done with LL_USART_TransmitData8. The half-duplex is not enabled.

What could block the receive when sending?

38 REPLIES 38

The registers were read when I stopped the debugger, so not reading realtime if that is what you meant mmm... 

So I made a test. I have one board sending 0xBB and the one, where I have the debugger, is sending 0xAA. I can only receive what the other board is sending. Never the byte (0xAA) what the current board was sending. As attachment I have included an oscilloscope image of the RX pin. There you can see both bytes and also the waveforms. So there is definitely something wrong with STM32H753 UART5 (I tired also UART4 with same results) implementation (at least with FIFO) or there are some undocumented features which I do not know of. I will try this without FIFO and see if it works then.

Does not work without FIFO either. RDR stays empty until I connect the communication cable between the boards and then the 0xBB is received.

TDK
Guru

It sounds like your transmission code is getting in the way of your reception code. You haven't shown much code so it's difficult to determine what is going on exactly.

If you think it's a hardware issue, post a short compilable code which reproduces the issue.

If you feel a post has answered your question, please click "Accept as Solution".

Well, I did show my transmission code. As I'm only testing, the code is sending 1 byte once in a millisecond with 

LL_USART_TransmitData8(UART5, 0xAA);

It does nothing else. And this command only writes to UART5->TDR. No disabling RX or changing any other registers. I will try to post a sample code (it might take some time).

 

Pavel A.
Evangelist III

It looks like the UART is in half duplex mode, though you say it isn't.

 

The half duplex in STM32H7 would be only TX pin acting as transmitter/receiver. And if you would have checked the registers I posted, you would see that, that is not the case.

Hello @jhi 

So I have tried to read carefully all of questions/answers of this thread. So you are working with UART5 in RS485 mode but you don't use RTS/DE pin to control your external transceiver, is that correct ?

Instead, you are using 2 distinct GPIO to drive DE and !RE so that you can "decide" if yu want to loopback TX to RX and this is the issue you have that you can retrieve the TX data in your test code, is that correct?

So it could be schematize like this :

MikaelM_1-1695219051599.png

If both assumption are correct then I can provide you a code that I have tested with a NUCLEO-H743ZI2 board.

For this example I configure UART5 as asynchronous and loop back PC12 (TX) to PB12(RX) on the board :

MikaelM_0-1695218605543.png

If you have not a nucleo board and want to adapt the code you just have to modify the following code in usart.c file :

/**UART5 GPIO Configuration
PB12 ------> UART5_RX
PC12 ------> UART5_TX
*/
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF14_UART5;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF8_UART5;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

Of course this is not RS482 example but a TX/RX loopback.

I use HAL code and not LL code, but you can compare registers values to try to debug yours.

The chip is an STM32H743ZIT6U

Best regards

Mikael

 

 

 

 

 

If you feel a post has answered your question, please click Accept as Solution.

Thanks @TDK for pushing me to write an example. As the example worked, I found in my original code that, when enabling the RS485 driver to send, I also disabled receiver because I did already have another UART (also RS485) doing something else and there it was not needed to read back what to send.