Hi All,
I am sending 13 bytes from a Due to a Mega over the UART serial comms running at 1MHz. My code works when two Due's are talking together but when a Mega is receiving I appear to get 9 bytes back, with the first byte as expected but the rest incorrect.
I imagine that the two different processors require different data formats, but I don't have a clue about this. Code snippets are attached below for both Arduinos, including serial outputs.
sending Due code; (data[] is populated in code not shown, but triggered by a request from the Mega)
char data[13];
void setup() {
Serial2.begin(1000000);
Serial.begin(112500);
}
void SendMyserial()
{
//send 13 bytes
for (int i=0;i<13;i++)
{
Serial2.write(data[i]);
}
Serial2.flush();
for (int i=0;i<13;i++)
{
Serial.print(data[i],HEX);
Serial.print(",");
}
Serial.println("");
}
Mega code for receiving data is below;
long i;
long istep = 1000;
void setup() {
Serial2.begin(1000000);
Serial.begin(112500);
}
void loop() {
// put your main code here, to run repeatedly:
if (millis() > i+istep)
{
Serial2.write(0x3A); //send command to due to get data
delay(5);
while(Serial2.available() >0)
{
Serial.print(Serial2.read(),HEX);
Serial.print(",");
}
Serial.println("");
i = millis();
}
}
The data sent by the Due is for example this; (13 bytes)
A2,1,4C,2A,40,0,0,85,F0,F0,F0,F0,F0,
and the same data as received by the Mega looks like this; (only appears to have received 9 bytes)
A2,C0,29,9,1,0,30,F0,F0,
The same code when used with two Dues produces expected results so I can rule out electrical noise and most other issues I think.
How do I fix my code? I have run out of ideas.
Thanks in advance,
Finlay