Tuesday, February 17, 2009

Microchip I2C slave ISR calls for reading and writing

PIC24 / PIC30 / PIC32 acting as I2C slave.

If the host writes a byte to address 0x40 (0x40, data), 2 calls to the ISR occur:
(1)
  I2CxSTATbits.D_A = 0 (address)
  I2C2STATbits.R_W = 0 (write)
  I2CxRCV = 0x40 (our address)
  Don't load I2CxTRN.
(2)
  I2CxSTATbits.D_A = 1 (data)
  I2C2STATbits.R_W = 0 (write)
  I2CxRCV = incoming data
  Don't load I2CxTRN

If the host reads a byte from address 0x40, 1 call to the ISR occurs:
(1)
  I2CxSTATbits.D_A = 0 (address)
  I2C2STATbits.R_W = 1 (read)
  I2CxRCV = 0x40 (our address)
  Load I2CxTRN with response