As a youngster I used to race radio controlled cars (10th scale electric indoor), many years later I got involved in Steampunk, and soon after found out about Teapot racing.
While many of the cheap kits are OK, they have been cost engineered to a point where things become a compromise. I've done a few low cost kits based on the SE8 (a cheap Chinese clone of the Nordic nRF24L01+) with a PIC MCU to decode and drive motor controllers.
For better racers and other devices (like the Teasmade and Little-luggage) I've used the FlySky system, this is a pretty decent, low-cost (around £50 for the Tx and about £10 per receiver). The iBus output from some of the receivers is easy to interface to MCUs (including Arduino and Raspberry-Pi), so is easy to interface to motor controllers and servos - See later for information about iBus frames.
The original version is uni-directional, the Tx sends the packets, and hopefully the Rx gets them. The newer version AFHDS-2A is bi-directional, the Tx sends packets, the Rx processes them, and occasionally returns status and information (battery voltages, propeller speeds, temperatures, etc.). Some FlySky transmitters only support AFHDS, some both AFHDS-2A, some support both. There is also a newer AFHDS-3 which is again completely different.
Mode | A7105 options | Payload Bytes | Payload start | channel data |
---|---|---|---|---|
AFHDS | 1F=0x0F-> CRC enabled, 4 byte ID, 4 byte preamble 20=0x1C-> Preamble detection=0 bits | 21 | 5 Bytes Type + 4xID | 16 Bytes 8 channels |
AFHDS-2A | 1F=0x1E-> FEC enabled, CRC enabled, 4 byte ID, 2 byte preamble 20=0x1E-> Preamble detection=8 bits | 37 | 9 Bytes Type + 4xTx-ID + 4xRx-ID | 28 Bytes 14 channels |
AFHDS-3 | ?? | 15+ | 9 Bytes Type + 4xTx-ID + 4xRx-ID | 6+ Bytes 3+ channels |
Both AFHDS-1 and AFHDS-2A use 160 channels of 500kHz, and an over air rate of 500kbps, a 16-bit payload CRC, and the same 32-bit packet ID (0x54 0x75 0xC5 0x2A) (this is used for all Tx and Rx packets as a packet ID, and is always the same, the Tx-ID and for AFHDS-2A the Rx-ID, are after the type byte in the payload data)
AFHDS-2A uses a shorter preamble (2-byte instead of 4) and has FEC for the payload and CRC, so sends those nibbles as 7-bits (for 4-data), this should give much better packet protection (and range), but will mean that the longer packets and FEC add to the over-air time
Preamble | Packet ID | Payload | CRC | Total | Over air time | Packet send rate |
---|---|---|---|---|---|---|
32-bits | 32-bits | 20x8=160-bits | 16-bits | 240-bits | 480µSec | every 1544µSec |
16-bits | 32-bits | 37x2x7=518-bits | 4x7=28-bits | 594-bits | 1188µSec | every 3850µSec |
There has been some analysis of the packets for AFHDS and AFHDS-2A (not all of it correct!). Most of this has been for the Tx side of things (see Deviation forum), while there has been some Rx work (mainly Thierry Pébayle's PIC code and Thierry Pébayle's ARM code) but this is limited to AFHDS, not AFHDS-2A.
The A7105 (or the slightly upgraded A7106) is used in the FlySky devices, for both AFHDS and AFHDS-2A.
It's easy to get A7105 modules, (the XL7105 includes a Tx amp). They use a well documented 3-wire SPI interface (with MISO and MOSI muxed onto a single I/O pin). So starting with some AFHDS code, a cheap A7105 module, and a PIC, I fixed a few bugs and was decoding packets.
But the existing AFHDS-2A bind sequence documentation, is missing a number of steps, so while a FlySky Receiver can bind with the Open-source Tx, a real FlySky Tx won't bind with something that only impliments whose features! So creating a FlySky compatible AFHDS-2A receiver is going to need more information!
Luckily the FlySky FS-i6 Tx PCB has the important A7105 signals taken out to test pads, so it's easy to connect wires to them (at least the SEN/SCLK/SIO/GPIO1/GPIO2 ones). With this it's simple to capture an actual Bind sequence. With the signals all connected, I captured the SPI sequence for a FlySky FS-i6 booting up in Bind mode, after a short while, I power up a FlySky FS-iA10B Rx in bind mode, so this capture includes the initial register settings, the bind search, and then the bind sequence when the Receiver is found.
An important thing to notice, is that the Tx uses overlapped send/receive operations to increase the processing time between sends. Waiting for the over air send and receive would take well over half of the frame time, so wouldn't leave much time for other things. Instead, the following sequence is repeated at 3.85ms intervals:
From this we can see that any data received during the listen in step #1, isn't read from the A7105's FIFO until step #7, and the data sent in step #5/#6 is calculated in step #2. So the data sent is based on the previously receive frame. This explains the weird "1 packet delay" during the bind sequence, where we see that although the Tx has received the Rx-ID, it doesn't include it until one packet later.
During each phase, the Tx switches between the sending channels with a 3.85ms period, after sending, it listens one channel down for the remainder of the period for a response.
The Rx switches between the channels at half the rate (so 2x3.85ms=7.7ms), until it syncronises with the Tx, then keeps stepping at 3.85ms even if a packet is missed, so that stays in sync with the Tx even if there is interference or other causes of missed packets
The bind sequence happens in two phases:
During phase #1, the channel sequence just toggles between the two bind channels (0x0D and 0x8C), with the Tx listening on 0x0C and 0x8B for a response.
The 16 data channels sent in the intial packets of phase #1 of the bind are used (listening for responses one channel down).
Every 3.85ms, the Tx sends a 37 byte 0x58 packet, and then listens for a response.
ID | Tx-ID | Rx-ID | Payload |
---|---|---|---|
0x58 | 32-bit Tx-ID | 32-bit Rx-ID | 14 blocks of 16-bits stick position (in µSec, Least significant byte first) |
ID | Tx-ID | Rx-ID | Payload |
---|---|---|---|
0xAA | 32-bit Tx-ID | 32-bit Rx-ID | Upto 7 sensor data blocks, of {sensor-Type}{Sensor-Num}{16-bit sensor val, Least significant byte first} |
Most receivers have seperate servo PWM outputs per channel (with a +ve pulse of 1000...2000 µSec repeated at about 20ms). This has been the industry standard for at least 50 years. While this was fine for a few channels, with 6+ channels you end up with a lot of wiring, so there have abeen a few alternative schemes.
This is essentially the inverted version of the old AM over-air signal, 400µSec lows, with the low+following high period being the PWM servo signal. Usually blocks of 8 servo positions (so 9 low pulses) repeated at 20ms intervals.
Here is an example PPM packet:
This is just the over air AFHDS-2A data with a header and checksum. It's sent as TTL level 115000 Baud serial, 1 start,8 data,2 stop, as 32-byte packets every 7.7ms (so every other received AFHDS-2A frame).
It starts with a length byte (0x20), then a type byte (0x40), then 14 channels of stick position as 16-bit µSec values, Least significant byte first, then 2 bytes of checksum.
The checksum is only for the data payload, and is inverted (so 16-bit payload sum + 16-bit CSUM value=0xFFFF).
Here is an example iBus packet: