Hey all,
I’m having some issues with the Serial1 peripheral.
I have an application which has pretty tight timings, specifically modbus.
It specifies the end-of-frame as 3.5 character periods. At 9600 baud that means each byte takes about 1.2 ms, so a T35 period is 4.8 or 5 ms.
We’ve been doing this for a while, but recently I’ve found something breaking when attempting to integrate with a new sensor (which might implement the spec a bit more strictly!). It seems that Serial1 is delivering information in bursts, with blank periods between them.
I’ve written a minimal reproduction, which I connected via a RS-485 converter to qmodbus (you should be able to use a USB-Serial converter. It shows the data being delivered, but it’s split into modbus frames (seems to be splitting at 5 bytes).
The digital writes are in-place to activate other peripheral hardware. They aren’t necessary, but I figured I’d keep them in for completeness.
Anyone have any insight into this? I’ve tried single threaded and atomic blocks to no avail. I’m using Device OS 0.6.4
#include <application.h>
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
void setup()
{
Serial.begin();
Serial1.begin(9600, SERIAL_8N1);
pinMode(A5, OUTPUT);
digitalWrite(A5, HIGH);
Serial.println("Started");
}
void loop()
{
Serial.println("Sending");
uint8_t data[] = { 0x02, 0x03, 0x00, 0x0d, 0x00, 0x02, 0x55, 0xfb};
delay(1000);
SINGLE_THREADED_BLOCK() {
digitalWrite(A5, LOW);
delay(10);
while(Serial1.available()) { Serial1.read(); }
Serial1.flush();
for(int i = 0; i < 8; ++i)
{
Serial1.write(data[i]);
}
Serial1.flush();
delay(5);
digitalWrite(A5, HIGH);
}
delay(1000);
}