Hi all, I'm looking for a little guidance on the attached.
I'm using a Mega2560, RX1/TX1 and attempting to read a serial data stream from an RC receiver that has a special serial output port for a variety of purposes. This is NOT a PPM stream that has been a common RC data stream capture technique. Attached is the spec (pdf document) from the manufacturer that details the header structure, format of data, baud rates and how to calculate servo pulse widths etc, etc. Also attached is a small code loop for the 2560 and a sample of the output I am getting. I'm running the serial port at 125K Baud, 250K must be for the 24 channel data stream which I have not yet enabled in the RC Transmitter nor tested.
The issue is that the output is not consistent with how I have interpreted the specification. I'm looking ONLY for the packet that has 0x3E 03 header which should contain ONLY the servo signal pulse width for the 16 servo channels contained in the data stream.
Here's my code:
const byte len = 40;
byte inBuffer1_16[len] {0};
void setup() {
Serial.begin(9600);
Serial1.begin(125000);
delay (200);
}
void loop() {
byte inByte1;
if (Serial1.available() > 0){
inByte1 = Serial1.read();
inBuffer1_16[0] = inByte1;
if (inByte1 == 0x3E){
byte inByte2 = Serial1.read();
if (inByte2 == 0x03){
inBuffer1_16[1] = inByte2;
serialPort1();
}
}
}
}
void serialPort1(){
for (byte i = 2; i < len; i++){
inBuffer1_16[i] = Serial1.read();
}
printEXPacket();
return;
}
void printEXPacket(){
for (byte i = 0; i < len; i++){
Serial.println(inBuffer1_16[i], HEX);
}
return;
}
and here's an example of the output I get which I have annotated.
3E // the 0x3E header
3 // followed by the 0x03
28 // the length of the packet (40 bytes)
4D // the packet ID
31 // The data type - channel data
20 // # of bytes of channel data - 32 bytes, 16 words
68
1F
40
1F
40
1F
40
1F
1E
30
D9
2E
B9
2E
E8
20
E0
2E
E0
2E
4D
31
20
68
FF // this appears to be bad data
FF // this appears to be bad data
FF // this appears to be bad data
FF // this appears to be bad data
FF // this appears to be bad data
FF // this appears to be bad data
FF // this appears to be bad data
FF // this appears to be bad data
1F // this appears to be bad data
FF // this appears to be bad data
3E
3
28
4D
31
20
68
1F
40
1F
40
1F
40
1F
1E
30
D9
2E
BB
2E
E8
20
E0
2E
E0
2E
E0
2E
E0
2E
E0
FF
FF
FF
FF
FF
FF
FF
FF
FF
3E // this appears to be a reasonable packet have not check the last two CRC-CCITT bytes to verify
3
28
4D
31
20
68
1F
40
1F
40
1F
40
1F
1D
30
D9
2E
BB
2E
E8
20
E0
2E
E0
2E
E0
2E
E0
2E
E0
2E
E0
2E
E0
2E
E0
2E
A1
27
Of particular note is the packet ID, the forth byte in the stream. It is the same value which surprises me since I'm assuming that every packet should be different.
I'm wondering it I have a timing issue with the speed at which data is being transmitted from the receiver and the speed at which I am trying to push it to the serial monitor or whether I simply have mode code all screwed up - BTW, I've never done serial communications before this so have no idea if my approach is even correct. I assume the serial "register" is cleared and loaded with the next byte in the serial buffer after each read().
Any guidance would be greatly appreciated.
EX_Bus_protokol_v121_EN.pdf (633 KB)