Basically, I have this code on a Bluno M3 Arduino:
#define MSG_LEN 2
unsigned char pixel;
char buff[MSG_LEN];
int i;
void setup() {
Serial4.begin(9600);
pixel=0xDD;
}
void loop() {
if(Serial4.peek() == -1){
while(Serial4.available() < MSG_LEN);
Serial4.readBytes(buff, 2);
if(buff[0] == 0xC8 && buff[1] == 0x00){
//send image
Serial4.write(0xC7); //send Image ACK
Serial4.flush();
for(i=0;i<4800;i++){
Serial4.write(pixel);
Serial4.flush();
}
for(i=0;i<MSG_LEN;i++){
buff[i]=0xFF;
}
}
}else{
while(Serial4.available()>0){
Serial4.read();
}
}
}
I'm using a PL2303 USB-Serial Adapter, Bluno M3 arduino, CoolTerm serial monitor.
And if you check this image:
You can see that in the data this code sends, the 0xC7 byte is mixed in with the 0xDD bytes (so called pixel bytes)
Why does that happen?
Do another test: instead of sending the same value increment it with every time. It will give more diagnostic data