-->
Page 1 of 3

I2C FM-radio

PostPosted: Thu Jan 14, 2016 12:48 pm
by luc VdV
I used the FM-module RRD-102 ver:2.0 and used it in compatible mode so the TEA5767 chip should also work.
Also included a sub to read the 5 status-bytes from the chip. Not used but might be useful for testing.

Code: Select allserialprintln "created with ESP Basic V1.76"
freq = 88.5
mute = 0
[BuildPage]
cls
wprint "Freq="
textbox freq
wprint "MHz  "
button "Update freq" [BuildPage]
button "Exit" [Exit]
button "Mute" [ToggleMute]
gosub [I2C_write5regs]
wait

[ToggleMute]
if mute = 0 then mute = 1 else mute = 0
goto [BuildPage]

[I2C_write5regs]
' PLL = int(4x(freq+225000)/32768)
pll = freq * 1000
pll = pll + 225
pll = pll * 4000
pll = pll / 32768
pll = int(pll)
pll_hi = pll / 256
pll_hi = int(pll_hi)
x = pll_hi * 256
pll_lo = pll - x
pll_lo = int(pll_lo)
reg1 = pll_hi
reg2 = pll_lo
reg3 = 16
reg4 = 16
reg5 = 0
if mute = 1 then reg1 = reg1 + 128
i2c.begin(96)
i2c.write(reg1)
i2c.write(reg2)
i2c.write(reg3)
i2c.write(reg4)
i2c.write(reg5)
i2c.end()
return

[Exit]
mute = 1
gosub [I2C_write5regs]
end

[I2C_read5regs]
i2c.requestfrom(96,5)
reg1 = i2c.read()
reg2 = i2c.read()
reg3 = i2c.read()
reg4 = i2c.read()
reg5 = i2c.read()
i2c.end()
serialprintln "read="
serialprintln reg1
serialprintln reg2
serialprintln reg3
serialprintln reg4
serialprintln reg5
return


[img]RRD-102.png[/img]

Re: I2C FM-radio

PostPosted: Thu Jan 14, 2016 10:55 pm
by forlotto
Ho Wow an FM radio who would have thought this thing just keeps getting better like wine!

Good Job!

Re: I2C FM-radio

PostPosted: Fri Jan 15, 2016 12:14 am
by Mmiscool
This is really awesome. Do you have any pictures of your build.

How about using a slider for the frequency maybe?

I really can't believe all the stuff you have manged to get done here in basic.

Re: I2C FM-radio

PostPosted: Wed Jan 20, 2016 2:35 pm
by luc VdV
The same project, same RRD-102 but now in 16-bit mode. Nothing is changed on the hardware side.
Also included a slider to adjust the volume.
subroutine [I2C_readregs] is included but not used in this light-version.
See manual of RDA5807M for details of the registers.
Code: Select allserialprintln "created with ESP Basic V1.77"
freq = 94.2
volume = 8

[BuildPage]
gosub [I2C_writeregs]
cls
wprint "volume:"
slider volume 0 15
wprint "<br>Freq="
textbox freq
wprint "MHz<br>"
button "Apply changes" [BuildPage]
wprint "<br>"
button "Exit" [Exit]
wait

[I2C_writeregs]
gosub [buildregisters]
i2c.begin(16)
i2c.write(reg2h)
i2c.write(reg2l)
i2c.write(reg3h)
i2c.write(reg3l)
i2c.write(reg4h)
i2c.write(reg4l)
i2c.write(reg5h)
i2c.write(reg5l)
i2c.end()
return

[buildregisters]
reg2h = 242
reg2l = 141
if volume = 0 then reg2h = reg2h - 64
chan = freq * 1000
chan = chan - 87000
chan = chan / 100
chan = chan * 64
reg3h = chan / 256
reg3h = int(reg3h)
x = reg3h * 256
reg3l = chan - x
reg3l = int(reg3l)
reg3l = reg3l + 16
reg4h = 4
reg4l = 0
reg5h = 128
reg5l = 128 + volume
return

[I2C_readregs]
i2c.requestfrom(16,4)
regah = i2c.read()
regal = i2c.read()
regbh = i2c.read()
regbl = i2c.read()
i2c.end()
return

[Exit]
volume = 0
gosub [I2C_writeregs]
cls
end