I2C FM-radio
Posted: Thu Jan 14, 2016 12:48 pm
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.
[img]RRD-102.png[/img]
Also included a sub to read the 5 status-bytes from the chip. Not used but might be useful for testing.
Code: Select all
serialprintln "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]