PIC16F87 to TDA7439 I2C interface

Status
Not open for further replies.

zkt_PiratesDen

New Member
The tda7439 is a sound processor chip and is controlled by a pic16f87. Communication is over an I2C buss as described below.

If the ack pulse sent by the tda7439 is ignored, It was easier to write my own I2C control code than use the pic I2C registers. The tda requires the PIC to do the following sequence of events in order for communication to take place.
1 .start condition: PIC holds scl line high while sda goes high to low
2. pic sends 8 adr bits on sda while sending clock on sck. data changes only when scl is low
3. on the 9th scl bit the tda7439 sends an acknoledgement pulse by pulling the sda low- this is ignored by pic
4. pic sends 8 sub_adr bits on sda while sending clock on sck. data changes only when scl is low
5. ack is ignored
6. pic sends 8 data bits on sda while sending clock on sck. data changes only when scl is low
7. ack is ignored
8. stop condition: while scl is high, sda goes low to high

The tda data sheet makes no ref to the scl freq, so I assume that a period of 1888us is ok.
The test setup consists of a signal on the tda input #2 (the defalt input pin upon power-up) The output is taken from the tda mux input selector. The scope verifies that the chip is working.
Running the following code should switch the tda input to#4, thereby shutting off the output. Naturally it doesnt. Big surprise. Befor I spend the rest of the day troubleshooting this thing, perhaps someone sees a blatant error that I have overlooked.? only the tda part of the code is shown>
Thanks
Code:
program rc5
' pic 16F87
dim dly_half_period,n,tmp,addr,data,which_byte,scl,sda as byte

const tda_adr=$88
const tda_sub_adr=$00    'aray
const tda_data=$00
                             ' portb.0-5: display
                             ' portb.6: input pin
                             ' portb.7 scl
                             ' porta.7 sda
main:
osccon=%01110010
while iofs=1
wend
cmcon=7
trisa=32
trisb=64
portb=%00111111
porta=0
t2con.t2ckps1=1
dly_half_period=0
tmp=0
n=12
addr=0
data=0
which_byte=0

'goto rc5

tda_start:
scl=%10000000
portb = portb and 128
sda=%10000000
porta = porta and 128
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend
sda=0
porta=sda and 128
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend

tda_adr:
for n=0 to 7
scl= not scl
portb=portb and 128
if portb.7=0 then
   tmp=tda_adr
   tmp=tmp<<n
   porta=tmp and 128
   end if
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend
next n                            ' skip 9th sck bit
scl=0
portb=scl and 128
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend
scl=1
portb= portb and 128
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend

tda_sub_adr:
for n=0 to 7
scl= not scl
portb=portb and 128
if portb.7=0 then
   tmp=tda_sub_adr
   tmp=tmp<<n
   porta=tmp and 128
   end if
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend
next n                            ' skip 9th sck bit
scl=0
portb=scl and 128
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend
scl=1
portb= portb and 128
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend

tda_data:                        ' send tda_addr
for n=0 to 7
scl= not scl
portb=portb and 128
if portb.7=0 then
   tmp=tda_data
   tmp=tmp<<n
   porta=tmp and 128
   end if
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend
next n                            ' skip 9th sck bit
scl=0
portb=scl and 128
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend
scl=1
portb= portb and 128
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend

tda_stop:
scl=%10000000
portb = portb and 128
sda=%00000000
porta = porta and 128
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend
sda=%10000000
porta=sda and 128
pir1.tmr2if=0
t2con.tmr2on=1
t2con.t2ckps1=1
while pir1.tmr2if=0
wend
 
hi everone,
how to control tda 7439 from pic F877 and picbasic,
please sample code volume control or etc.
thanks all,
 
hi zkt pratesden , your code is microbasic or mbasic? my pbp compiler have a lot error on this code? how to use this code pls help? thanks
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…