I2C on PIC: Microchip MCC Boilerplate Is A Pretty Good Tutorial In Itself.

After completing the MCC tutorial, I knew I wanted to start learning about implementing I²C on the PIC micro controller. I planned to use PIC in conjunction with a Raspberry Pi and I²C is the protocol already used by existing Raspberry Pi peripherals. I wanted my PIC projects to play well with others in this ecosystem.

The Microchip tutorial covered serial communication with the EUSART module but not communication with the MSSP (Master Synchronous Serial Port) module that assists with implementing the I²C protocol.  I went hunting for such a tutorial elsewhere on the Microchip web site but didn’t find one.

At this point I was not terribly worried. The PIC16F18345 data sheet provided an overview of implementing I²C using the MSSP module.  Section 30.5 I2C Slave Mode Operation included a list of operations during normal I²C communication. This list was almost a pseudo-code outline of what the developer needs to do to implement I²C communication on the PIC.

I would be happier if there was a tutorial walking through the actual code of an I²C implementation, but the pseudo-code should be enough to help me take whatever boilerplate MCC (MPLAB Xpress Code Configurator) generated and filling in the missing parts.

I created a new PIC project and used MCC to enable the MSSP module for I²C communication. After auto generation was complete, I went into the code ready to get to work. And… hmm… what’s this?


The MCC boilerplate is more than just a bunch of function prototypes, it’s actually an implementation of an I²C slave acting like a EEPROM device. This was, for all practical purposes, the tutorial I had been looking for. Within an hour I was controlling the brightness of a single LED via commands sent over I²C bus and interpreted by my PIC.

So let this be an announcement to other PIC programming novices: sometimes the tutorial you’re looking for is right in the MCC boilerplate code.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s