This week support Thomas Henry I completed a series of investigations on GCB Software I2C. That required me to sort the I2C Hardware support in terms of usage and examples. I2C Hardware support is achieved by using the MSSP or SSP module in the Microchip product range.
The attached code is example code for a Hardware I2C Master (using the SSP/MMSP module) setting and retrieving data from an I2C Hardware Slave. And, I have included example code for Hardware I2C Master to set and retrieve data from a Software I2C slave.
The hardware Master is relatively simple. HI2CStart, HI2CSend and HI2CStop. The I2C data exchange is very similar to an EEPROM on address 0x0A.
The hardware Slave is interesting. It uses the SSP module interrupt and then updates the global variables. You can use software I2C or hardware I2C to communicate with the hardware slave.
Operations you can complete.
Discover Device - via I2C protocol.
Write Device - write bytes to update variable but this could be an array or whatever...
Read Device - read back the variables. Again, these are fixed in the example code but you can expand to return lots of different byte values.
Thomas Henry is working on the software I2C library at the moment, but, I thought I would share these as we do not have any examples of Hardware I2C in the current help file.
See posting with attachment for the hardware and the software code that does the same but with the software slave has limitations in terms of I2C performance, also it is not interrupt driven and it can/will lock the I2C clock line.
See the attachments.
The concept of the three LEDS belongs to Thomas Henry. All credit to him for the idea to use this test case.