Serial Port Write Delay Between Characters Affecting Device at High Baud Rate

I'm communicating with a serial device on 921600 baud. I am receiving and decoding data, but it's not responding to commands I send it. It appears that the P2 is putting large enough delays between characters that the target device is not accepting them as valid sequences.

This first image shows the trace when a command is sent from a PC via Realterm and a FTDI usb adapter:

Heres the same command sent from the P2 over Serial2.

Is this expected behavior? Is there anything I can do to speed up the transmission rate of characters? The timing between characters looks to be roughly 20us or 50khz, which sounds awfully like a round number that might be related to the threading in FreeRTOS?

The task scheduler in FreeRTOS runs off the 1 millisecond tick timer, or 1000 times per second so this could be a factor at 921600 baud.

Are you doing anything that would yield between characters? Also what is the longest sequence of characters you are sending? If you exceed the transmit buffer size you could also run into blocking and subsequent thread swapping delays, but that could be fixed by using a larger buffer.

Heres the function, it's pretty straightforward...
SerialPort is a pointer a USARTSerial that the object should use, Serial2 in my case

void Benewake_TF03::disable_output()
{
    byte command_disable_output[5] = { 0x5A, 0x05, 0x07, 0x00, 0x66 };
    SerialPort->write(command_disable_output, sizeof(command_disable_output));
}

Sort of relatedly, the next lowest baud rate on the device is 460800, which does work on my P2, BUT 460800 isn't listed as an available baud on the P2 datasheet. It seems to work fine though? Is there a footgun I should know about or is it a possible oversight in the documentation, and 460800 is a valid baud rate for the p2?

On the P2, Photon 2, M-SoM, and Muon UART serial, 2400, 4800, 380400, 460800, baud rates are supported but were not listed. The datasheets and migration guides have been updated.

2 Likes

@willdueease were you seeing any other issues with the Serial2 port on the Photon2 / P2?

I'm trying to interface with a RS-485 driver and getting strange issues after transmitting to the buffer and waiting for completion using flush.