cancel
Showing results for 
Search instead for 
Did you mean: 

USART1 Byte length off for some reason

debug
Associate III

Hi,

 

I am unable to interface with a sensor over RS485. I have a uart->RS485 converter hooked up to pins for USART1 (Tx on PD8, Rx on PD9) on a Nucleo-F439ZI.

I also have a USBtoRS485 converter with which i'm able to communicate to the sensor fine. I have a scope connected onto the B- line and can compare the data.

The sensor prescribes the following UART settings:

  • Data bits: 8
  • Number of stop bits: 1 bit
  • Parity: even
  • Baud rate (bps): 57600 (factory setting)

and I have set USART1 t initialize with the following settings:

huart1.Instance = USART1;

huart1.Init.BaudRate = 57600;

huart1.Init.WordLength = UART_WORDLENGTH_8B;

huart1.Init.StopBits = UART_STOPBITS_1;

huart1.Init.Parity = UART_PARITY_EVEN;

huart1.Init.Mode = UART_MODE_TX_RX;

huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;

huart1.Init.OverSampling = UART_OVERSAMPLING_16;

 

An image looks as can be seen in the attached scope3.jpg picture where RefA (grey) is the recorded (working) signal from the USBtoRS485 converter and CH1 (yellow) is the signal from the Nucleo board. 

I think from thevery beginning of the traces one can see that the bit timing appears to align but weird enough, the second falling edge from the left appears to have a one bit offset. I am sending 5 Bytes, 3 payload Bytes and aCRC16 checksum (per Modbus RTU).

Byte 1 should be the slave address(1)
Byte 2 should be the function ID (4 = read from input register)
Byte 3 should be the register number to read from which in this case ought to be 200.
But to me it appears like something with the stop bit or the parity might be off :-1:

1 ACCEPTED SOLUTION

Accepted Solutions
debug
Associate III

The problem was resolved by setting the word length to 9 bit (because ST apparently counts the parity bit to the actual word size, the sensor I worked with didn't & indicated data bits 😎 

View solution in original post

2 REPLIES 2
SofLit
ST Employee

Hello,


An image looks as can be seen in the attached scope3.jpg picture where RefA (grey) is the recorded (working) signal from the USBtoRS485 converter and CH1 (yellow) is the signal from the Nucleo board. 

No image is attached.

Also you tagged FreeRTOS in the thread. You need also to confirm if you're using RTOS.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
debug
Associate III

The problem was resolved by setting the word length to 9 bit (because ST apparently counts the parity bit to the actual word size, the sensor I worked with didn't & indicated data bits 😎