Brion Sohn
Well-known member
OK So I have this code to read the serial that is coming over my HC-05 Bluetooth connection but there is an oddity:
The Variables used are as follows:
the data being sent to this code is RAW BYTEs
So when I have serial1DataPkg @ 8 everything works Fine but I would like a longer Data stream to be recorded.
i.e Sent data of "01 02 03 04 05 06 07 FF" works fine and populates the serial1Data array properly.
The ISSUE is when I want to set it longer i.e. serial1DataPkg @ 10
when I sent "01 02 03 04 05 06 07 08 09 FF" i get the following in the serial1Data "01 02 03 04 05 06 07 08 00 FF"
So I tried serial1DataPkg @ 16
when I sent "01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F FF" i get the following in the serial1Data "01 02 03 04 05 06 07 08 00 10 11 12 13 14 15 FF"
So for some reason something is Zeroing out the 8th Byte when sending over 8 Bytes and I can't for the live of me figure out why.. Technically I can write code around that oddity but Im really wondering what might be causing it.
Any ideas?
Code:
void serialEvent1() {
if (Serial1.available() > 0) {
delayMicroseconds(1500);
incomingByte1 = (byte)Serial1.read(); // get a single byte
if (serial1Step != endOfPkg1 ) {
serial1Buffer [serial1Step] = incomingByte1; // place read Byte in buffer array.
serial1Step = serial1Step + 1; // step for next processor loop
} else if (serial1Step == endOfPkg1) { // check for end of package defined by serial1DataPkg
serial1Buffer [serial1Step] = incomingByte1; // place read Byte in buffer array.
serial1Step = 0; // reset counter
if (serial1Buffer[endOfPkg1] == errorCheckEnd1) { // data checksum byte check (error check)
for (byte c = 0; c < serial1DataPkg; c++) {
serial1Data[c] = serial1Buffer[c]; // copy serial1Buffer to serialData
}
}
for (byte r = 0; r < serial1BufferSize; r++) {
serial1Buffer[r] = 0; // reset serial1Buffer
}
}
}
The Variables used are as follows:
Code:
// serial function variables
#define serial1DataPkg 8
#define errorCheckEnd1 0xFF
byte serial1Step = 0; // tracks how many processor loops have passed for serial1.read
byte incomingByte1; // single byte serial1.read variable
const byte serial1BufferSize = serialDataPkg + 0; // set serialBufferSize and adjust serial1BufferSize for EOL check (if needed)
byte serial1Buffer [serial1BufferSize]; // incoming serial1 buffer
byte serial1Data [serial1DataPkg]; // serial1Data package
byte endOfPkg1 = serial1DataPkg - 1; // serial1 package length (adjustment for 0)
the data being sent to this code is RAW BYTEs
So when I have serial1DataPkg @ 8 everything works Fine but I would like a longer Data stream to be recorded.
i.e Sent data of "01 02 03 04 05 06 07 FF" works fine and populates the serial1Data array properly.
The ISSUE is when I want to set it longer i.e. serial1DataPkg @ 10
when I sent "01 02 03 04 05 06 07 08 09 FF" i get the following in the serial1Data "01 02 03 04 05 06 07 08 00 FF"
So I tried serial1DataPkg @ 16
when I sent "01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F FF" i get the following in the serial1Data "01 02 03 04 05 06 07 08 00 10 11 12 13 14 15 FF"
So for some reason something is Zeroing out the 8th Byte when sending over 8 Bytes and I can't for the live of me figure out why.. Technically I can write code around that oddity but Im really wondering what might be causing it.
Any ideas?