Help needed reading telemetry data stream

reywas

Member
I'm trying to figure out how to read the telemetry stream coming from an RC receiver (FrSky D8R-II) and I could use some help. I'm pretty new to PICAXE and this is the first time I've tried to use the serin.

The code below doesn't work with both qualifiers in place (it just stops at the serin) and I can't figure out why. If I remove the $7E qualifier, I get the first block of data shown below. The second block of data is the raw data coming from the transmitter into COM1. The frame format, as shown on the attached PDF file section 3.1.3, is a total of 11 bytes including a HDR ($7E), Frame ID($FE), Port1, Port2, Link Quality, 5 data bytes, end byte. The second block of data shows the correct frame format with 11 bytes. Looking at the first block of data below, if you count from 7E to 7E and add in the $FE qualifier, there are only 10 bytes. There should be 11. I'm only interested in the data bytes but I'd like to understand whats going on here.

1) Why doesn't the serin see the $7E qualifier?

2) Why am I losing a byte?

3) Since the qualifier $FE comes after $7E in the data stream, why are there two 7E's in the first block of data?

View attachment TwoWayProtocol.pdf



Code:
[color=Green];PIC2 Tx end[/color]
[color=Blue]setfreq m8[/color]
[color=Black]main:[/color]

[color=Blue]serin c.0[/color][color=Black],[/color][color=Blue]T9600_8[/color][color=Black],[/color][color=Blue]([/color][color=Navy]$7E[/color][color=Black],[/color][color=Navy]$FE[/color][color=Blue])[/color][color=Black],[/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7[/color][color=Black],[/color][color=Purple]b8[/color][color=Black],[/color][color=Purple]b9[/color]

[color=Blue]sertxd([/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7[/color][color=Black],[/color][color=Purple]b8[/color][color=Black],[/color][color=Purple]b9[/color][color=Blue])
high c.4
pause [/color][color=Navy]200[/color]
[color=Blue]low c.4
pause [/color][color=Navy]200[/color]
[color=Blue]goto [/color][color=Black]main[/color]

Data from above code without the $7E quilifier:

2E 31 A3 06 00 00 00 7E 7E 2E 31 2D 32 00 00 00
7E 7E AE 4C 4B 06 00 00 00 7E 7E AE 6C 4B 06 00
00 00 7E 7E AE 4C 4B 06 00 00 00 7E 7E AE 4C 6B
06 00 00 00 7E 7E 2E 6C 6B 06 00 00 00 7E 7E 2E
6C 8B 06 00 00 00 7E 7E 5C 4C 8B 06 00 00 00 7E
7E 5C 4C 6B 06 00 00 00 7E 7E 5C 6C 6B 06 00 00
00 7E 7E 2E 4C 6B 06 00 00 00 7E 7E 5C 4C 4B 06
00 00 00 7E 7E AE 6C 4B 06 00 00 00 7E 7E 2E 4C
8B 06 00 00 00 7E 7E 5C 6C 8B 06 00 00 00 7E 7E
5C 6C 8B 06 00 00 00 7E 7E 2E 6C 8B 06 00 00 00
7E 7E 2E 6C 8B 06 00 00 00 7E 7E 2E 4C AB 06 00
00 00 7E 7E AE 6C 8B 06 00 00 00 7E 7E AE 6C AB
06 00 00 00 7E 7E AE 6C AB 06 00 00 00 7E 7E AE
6C 8B 06 00 00 00 7E 7E AE 6C 6B 06 00 00 00 7E
7E AE 6C 8B 06 00 00 00 7E 7E AE 6C 8B 06 00 00
00 7E 7E AE AC 88 06 00 00 00 7E 7E AE 6C 4B 06
00 00 00 7E 7E AE 4C 6B 06 00 00 00 7E 7E

Raw data from transmitter to COM1:

7E FE 57 6E 1D 1D 00 00 00 00 7E 7E FE 57 6E 48
3A 00 00 00 00 7E 7E FE 57 6E 73 57 00 00 00 00
7E 7E FE 57 6E 67 73 00 00 00 00 7E 7E FE 57 6E
5C 90 00 00 00 00 7E 7E FE 57 6E 56 AD 00 00 00
00 7E 7E FE 57 6E 56 CA 00 00 00 00 7E 7E FE 57
6E 56 E7 00 00 00 00 7E 7E FE 57 6E 56 DE 00 00
00 00 7E 7E FE 57 6E 56 D5 00 00 00 00 7E 7E FE
57 6E 57 CC 00 00 00 00 7E 7E FE 57 6E 56 C4 00
00 00 00 7E 7E FE 57 6E 57 BB 00 00 00 00 7E 7E
FE 57 6E 57 B2 00 00 00 00 7E 7E FE 57 6E 56 A9
00 00 00 00 7E 7E FE 57 6E 56 A0 00 00 00 00 7E
7E FE 57 6E 57 A0 00 00 00 00 7E 7E FE 57 6E 57
A1 00 00 00 00 7E 7E FE 57 6E 57 A1 00 00 00 00
7E 7E FE 57 6E 57 A1 00 00 00 00 7E 7E FE 57 6E
57 A1 00 00 00 00 7E 7E FE 57 6E 57 A1 00 00 00
00 7E 7E FE 57 6E 57 A1 00 00 00 00 7E 7E FE 57
6E 58 A2 00 00 00 00 7E 7E FE 57 6E 57 A1 00 00
00 00 7E 7E FE 57 6E 58 A1 00 00 00 00 7E 7E FE
57 6E 57 A1 00 00 00 00 7E 7E FE 57 6E 57 A2 00
00 00 00 7E 7E FE 57 6E 56 A1 00 00 00 00 7E 7E
FE 57 6E 57 A1 00 00 00 00 7E 7E FE 57 6E 58 A1
00 00 00 00 7E 7E FE 57 6E 57 A1 00 00 00 00 7E
7E FE 57 6E 57 A1 00 00 00 00 7E 7E FE 57 6E 57
A2 00 00 00 00 7E 7E FE 57 6E 57 A2 00 00 00 00
7E 7E FE 57 6E 57 A1 00 00 00 00 7E 7E FE 57 6E
58 A2 00 00 00 00 7E
 

neiltechspec

Senior Member
Try

setfreq m16

serin c.0,t9600_16

That's what I use for 9600 baud, been capturing 24 bytes from a 33 byte string for a few years without errors.

Neil
 

rossko57

Senior Member
Tackling the "why"; it takes the Picaxe a finite time to process the qualifier. If that takes too long, the data stream will be into subsequent character before the qualifier is accepted, and everything gets out of sync.
Running the Picaxe at a faster processing rate speeds up qualifier processing.
 

reywas

Member
Thanks for the help guys. That seems to have done the trick.

Now, I would like to add a line feed to the sertxd so that my columns line up on the terminal emulator screen but it isn't seeing the (10,13) as command characters. They are just being added to the sertxd output. Is there a way to get the terminal to recognize the command characters and output the rest of the data in hex? Here's the code:

Code:
[color=Green];PIC2 Tx end[/color]

[color=Blue]setfreq m16[/color]
[color=Black]main:[/color]

[color=Blue]serin c.0[/color][color=Black],[/color][color=Blue]T9600_16[/color][color=Black],[/color][color=Blue]([/color][color=Navy]$7E[/color][color=Black],[/color][color=Navy]$FE[/color][color=Blue])[/color][color=Black],[/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7[/color][color=Black],[/color][color=Purple]b8[/color][color=Black],[/color][color=Purple]b9[/color]

[color=Blue]sertxd([/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7[/color][color=Black],[/color][color=Purple]b8[/color][color=Black],[/color][color=Purple]b9[/color][color=Black],[/color][color=Navy]10[/color][color=Black],[/color][color=Navy]13[/color][color=Blue])
high c.4
pause [/color][color=Navy]500[/color]
[color=Blue]low c.4
pause [/color][color=Navy]500[/color]
[color=Blue]goto [/color][color=Black]main[/color]
 

neiltechspec

Senior Member
Try

sertxd(b1,b2,b3,b4,b5,b6,b7,b8,b9,13,10)

or

sertxd(b1,b2,b3,b4,b5,b6,b7,b8,b9,cr,lf)

assuming your variables b1 to b9 are printable characters.

don't think 10,13 works.


Neil
 

hippy

Ex-Staff (retired)
I suspect the problem is that "Show Hex" is being used for the Terminal to show the data in hex, but that also causes the CR and LF to be shown as hex also.

You can write your own code to show the data in hex ...

Code:
serin c.0,T9600_16,($7E,$FE),b1,b2,b3,b4,b5,b6,b7,b8,b9
For bptr = 1 To 9
  b0 = @bptr / $10 + "0" : If b0 > "9" Then : b0 = b0 + 7 : End If
  SerTxd( b0 )
  b0 = @bptr & $0F + "0" : If b0 > "9" Then : b0 = b0 + 7 : End If
  SerTxd( b0, " " )
Next
SerTxd( CR, LF )
 

reywas

Member
Thanks hippy, it's working! I had to add a 50mS pause after each sertxd to get it to work. Where can I find an explanation of bptr and @bptr? Can you please give an explanation of the line ' b0 = @bptr / $10 + "0"'?
 

hippy

Ex-Staff (retired)
PICAXE Manual 2 explains the 'bptr' and '@bptr' variables ( plus 'ptr' and '@ptr' ). Basically they allow access to RAM and variables ( or scratchpad for 'ptr' ).

The b0 = @bptr / $10 + "0" gets the 4 msb's of a variable ( 0 to 9, 10 to 15 ), converts them to an ASCII digit, and the following If b0 > "9" adjusts the ASCII character value for "A" to "F".

b0 = @bptr & $0F + "0" does similar for the 4 lsb's.
 
Top