Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/16/08 03:09
Read: times


 
#159102 - TWI and AD7745 with 5131
Hi everyone!

I'm working on a project that needs to read a small capacitance and take the appropriate action.

We are using an AT89C5131A connected by an i2c (TWI) bus to an AD7745.

The software routine uses the built-in TWI interface of 8051's.

If i try to read any other registers, like 0x0A (configuration), the AD return the value perfectly.

But if try to read the capacitance registers (0x01, 0x02 and 0x03), the AD miss one or two bytes when the capacitance channel is enabled. If I reset it and read those registers, it returns 000000 (ok).
The program runs on a loop. Some readings returns three bytes, some two bytes or only one byte. Its not regular.

I adapted my code to show each step on the LCD. For example, when i get missed bytes, I see the following sequence for a 2-byte read:

S | 0x90 | A(s) | 0x01 | S | 0x91 | A(s) | Data1 | A(m) | A(m) | !A(m) | P

S= Start
0x90= AD write address
A(s) ACK by slave
0x01= first register to read
A(m)= ACK by master
!A(m)= not ACK by master
P= Stop

So, the microcontroler is issuing an ACK even when there is no data.

I tried the following:
-Set continuous conversion
-Set only one conversion, start and then stop the conversion
-Set continuous conversion, start and stop the conversion.
-check the ready flag of status register

All of then I get the same results.

I've tried also with the built-in temperature sensor, and i also get missed bytes

I wrote my code checking the value of sscon when the TWI interrupt is triggered.

I think that my code is correct, since i can read all bytes, except the capacitance/temperature when conversion bit is set.

The datasheet only mentions that i should read all bytes sequentially to prevent mixing data from different readings, and is not working :(

My code is below and based on Atmel's example. It's only missing the actions for arbitration lost (I do not understand what it does)

Thanks,

Danniel

call cdcreset
call cdcint
call cap

cap:
setb i2cbusy
mov i2cadd,#90h
mov cdcadd,#01h          ;first address read
mov i2cdp,#40h
mov i2ctask,#83h         ;8= read 3= three bytes
mov a,i2ctask
anl a,#0fh
mov i2cdatacnt,a				
mov ssdat,#00h
orl sscon,#20h
jb i2cbusy,$
ret

;------
;AD reset

jb i2cbusy,$
setb i2cbusy
mov i2cadd,#90h
mov cdcadd,#0bfh
mov i2ctask,#01h
mov ssdat,#00h
orl sscon,#20h
ret

;------
;AD initialization

jb i2cbusy,$
setb i2cbusy
mov 40h,#81h
mov i2cadd,#90h
mov cdcadd,#07h
mov i2cdp,#40h
mov i2ctask,#00h
mov ssdat,#00h
orl sscon,#20h
call delay50

jb i2cbusy,$ 
setb i2cbusy
mov 40h,#01h
mov i2cadd,#90h
mov cdcadd,#0ah
mov i2cdp,#40h
mov i2ctask,#00h
mov ssdat,#00h
orl sscon,#20h
jb i2cbusy,$ 
call delay50
ret


;-----
;i2c interrupt

i2c:
push acc
push psw
push 00h
push 06h
push 07h


mov r7,sscs

cjne r7,#00,end00
clr i2cbusy
jmp i2cexit
end00:

cjne r7,#08,end08
anl sscon,#~20h
mov ssdat,i2cadd
orl sscon,#04h

jmp i2cexit

end08:
cjne r7,#10h,end10

anl sscon,#~20h
inc i2cadd
mov ssdat,i2cadd
orl sscon,#04h
jmp i2cexit

end10:
cjne r7,#18h,end18


mov ssdat,cdcadd
orl sscon,#04h
orl i2ctask,#20h
jmp i2cexit

end18:
cjne r7,#28h,end28

mov a,i2ctask
jnb acc.7,writedata
orl sscon,#20h
jmp i2cexit
writedata:
mov a,i2ctask
jb acc.0,sendstop
jb acc.4,sendstop
mov ssdat,40h

orl sscon,#04h
orl i2ctask,#10h
jmp i2cexit
sendstop:
orl sscon,#10h 				;envia STOP
orl i2ctask,#10h
clr i2cbusy
jmp i2cexit

end28:
cjne r7,#40h,end40
mov a,#'A'
call dispchar

djnz i2cdatacnt,j8
anl sscon,#0c3h
jmp i2cexit
j8:
orl sscon,#04h
jmp i2cexit

end40:
cjne r7,#50h,end50

mov r0,i2cdp
mov a,ssdat
mov @r0,a
call dispascii
mov a,#'a'
call dispchar
inc i2cdp
djnz i2cdatacnt,j7
anl sscon,#0c3h
jmp i2cexit

j7:
orl sscon,#04h
jmp i2cexit


end50:
cjne r7,#58h,end58


mov r0,i2cdp
mov a,ssdat
mov @r0,a
call dispascii
mov a,#'n'
call dispchar
inc i2cdp
orl sscon,#10h
clr i2cbusy
mov a,#'P'
call dispchar


end58:
i2cexit:
anl sscon,#~08h
pop 07h
pop 06h
pop 00h
pop psw
pop acc
reti


List of 12 messages in thread
TopicAuthorDate
TWI and AD7745 with 5131            01/01/70 00:00      
   where is main routine?            01/01/70 00:00      
      Routines            01/01/70 00:00      
         lack ot time ????            01/01/70 00:00      
            License on I2C            01/01/70 00:00      
            Code            01/01/70 00:00      
               Slave?            01/01/70 00:00      
                  Master            01/01/70 00:00      
            TWI is a very common "generic" name for I2C-compat            01/01/70 00:00      
               I do not think so            01/01/70 00:00      
                  Oh yes it is! (with examples)            01/01/70 00:00      
                     Don't want to fight a lawyer            01/01/70 00:00      

Back to Subject List