bodger
New member
I was writing some code to transfer binary numbers over a serial port and it kept getting out of synch. I kept simplifying the code until it was about as trivial as it can be (sends 0x11, 0x22, 0x33 repeatedly, with a delay). The output is still out of order. Here's the code:
Here's a hex dump of what I receive:
This is with a Teensy 3.2 using the USB serial port. I don't think I'm overflowing any buffers, I'm not overclocking, and I don't think the compiler is reordering the code (I've tried it with both 72MHz optimize speed and 72MHz reduce code size). If I uncomment the line to send 0x44, I get this:
My original application sent 0xff synch bytes, along with 4-byte floating point values. I'd get the synch bytes scattered throughout my data, not every 5th byte as expected.
Code:
#define SERIALPORT Serial
void
setup()
{
SERIALPORT.begin(9600);
}
void
loop()
{
SERIALPORT.write((byte) 0x11);
SERIALPORT.write((byte) 0x22);
SERIALPORT.write((byte) 0x33);
//SERIALPORT.write((byte) 0x44);
delay(100);
}
Here's a hex dump of what I receive:
Code:
0000000 2211 1133 3322 2211 1133 3322 2211 1133
0000020 3322 2211 1133 3322 2211 1133 3322 2211
0000040 1133 3322 2211 1133 3322 2211 1133 3322
This is with a Teensy 3.2 using the USB serial port. I don't think I'm overflowing any buffers, I'm not overclocking, and I don't think the compiler is reordering the code (I've tried it with both 72MHz optimize speed and 72MHz reduce code size). If I uncomment the line to send 0x44, I get this:
Code:
0000000 2211 4433 2211 4433 2211 4433 2211 4433
My original application sent 0xff synch bytes, along with 4-byte floating point values. I'd get the synch bytes scattered throughout my data, not every 5th byte as expected.