CRSF protocol for TBS Crossfire?

ersky9xr is the port of the er9x firmware to the 9XRPRO radio.
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: CRSF protocol for TBS Crossfire?

Post by MikeB »

LoafFPV: ersky9x does already include support for the crossfire protocol, so should, at least, operate controls.

I've just posted a test version of ersky9x for the 9XR-PRO that includes code to send and receive crossfire telemetry data from/to a script.
Sending:
result = crossfiresend( command, count, byte_array )
result is 1 if sent and 0 if not sent (usually because a previous send hasn't gone yet).
count is the number of bytes in byte array to send
Declare a byte array by a statement at the beginning of the script like:
array byte ba[20]
Use this array in the function as:
result = crossfiresend( command, count, ba[0] )
the "address" of ba[0] is used implicitly. I may look into updating the script processing so that "ba" without the subscript also works.
I have tested the sending and I can see a correct telemetry packet using my 'scope.

Receiving:
result = crossfirereceive( ( command, count, byte_array )
result is 1 if a packet is received and 0 if not. If the byte_array is not large enough to store the packet data, the result is 0.
The array is handled as with the send function.

I cannot test this receive function works.

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

LoafFPV
Posts: 16
Joined: Fri Apr 06, 2018 4:51 am
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by LoafFPV »

From what I read I understand the crossfire micro TX will bind to the crossfire RX in ppm-mode and you need a lua-script, or equivilent, to change mode to ”CRSF”? That is what I was refferring to.
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

I'm using 9xtreme :(
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: CRSF protocol for TBS Crossfire?

Post by MikeB »

Oops, I forgot. I've just posted the same for the 9Xtreme, but haven't tested it at all!

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

Thanks mike, would you recommend some way of storing and drawing a string received from `crossfireReceive` function? So far I can only think of having a predefined set of `array byte crossfireDeviceNameN[32]`, for `N = 0..16` to store received names. But how do I convert them back to `string` for drawing via `drawtext()`? Can `drawtext` accept a byte array directly?

User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: CRSF protocol for TBS Crossfire?

Post by MikeB »

Yes, drawtext should accept a byte array as well as a string. Make sure the byte array ends with a 0 (zero) byte as a string terminator.
As with other byte array references you need to include the starting subscript, even if it is 0.

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

Got it, thanks. What's up with int arrays? I get a syntax error for this line:
`array int deviceTimeouts[16]`
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: CRSF protocol for TBS Crossfire?

Post by MikeB »

Should work, I'll check. "int" is the default for an array, so:
array deviceTimeouts[16]
should work.

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

Here's the script I'm currently using and I get a blinking "send succeeded" line, while all other lines say "result is zero", "count is zero", "command is zero".
It looks like the response of my CROSSFIRE Micro TX module never gets back. Is there a possibility ErSky9x hijacks it?
https://github.com/DieHertz/ersky9x-cro ... SSFIRE.bas
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: CRSF protocol for TBS Crossfire?

Post by MikeB »

You need the subscript in this line to indicate where in the byte array to store the data:
result = crossfirereceive(command, count, receiveBuffer[0])

I need to see if I can make the reference without the subscript work, currently you must include it, even if it is [0].

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

Thank you, I'll try it. From your earlier message I've misunderstood it as If it's only necessary for send.
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: CRSF protocol for TBS Crossfire?

Post by MikeB »

It looks like I've got code now working to recognise an array without a subscript to refer to the array with a subscript of 0, so the next test version of ersky9x will have that in.

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

Am I right to assume there are no scopes and hence no local variables? Passing parameters to a subroutine should be done via globals?
Is there a possibility to as built-in construct to pass control to another script? E.g. in CROSSFIRE.bas I want to `return "CRSF_DEVICE.bas"` to pass execution along with current symbol table to another script.
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: CRSF protocol for TBS Crossfire?

Post by MikeB »

Yes, currently there are no local variables available. It is something for me to consider, but, to allow for recursion, it will need a data stack, then it needs a decision on how large to make such a stack. Since several scripts may run at the same time, each would needs its own stack.

I might be able to get a script to "chain" to another, but passing the existing variables would be quite difficult. The existing "symbol table" is overwritten by the script data when it runs.

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

Unfortunately I still get no messages from the Radio TX nor from the bound Receiver in telemetry script.
Could you share the C-implementation of these two new functions to review? There is some fuss about extended headers for CRSF, maybe the cause is in how you're formatting header. Are you using "broadcast" CRSF device address?
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: CRSF protocol for TBS Crossfire?

Post by MikeB »

I've just posted an update, I reckon I had the crc calculated for the send missing the command byte.
I've also just committed the current source files to Github.

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

Thanks Mike, I'll scope into the communication line tomorrow to see what happens. Still getting no responses for my `poll` command to CROSSFIRE TX :-(
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: CRSF protocol for TBS Crossfire?

Post by MikeB »

I'm using the same "MODULE_ADDRESS" (0xEE), for both control and telemetry packets.
The code that builds the packet to send is in "pulses.cpp", function "setupPulsesXfire()".

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

Not sure what's wrong, but scoping into the SmartPort line with a Saleae logic analyser all I get is this.
Screen Shot 2018-04-08 at 11.22.53.png
No signs of Tx Module ID (0xEE), Radio Tx ID (0xEA) nor Poll Devices command (0x28) over a span of 5 seconds in decoded serial output.
I had to disconnect the module because scoping into the serial line somehow breaks integrity, it manifested itself as Receiver going into failsafe, but even with no module connected there are no signs of telemetry requests being sent.

All I get on the screen is `Waiting for devices`.

Latest version of code used is in my GitHub repo:
https://github.com/DieHertz/ersky9x-cro ... SSFIRE.bas
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

Seems like my quest is finished for now. Any idea what happened here? Too high current draw?
IMG_20180408_135108_HDR.jpg
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: CRSF protocol for TBS Crossfire?

Post by jhsa »

Did you short something? Inserted / removed the module while the radio was ON?

João


My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: CRSF protocol for TBS Crossfire?

Post by MikeB »

I'm fairly certain that is Q2, a "MOSFET P-Ch AO3407A SOT23", and is the external module power switch.
Any chance you shorted the power and ground pins of the module connector together (counting from the top they are pins 3 and 4)?

I've just put a 'scope on the SPort signal on my 9Xtreme, with the current test version of the firmware, an I see a correct frame beginning with a 0xEE (inverted serial data at 400Kbaud), with the whole frame taking about 650uS to send.

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

I had no module connected at all, only probes at bottom pin (telemetry) and middle pin (ground).
Will try to find a replacement unless it burnt something badly

Is AO3401 a suitable replacement?
Looks like drain pas got burnt, will have to jumper it.

Lol, middle is power, not ground, that's the cause of it :(
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: CRSF protocol for TBS Crossfire?

Post by jhsa »

If you are in Germany or close, please PM me. I have some of those FETs. :)

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

Thank you for your kind offer, unfortunately I'm not that close, Russia. For now AO3401 seems to work, I'll put 3407A on order.
Really stupid of me confusing middle pin for ground :(
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: CRSF protocol for TBS Crossfire?

Post by jhsa »

It can happen.. :) Sometimes we are paying a lot of attention to other issues and forget the basic. it happens to the best.. :mrgreen:

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

I see the correct packages now, sorry Mike :) Will try to investigate why responses aren't arriving.
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

Here's the response to poll devices, it seemingly gets dropped because it doesn't fit into 16 byte limit.
Overall great job Mike, implementing a protocol without hardware at hand is a great feat.
Screen Shot 2018-04-08 at 16.37.22.png
This one is 32-byte but may be as long as 64.

This line in `crossfirereceive` implementation always returns `-1`:
value = peek_fifo128( &Lua_fifo ) ;
#endif
if ( value != -1 )
What could be the cause?
Last edited by Hertz on Sun Apr 08, 2018 3:18 pm, edited 1 time in total.
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: CRSF protocol for TBS Crossfire?

Post by MikeB »

I've just posted a new test version ('Pro and 9Xtreme). This allows a send of up to 64 bytes for crossfire. Receive should still work with 64 bytes. The 9Xtreme version has some debug (on the DEBUG menu, UP LONG, then LEFT or RIGHT several times).
The top line of values are "Amount of space in script fifo", and 3 values from withing the script receive processing.
The next two lines have the first 8 bytes in the script fifo.

Mike
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: CRSF protocol for TBS Crossfire?

Post by Hertz »

FIFO space is always `0x7f` on mine, while TelRxCount runs up quickly. All other lines are 0, just what I observe from inside the script.
The issue was with `#ifdef REVX`
I now receive the device info messages, but have another weird issue. My receive buffer is 64-bytes, and when third message arrives I get an error:
111 at line 30. This is the exact line of `crossfirereceive` function call.

Post Reply

Return to “ersky9xr”