Hi,
I am using STM32F407VET6 MCU and trying to receive data using LL API LL_USART_ReceiveData8 over USART configured as modbus.
I confirmed USART transmit (
LL_USART_TransmitData8) is successful through an modbus APP, on rx side of the other device as well as fact that LL_USART_IsActiveFlag_TC is returning True.
I also confirmed other receiving device also sending a 8 byte response back. (Confirmed via Modbus app)
But on the STM32F407VET6 MCU side I am just receiving 1 byte of data.
Note - If I don't insert delay (LL_mDelay) I only get first byte, if I add delay I only get 2nd byte.
After receiving one byte , its just forever waiting on LL_USART_IsActiveFlag_RXNE (never comes out of while loop).
Based on online search I see lots of folks are seeing the same problem (
LL_USART_IsActiveFlag_RXNE getting overrun ?) but could not find solution yet.
If HAL_UART_Receive is used instead of LL_USART_ReceiveDatta8, MCU is receiving complete response.
Below is my code :-
void LL_USART_Transmit(USART_TypeDef *USARTx, uint8_t *buff, uint32_t len)
{
printf("LL_USART_Transmit() rcvd Len= %d\n", len);
for (int i = 0; i < len; i++)
{
LL_USART_TransmitData8(USARTx, buff[i]);
LL_mDelay(10);
if (LL_USART_IsActiveFlag_TC(USARTx)) {
printf("LL_USART_Transmit() successful, data= %d\n", buff[i]);
}
else
{
printf("LL_USART_Transmit() TC flag False");
}
}
}
uint8_t LL_USART_Receive_Byte(USART_TypeDef *USARTx) {
// Wait for Read Data Register is not empty
while (!LL_USART_IsActiveFlag_RXNE(USARTx));
return LL_USART_ReceiveData8(USARTx);
}
void LL_USART_Receive(USART_TypeDef *USARTx, uint8_t *buff, uint32_t len)
{
printf("LL_USART_Receive() rcvd Len= %d\n", len);
for (int i = 0; i < len; i++)
{
buff[i] = LL_USART_Receive_Byte(USARTx);
LL_mDelay(200);
printf("LL_USART_Receive() rx_data= %d\n", buff[i]);
}
}