Skip to main content
CharlieMangold
Senior
August 25, 2023
Solved

STM32G0B0 USART1 data incorrect

  • August 25, 2023
  • 6 replies
  • 3600 views

- STM32G0B0 USART1 receiving RS485 data via interrupt driven data collection.

   Our micro is attached to a RS485 interface(38400, 8,N,1) receiving BACnet data. The data taken on the 485 bus is different from what we receive in the USART buffers. We have reviewed the USART config many times over and can not find anything obvious.

485:        55 FF 01 11 0C 00 00 DC

USART:  55 00 7F 7A DE FF EB 00

Notes: All the 485 packets seem to be 8 bytes in length and the micro received packets can be seven or 8 bytes. The scope trace is taken going into the micro after the 485 chip(THVD1410DR). The scope trace seems to show the second byte as all ones.

We have tried different USART1 configs but the received data always seems wrong after the first byte. Any help is appreciated.

Capture.JPG

 

RigolDS0.jpg

 

	LL_USART_InitTypeDef USART_InitStruct = {0};

	USART_InitStruct.PrescalerValue			= LL_USART_PRESCALER_DIV1;
	USART_InitStruct.BaudRate				= 38400;
	USART_InitStruct.DataWidth				= LL_USART_DATAWIDTH_8B;
	USART_InitStruct.StopBits				= LL_USART_STOPBITS_1;
	USART_InitStruct.Parity					= LL_USART_PARITY_NONE;
	USART_InitStruct.HardwareFlowControl	= LL_USART_HWCONTROL_NONE;
	USART_InitStruct.TransferDirection		= LL_USART_DIRECTION_TX_RX;
	USART_InitStruct.OverSampling			= LL_USART_OVERSAMPLING_16;
	LL_USART_Init(USART1, &USART_InitStruct);
	LL_USART_DisableFIFO(USART1);
	LL_USART_ConfigAsyncMode(USART1);
void USART1_IRQHandler(void)
{
	if(LL_USART_IsActiveFlag_RXNE_RXFNE(USART1) != RESET)
	{
		/* Read one byte from the receive data register and log the current time stamp */
		uart1RxBuffer[rxHead][uart1RX[rxHead].rxSize]	= LL_USART_ReceiveData8(USART1);
		uart1RX[rxHead].rxTime[uart1RX[rxHead].rxSize]	= timer3_get_count();
		uart1RX[rxHead].rxSize++;
 }
}

 

Capture.JPG

This topic has been closed for replies.
Best answer by TDK

UART is typically idle high. Is yours idle low and if so is RXINV set?

Seems like 0x55 0x00 is plausible for the first 2 bytes to me. Start bits in green, stop bits red.

TDK_0-1692977875983.png

 

6 replies

TDK
TDKBest answer
August 25, 2023

UART is typically idle high. Is yours idle low and if so is RXINV set?

Seems like 0x55 0x00 is plausible for the first 2 bytes to me. Start bits in green, stop bits red.

TDK_0-1692977875983.png

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
CharlieMangold
Senior
August 25, 2023

Hmmm, seems like RXINV is off. Not really sure how the RS485 chips takes the twisted pair data and converts it. I'll look at the data sheet. Just seemed weird that the first byte was fine but the second was inverted.

Capture.JPG

 

Capture2.JPG

waclawek.jan
Super User
August 25, 2023

You may have swapped A and B Unfortunately, there's no standard for this, and in some environments (e.g.Modbus) the marking is opposite to what the IC manufacturers use.

JW