>-----Original Message-----
>From:
.....piclist-bouncesKILLspam
@spam@mit.edu [
piclist-bounces
KILLspammit.edu]
>Sent: 14 March 2005 11:25
>To:
.....piclistKILLspam
.....mit.edu
>Subject: [PIC] slave I2C problems, WCOL bit
>
>
>Hello all,
>
>I am using a PIC 16F877 as an interrupt-driven I2C slave and
>have found one issue, which I would like to share with others.
>
>Sometimes, when the PIC is addressed for reading (i.e. master
>reads, PIC writes), it would fail to transmit the 2nd or
>subsequent data bytes back to the master. This would never
>happen for single-byte messages, though. The problem seems to
>be that sometimes, when the SSP interrupt is entered with
>SSPSTAT containing:
>
>S = 1 (START condition seen last in the bus)
>RW = 1 (master wants to read a byte)
>DA = 1 (last byte sent was data)
>BF = 0 (buffer is empty)
>
>and you write a byte to SSPBUF, the SSP module detects a
>collision and sets the WCOL bit, and SSPBUF is not updated.
>
>In theory this should never happen. According to app note 734:
>
>"In practice, there will be no write collisions if the
>application firmware only writes to SSPBUF during states when
>the BF bit is cleared and the Slave device is transmitting
>data to the Master."
>
>However here there is a write collision, even though BF was
>clear at the time SSPBUF is written to.
>
>It is possible to work around this by checking WCOL
>immediately after writing to SSPBUF (which, on the other hand,
>is exactly what the code from AN734 does), e.g.:
>
>_tryagain
> bcf SSPCON, WCOL
> movwf SSPBUF
> btfsc SSPCON, WCOL
> goto _tryagain
>
>However I don't understand why this is happening.
>Theoretically there should not be any write collisions if the
>buffer is empty.
>
>Anyone has seen this before?