PIC32 and I2C

I’ve been struggling with Microchip’s plib library trying to get I2C working.  First, the example I2C code is horrible.  Second, I’m not even sure what sample hardware from Microchip actually uses it.  It’s just so confusing.

Anyway, there are a few things to note here about the I2C library and the quirks that it has:

  • Make sure that you have pull-up resistors on the I2C bus.  This was problem #1.
  • Make sure you configure all pins as digital, if they are analog pins.  This was problem #2.
  • There are two methods you need to acknowledge the I2C: I2CAcknowledgeByte and I2CByteWasAcknowledged.
  • When reading a byte from the bus when you are the master, you need to call I2CReceiverEnable for each byte that you need to get.

These functions are not very special; the problem is that they are poorly documented.  For the most part, the plib functions simply access the registers directly in memory and return an appropriate value after checking the bits that may be set as a side effect.  It’s not particularly hard, they are just oddly named often times.

Anyway, you can see more about this both here and… some other place on the Microchip forums, I can’t find it now.

Hope that helps.

Leave a Reply

Your email address will not be published. Required fields are marked *