I am sending RS485 signals from a master (STM32 Nucleo board with a Waveshare - CAN RS485 shield) to a slave (custom PCB). The PCB then responds. I am switching the DE pin in the meantime and I can verify that the RS485 chip successfully receives the response data by using a picoscope to read the signal on the 485_R pin on the shield.
However when I try to read this data using HAL_UART_Receive, I find that I do not get the exact data that I should be getting, but instead receive slightly garbled data, with some bytes correct but some not.
I used STM32IDE.
I set up the .ioc file so that the RX and TX pins matched those that were connected to the relevant RX and TX pins on my hat. I set up the pin connected to 485_E as a GPIO output.
I then used HAL_GPIO_WritePin to set the DE pin positive, used HAL_UART_Transmit to send the message and then used HAL_GPIO_WritePin to set the DE pin negative. I then used HAL_UART_Receive to read the data. I added a Delay of 40ms after the HAL_UART_Receive to allow time to receive the data before looping through again.
This process worked when embedding code using the Simulink embedded coder and the SCI Read block, however I cannot get it to work using the HAL functionality on the STM32IDE for whatever reason.
Just an update on this question:
It appears that the status returned by HAL_UART_Receive is "HAL_TIMEOUT", which I believe originates from the following piece of code in stm32f7_hal_uart.c:
/* Check for the Timeout */
if (Timeout != HAL_MAX_DELAY)
{
if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
{
return HAL_TIMEOUT;
}