User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

[Done] Programming with I2C - RDA5807M

Sun Nov 03, 2013 11:34 am

I'm thinking of buying a small FM radio module from eBay this is an RDA5807M with a large tuning range and RDS decoding capabilities.
According to the data sheet ( http://www.electrodragon.com/w/File:RDA ... eet_v1.pdf ) it uses a 2-wire bus interface which I assume is another name for I2C.

Are there any decent online tutorial for connecting an I2C device and how to talk to it with code like bash script, python or C etc??

Also my Pi is one of the early board designs did some of the pins involving I2C get moved around with the rev 2 boards, would this cause problems when coding??

Richard S.
Last edited by redhawk on Tue Mar 25, 2014 5:02 pm, edited 3 times in total.

User avatar
joan
Posts: 14689
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Programming with I2C??

Sun Nov 03, 2013 11:47 am

The datasheet mentions I2C.

http://www.robot-electronics.co.uk/acat ... orial.html

I suppose you might be able to use bash but I'm not sure if that would be reliable.

Python has the SMBUS module (probably others as well). C can talk direct to the /dev/i2c-0 device.

Probably best to add yourself to the i2c group (sudo adduser pi i2c).

The pins are the same between the Rev.1 and 2 boards. Just the gpio numbers are different (0/1 rather than 2/3),

User avatar
DougieLawson
Posts: 37111
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Programming with I2C??

Sun Nov 03, 2013 11:51 am

Try this: http://quick2wire.com/articles/how-to-a ... re-source/

That gives you a python library to work with SPI and I2C.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Programming with I2C??

Sun Nov 03, 2013 12:32 pm

One of the first people I encountered who explored I2C on RPi was Nathan Chantrell. His explanations still look useful, apart from the fact that some of the kernel mods and such are now a default part of Raspbian.

http://nathan.chantrell.net/20120602/ra ... der-board/
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Programming with I2C??

Sat Nov 09, 2013 9:45 pm

Thanks for for the tips on I2C programming, I've found some nice C libraries to work with from WiringPi at least I can compile something instead of relying on a language interpreter.
Anyway my RDA5807M RDS capable radio board from China still hasn't arrived in the post yet but in the meantime I've acquired a 2 quid TEA5767 board from a eBay UK seller. :)

So far so good it works including the RSSI meter and automatic tuning, however I have to be honest I am a little disappointed with the audio quality the MPX decoder (stereo decoder) is very noisy even when using a nearby FM transmitter.
I'm guessing this maybe due to RF noise from the Pi's I2C interface via short wires which if true kind of defeats the whole point of having an I2C powered FM radio for the Pi.

Could I extend the wires to the I2C interface and what is the recommended length before I experience communication problems??

And another thing I wired my board and Pi as SDA to SDA, SCL to SCL and it failed to detect, I had to swap one of the SDA SCL lines to get it working.

Is this the correct way to wire up I2C i.e. SDA with SCL or did someone made an error with their documentation I was working with??

http://www.doctormonk.com/2012/03/tea57 ... d-for.html

Richard S.

User avatar
joan
Posts: 14689
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Programming with I2C??

Sat Nov 09, 2013 9:55 pm

It should be SDA to SDA and SCL to SCL. You need the grounds as well.

What sort of distance are you thinking of? Several feet should be fine. I reckon it's a question of trying.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Programming with I2C??

Sat Nov 09, 2013 10:03 pm

I was thinking of something like 1 metre of shielded cabling or maybe modify a 1.5m USB extension lead which also carries 4 wires inside.
I'm hoping that by getting the board far away from the PI I could clip on a few ferrite cores and hopefully reduce some of the incoming interference.

Richard S.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Programming with I2C??

Sat Nov 09, 2013 11:34 pm

It is quite common to run I2C over long distances not what originally meant for. I have run it successfully over 10-15m even without a shield. When you get longer distances you may well have to reduce clock speed if already running faster than 100kHz

Often people use twisted pairs SCL and GND as one pair, SDA and power as the other pair.

If in doubt on electrical always consult the standard at NXP

Despite what various parts of Broadcom data sheet NXP has the standard for I2C (and patent/copyright) from when it was part of Philips as Philips Semiconductors; whilst Freescale has the SPI standard from when it was part of Motorola.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Programming with I2C??

Wed Nov 13, 2013 7:30 pm

Well I managed to get some improvement out of the radio unfortunately that meant powering the Pi from batteries and putting it into shutdown mode.
I still haven't tried longer wires yet but I'm hoping some carefully selected rf chokes on every line should help the noise problems.

Just out of curiosity can several I2C devices share the same data lines proving they don't share the same device ID or do I need some kind of hub??

Richard S.

User avatar
joan
Posts: 14689
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Programming with I2C??

Wed Nov 13, 2013 7:46 pm

You can plug multiple devices into an I2C bus. The only requirement is that each device has a unique address.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Programming with I2C??

Wed Nov 13, 2013 7:54 pm

That's the point of unique IDs (I2C addresses) so you can put lots of devices on the same bus.

Read the spec I linked in previous post lots of examples.

BTW in I2C you dont have hubs, you have bus switches that DISCONNECT branch networks and only connect one at a time. That is for when you have LOTS of devioce that must have the same device ID
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Programming with I2C??

Fri Dec 06, 2013 10:52 pm

I finally got my RDA5807M in the post today and I can say it was worth the wait. :)

This chip beats the crap out of the Philips TEA5767 for audio quality, better noise immunity for MPX decoding, and can drive a pair of headphones better than the Pi.
Rather surprisingly it's nearly fully backwards compatible with the TEA5767 so i2c code can be shared with the exception of a few commands like mute left, mute right.
Still need to figure out how the RDS stuff works but I'll report back when I have some success.

Just out of curiosity what would happen when 2 i2c devices share the same address and connected together, do they both receive the same commands or fight it out??

Richard S.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Programming with I2C??

Sat Dec 07, 2013 10:32 am

redhawk wrote:Just out of curiosity what would happen when 2 i2c devices share the same address and connected together, do they both receive the same commands or fight it out??
The device and controller get garbage. The controller only will be able to recognise the issue at certain times more often than not it cant tell, it might get a bus error that gets reported up, but your data will be meaningless.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Programming with I2C??

Tue Dec 10, 2013 10:30 pm

So I managed to get the RDA5807M working in native mode rather than compatible TEA5767 and sadly I have to say the RDS support sucks.
This chip does in fact decode RDS signals but it's data is presented in RAW format and would required the host computer to do all the hard work.
The datasheet doesn't really go into great detail on how to handle the information, there are 5 x 16bit blocks ABCD and E but no mention of error corrections.
This seems to contradict another datasheet I have on the Si4701 which states that RDS is 4 x 16bits data + 10bits error correction table = a total of 104bits.

To be honest RDS decoding is beyond me but it wouldn't be interested to know if anyone could crack it. :)

In any case the RDA5807M is quite a versatile radio and has many features that are lacking with the TEA5767:
-headphone amplifier for 16omhs x2 impedance
-bass boost switch
-good audio response at high frequencies although pilot tone still persists (no worse than the TEA5767 or a typical FM radio)
-75us / 50us de-emphasis that actually sounds like its working
-16 step volume control
-soft mute mode, reduce audio level with diminishing signal
-32 step adjustable stereo blend, blend stereo to mono depending on signal strength
-afc automatic frequency control for better signal locking
-better mpx decoding, the TEA5767 was quite noisy
-no audible noise leaks from the Pi, the TEA5767 had some weird rumbling noises in the background.

Richard S.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Programming with I2C - RDA5807M RDS information??

Tue Mar 25, 2014 2:13 pm

I've finally cracked the RDS decoding it looks like the RDA chip wasn't so difficult after all as first anticipated.
My main problem was the poor / lack of documentation on how to manage the data in each block.
To decode RDS successfully the chip needs a strong clean signal unfortunately the reception quality does degrade slightly while being strapped to the Pi.
I guess these FM chips work best being driven by battery powered ATMEL ATMEGA32 or something similar rather than a high/medium powered computer.

Code: Select all

RDS Text1: Radio 1
RDS Text2: Now Playing: Dark Horse by Katy Perry feat. Juicy J
Not Ready
In Sync
No BLOCK E
BLOCKS = ABCD
BLOCK DATA OK

Block_A, 1100 0010 0000 0001, c201
Block_B, 0000 0001 0101 1001, 0159
Block_C, 0111 1001 0110 0110, 7966, yf
Block_D, 0110 0100 0110 1001, 6469, di

Station Name: Radio 1 (PI=0xc201)
Group Type..: Station Name
Prog Type...: Pop Music
TP mode.....: 0
Char Offset.: 1
Other Msg...: 00011001
Well that's my 2 quid well spent :)

Richard S.

rastro
Posts: 1
Joined: Tue Apr 01, 2014 3:52 am

Re: Programming with I2C - RDA5807M RDS information??

Tue Apr 01, 2014 4:09 am

redhawk wrote:Well that's my 2 quid well spent :)
Could you please verify two questions for me and others:

Datasheet v1.0 says that the minimum Vdd is 1.8V, datasheet v1.1 says 2.7V
So, will it work at around 2V?

And the big plus for me is that the maximum frequency is 115MHz, at least the datasheet says so.
Is it really so? Can you enter those frequencies 109...115MHz ?

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Programming with I2C - RDA5807M RDS information??

Tue Apr 01, 2014 5:19 pm

There's no 108MHz limit that's just a software restriction, however the RDA5807M is capped at maximum of 120MHz (and 129MHz for the TEA5767).
As for voltage supply I didn't have anything suitable to recreate 2.0v so I used the voltage drop across a few rectifier diodes.
So far so good I managed to drive RDA with only 1.78v so the values quoted from the datasheet are pretty much spot on. :)

Richard S.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: [Done] Programming with I2C - RDA5807M

Thu Apr 03, 2014 11:17 pm

I've released the source code from my radio app project just in case anyone was having difficulty programming this chip - http://pastebin.com/zax6iH2f
However I've removed a few features such as auto scan and RDS/RBDS decoding, I didn't feel it was justified giving everything away for nothing.
Nevertheless it's still a fully functioning radio app with 76MHz - 120MHz tuning, volume control, bass boost, stereo / mono switching and 50us/75us de-emphasis selection.

To copy the source code to the Pi from pastebin you'll need to run the following:

Code: Select all

curl http://pastebin.com/raw.php?i=zax6iH2f | tr -d '\r' > rda.c
Richard S.

scbjorns
Posts: 1
Joined: Wed Jun 17, 2015 7:30 pm

Re: [Done] Programming with I2C - RDA5807M

Wed Jun 17, 2015 7:35 pm

Richard S.

I read through this posting and was very helpful in getting the Raspberry Pi to control the RDA5807M. I can successfully control the module but I can't get the RDS decoder to work. The signal is very strong but I don't get any RDS decodes or synchronization.

Did you have to do anything special to get the chip to decode the RDS connected to the Raspberry Pi? I think I can handle the data the chip would provide it. Any tips will be helpful.

Thanks,
scbjorns

gomme600
Posts: 2
Joined: Wed Aug 09, 2017 4:57 am

Re: [Done] Programming with I2C - RDA5807M

Wed Aug 09, 2017 5:02 am

Hi, did anyone else ever get rds decoding working? I'm working on a car pc project and rds is really a must. Also, do I need to change any pin assignments in the c program above? I am using the raspberry pi 3 and when typing "./rda freq 107.4" I get a message telling me that the radio is off or not tuned.
Thanks
Seb.

icraftcrafts
Posts: 4
Joined: Sat Dec 30, 2017 6:44 am

Re: [Done] Programming with I2C - RDA5807M

Sun May 27, 2018 2:23 pm

Thanks for the work, redhawk.

Return to “Interfacing (DSI, CSI, I2C, etc.)”