Re: Difference between 24LC32 and 24LC32A using PIC 16F877A's I2C protocol?



Hello all,

I think I need to follow up with source code here, can some one spot
some potential timing issues with this code which may cause the write
operation to fail.

The code would select the device using ADDRSW for write operation,
RomAddrsW:2 provides the address, data is provided by RomDataW. The
observation is that after writing the first byte it gets stuck
somewhere. And if you notice in the code, I shouldnt have timing
problems since the clock frequency is 333khz (4MHZ crystal and BRG
value = 2). This code works fine with 24LC32A but doesnt work with
24LC32... any ideas ?

WrtStart:
banksel SSPCON2
bsf SSPCON2, SEN ; initiate start condition
btfsc SSPCON2, SEN ; hardware reset to 0?
goto $ - 1 ; if not, poll again

WrtAddrs:
banksel SSPBUF ; select device
movlw ADDRSW ; apply device address to write to
movwf SSPBUF
banksel SSPSTAT
btfsc SSPSTAT, R_W ; poll until reset to indicate xmit complete
goto $ - 1
banksel SSPCON2
btfsc SSPCON2, ACKSTAT ; if ACKSTAT is cleared by slave, then
continue
goto WrtStop ; if not set, then slave sends not acknowledge

banksel SSPBUF
movf HIGH ( RomAddrsW ), w ; apply device address to write to
movwf SSPBUF
banksel SSPSTAT
btfsc SSPSTAT, R_W ; poll until reset to indicate xmit complete
goto $ - 1
banksel SSPCON2
btfsc SSPCON2, ACKSTAT ; if ACKSTAT is cleared by slave, then
continue
goto WrtStop ; if not set, then slave sends not acknowledge

banksel SSPBUF
movf LOW ( RomAddrsW ), w ; apply device address low to write to
movwf SSPBUF
banksel SSPSTAT
btfsc SSPSTAT, R_W ; poll until reset to indicate xmit complete
goto $ - 1
banksel SSPCON2
btfsc SSPCON2, ACKSTAT ; if ACKSTAT is cleared by slave, then
continue
goto WrtStop ; if not set, then slave sends not acknowledge

WrtByte:
banksel SSPBUF
movf RomDataW, w ; apply device address to write to
movwf SSPBUF
banksel SSPSTAT
btfsc SSPSTAT, R_W ; poll until reset to indicate xmit complete
goto $ - 1
banksel SSPCON2
btfsc SSPCON2, ACKSTAT ; if ACKSTAT is cleared by slave, then
continue
goto WrtStop ; if not set, then slave sends not acknowledge

WrtStop:
banksel SSPCON2
bsf SSPCON2, PEN ; generate stop condition
btfsc SSPCON2, PEN ; is PEN bit reset?
goto $ - 1 ; if yes, exit

exit_wrt:
return
;-------------------------------------------------------------

Any help...

Thnx in advance

Mak
.