cleanflight icon indicating copy to clipboard operation
cleanflight copied to clipboard

Add telemetry output/voltage monitoring support for Radiolink receivers through I2C.

Open KP1533TM2 opened this issue 10 years ago • 31 comments

Some Radiolink receivers, such as R9D and R10D, have an additional I2C port to plug in an addon module (PRM-01 or PRM-02).

  • PRM-01 (http://www.radiolink.com.cn/doce/product-detail-111.html) only does battery voltage measurement;
  • PRM-02 (http://www.radiolink.com.cn/doce/product-detail-110.html) requests telemetry data from the flight controller using PIX or APM protocol.

Receiver then sends that data back to the transmitter to display all that stuff on its screen. There's no official documentation on I2C protocol those modules use, but few people managed to analyze PRM-01's communication and make a clone with Arduino (http://forum.rcdesign.ru/f4/thread416311-11.html). Not much is known right now about PRM-02 module's data structures or communication protocol.

Technical details for battery voltage monitoring (from the same rcdesign.ru thread, post 406: http://forum.rcdesign.ru/f4/thread416311-11.html#post6127465):

  • Receiver periodically reads from I2C addresses 0x01 to 0x05 (only when transmitter is on);
  • PRM-01 module responds with 3 bytes on address 0x01 as follows: 1st byte is the cell count, 2nd byte is battery voltage high byte and 3rd byte is battery voltage low byte. For example, response [0x03, 0x00, 0x73 (dec. 115)] means 3 cell battery measuring 11.5v.

It would be nice to have a feature to pass data (battery voltage, atleast) from flight controller to the receiver directly over I2C without having to use an addtitonal redundant module in the middle.

KP1533TM2 avatar Jan 17 '16 07:01 KP1533TM2

+1 on this RadioLink offers a chea and mighty alternative to FrSky's Taranis and it would be an overkill to also have tlemetry available for those! I would be happy to test for you if you wanted me to do. Other idea which would be enough for me would be to just support talking to PRM-02 (PIX or APM-Protocol)

fsedarkalex avatar Mar 24 '16 14:03 fsedarkalex

@fsedarkalex talking to PRM-02 will be possible if #806 gets merged.

digitalentity avatar Mar 24 '16 14:03 digitalentity

I have managed to decode the messages between the PRM-02 module and the receiver. If this was implemented into cleanflight we would not need the module to decode Mavlink. We could plug the receiver's telemetry port directly into the FC I2C plug. Would this be of any interest to anyone? I am just doing some final tests then I will release the data required.

southbot avatar Mar 26 '16 08:03 southbot

@davidgrm I am still interested in such implementation, however I'm not familiar enough with STM32's hardware and cleanflight source code enough yet to implement this myself.

KP1533TM2 avatar Mar 26 '16 08:03 KP1533TM2

I know nothing about the workings of cleanflight but hopefully someone here does?? If I get a chance I will have a look and see if I can figure out where/ how one would add it. It would also depend on what else is using the I2C and if there is some way of turning it off. I am posting the stuff here: http://www.rcgroups.com/forums/showthread.php?t=2236519&page=14#post34359050

southbot avatar Mar 26 '16 08:03 southbot

unfortunately I don't know about CF-Internals eighther but I would also like to express my interest once again.

fsedarkalex avatar Mar 26 '16 10:03 fsedarkalex

For my FC (SP Racing F3 Deluxe) the manual says:

I2C1 connector - Used for external sensors and OLED displays. The SCL and SDA are 3.3v signals.5.0v is always supplied via the on-board voltage regulators, even when powering via USB. WARNING: logic level converters are REQUIRED if your sensors require 5.0v signals.

So I think technically it should be possible to use it

fsedarkalex avatar Mar 26 '16 10:03 fsedarkalex

I did my testing with an AVR Xmega running on 3.3v and the receiver uses 5v. I connected the I2c pullup resistors to 3.3. This worked without problems.

southbot avatar Mar 26 '16 10:03 southbot

Just a little update. Today I decided to see if I can implement battery monitoring the way I wanted (meaning connecting I2C bus of my Naze32 (V2.3_OEM) to R9D receiver I2C port). That failed (atleast at the moment). Made an appropriate cable, hooked up a logic analyzer to debug stuff. Embarassingly enough, it took me an entire evening to figure out that all sensors are sharing this exact bus. R9D receiver acts as a bus master, and thus, can't be easily set up on the same I2C bus along with other master. In this case, an extra 'special' code that handles bus multimaster mode is required (that is, CPU would take over the bus to read sensors and stuff and then release it and act as a slave to respond when R9D asks for battery/telemetry info; that's how I see it working in my mind, but I'm not sure R9D would even check for bus activity before colliding with other data, since it seems it never was desingned to be used in multimaster mode). So I looked into the possibility of using another I2C interface. That doesn't look very good either. According to STM32F103 datasheet, both I2C1 alternate and default pins are mapped to ports that are used to drive ESCs (again, on my Naze32 atleast) :( The only obvious choice at this point seems (imho) to implement software interrupt-driven slave I2C, given that I'll find a free 'pin change' interrupt and enough corresponding free pins to physically plug the receiver's I2C into my Naze32.

KP1533TM2 avatar May 09 '16 19:05 KP1533TM2

I'd be very interested in this too. I see that the X4RII receiver plugs in straight into the board and provides telemetry instantly, I wonder if this would ever be possible though. I'm not familiar with Cleanflight code or with RadioLink protocols, just stating my interest :)

rigo3t avatar Jun 01 '16 04:06 rigo3t

@davidgrm Did you ever end up finishing the code? Im working on the same problem and wanted to see how you might have done it.

FLYBYME avatar Jul 17 '16 17:07 FLYBYME

I ended up using Radiolink PRM-02 module with MAVLink telemetry for now. It seeems to me, that the solution, for Naze32 atleast, would be quite non-trivial - it's either wasting 2 ESC ouputs to enable second I2C bus, or implementing I2C in software, or doing some weird multi-master stuff with sensor bus.

KP1533TM2 avatar Jul 19 '16 04:07 KP1533TM2

@FLYBYME I was not writing any code for it. All I did was figure out the mavlink commans that are being used so that is any of the coders here wanted to add the code they could

southbot avatar Jul 19 '16 08:07 southbot

@KP1533TM2 I more choose to make PRM-02 like module and talk using UART than directly using I2C. I was try to make adaper code to translating MSP to PRM-02 format and flashed to Arduino Pro Mini, It's work fine. And I think I will use i2c-gps-nav module with custom firmware to translating MSP data to PRM-02 data.

tjstyle avatar Jul 19 '16 16:07 tjstyle

@tjstyle do you happen to have any code you care to share? I'm trying to do the same thing you are but I'm having trouble understanding the high and low bi bits. I don't understand the maths that must be taken from high and low bits to get a number the telemetry understands.

FLYBYME avatar Jul 19 '16 17:07 FLYBYME

@FLYBYME Still missing some value for the telemetry, I think I will share some code when all value was correct. VOLT, YAW,ROLL,PITC and ALT it was same like on CF Config. on still don't know what value that I must send for SPEED, RISE and DIST. GPS is also correct including LATI and LONG, but for LATI the original value is with minus sign, I don't know why in the AT9 the minus sign is not shown. prm-hym

tjstyle avatar Jul 20 '16 01:07 tjstyle

@tjstyle If you would mind just sharing the maths for the high and low bit for voltage that equals the 15.6v that you have showing in you images. I dont understand how hi=44 lo=236 voltage=11.5v.

FLYBYME avatar Jul 21 '16 01:07 FLYBYME

@FLYBYME from where you've got hi=44 lo=236 voltage=11.5v ?

tjstyle avatar Jul 21 '16 02:07 tjstyle

@tjstyle from this post; http://www.rcgroups.com/forums/showthread.php?t=2236519&page=14#post34359150

FLYBYME avatar Jul 21 '16 02:07 FLYBYME

I don't see any word about hi=44 lo=236 equal to voltage=11.5v This is some example: In multiwii serial protocol, the vbat value on MSP_ANALOG is UINT8, just convert that to UINT16. When the the voltage is 11.5v the UINT8 value is 115, multiply that by 100 so you will have 11500 (UINT16) or 2CEC (HEX). So you can use that with: hi=0x2C lo=0xEC

tjstyle avatar Jul 21 '16 02:07 tjstyle