Hi everybody!!!!
I am sending an array of 94 bytes using an Arduino Uno to an Arduino Mega. I have used a piece of copper wire to connect the TX terminal of the Uno to the Rx1 terminal of the Mega. Here is the code the I compiled on the Uno:
unsigned char sample[94] = {0x82, 0x81, 0x80, 0x30, 0, 0, 0, 0, 0x21, 0x46, 0x01, 0x1D, 0, 0, 0, 0, 0x3F, 0x01, 0x22, 0x22, 0, 0x06, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0x80, 0x0E, 0, 0, 0, 0, 0xFA, 0, 0, 0x27, 0x85, 0x07, 0x0F, 0x4C, 0x82, 0x80, 0, 0, 0, 0x05, 0x01, 0xC1, 0x13, 0x1D, 0, 0, 0, 0, 0x3F,0x01, 0x22, 0, 0x06, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0, 0, 0, 0xFA, 0, 0, 0x27, 0x85, 0x07, 0xBF, 0x7B};
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600); // talk to car
}
void loop() // run over and over
{
for(int i = 0; i<94; i++)
{
Serial.write(sample[i]);
}
}
My aim is to create two arrays on Mega. One which will contain all the 94 bytes and a second array that will contain the first 91 bytes.
This is the code that I implemented on Mega to achieve this:
#include <avr/pgmspace.h>
unsigned char buff[94];
unsigned char buff2[90];
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600); //talk to laptop
Serial1.begin(9600);
}
void loop() // run over and over
{
if (Serial1.available() >= 63)
{
if (Serial1.read() == 0x82) // Checking if the three starting bytes are present in the incoming data
{
if (Serial1.read() == 0x81)
{
if (Serial1.read() == 0x80)
{
buff[0] = 0x82;
buff[1] = 0x81;
buff[2] = 0x80;
for (int i = 3; i<94; i++) // Put the incoming 94 bytes in buff
{
buff[i] = Serial1.read();
}
}
}
}
for ( int j = 0; j < 91; j++) // Put the first 91 bytes of buff in buff2
{
buff2[j] = buff[j];
}
for (int k =0; k<91; k++) //for debugging purposes
{
Serial.print(buff2[k], HEX);
}
}
}
This is a full block of data that I desired the Uno to send to Mega, attained from the serial port:
828180300000214611D00003F1222206000000000C1080700000000223F046030827000000063F0135FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0FFFFFFFFFFFFFFFFFF828180300000214611D00003F1222206000000000C1080700000000223F046030827000000063F0135FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0FFFFFFFFFFFFFFFFFF
What's puzzling me is the appearance of the "FFFFFFFFFFF" bits in the data flow. This keeps happening in the rest of the data iterations as well.
Any ideas what is happening??
Any hints or advice is much appreciated.