Introduction
Author: Filip Manole, Microchip Technology Inc. |
The approach in implementing the I2C communication protocol is different among the PIC18F device family of microcontrollers. While the PIC18-K40 and PIC18-Q10 product families have a Master Synchronous Serial Port (MSSP) peripheral, the PIC18-K42, PIC18-K83, PIC18-Q41, PIC18-Q43 and PIC18-Q84 product families have a dedicated I2C peripheral.
The MSSP and I2C peripherals are serial interfaces useful for communicating with external hardware, such as sensors or microcontroller devices, but there are also differences between them. The MSSP peripheral can operate in one of two modes: Serial Peripheral Interface (SPI) and Inter-Integrated Circuit (I2C), having the advantage of implementing both communication protocols with the same hardware. For a detailed comparison between the MSSP and dedicated I2C peripherals, refer to: Master Synchronous Serial Port (MSSP) to the Stand-Alone I2C Module Migration.
This technical brief provides information about the MSSP peripheral of the PIC18-K40 and PIC18-Q10 product families and intends to familiarize the user with the PIC® microcontrollers. The document covers the following use cases:
- Host Read/Write Data:
This example shows how the microcontroller configured in I2C Host mode interacts with different I2C Client devices on the PICkit Serial I2C Demo Board.
- Host Read/Write Data Using
Interrupts:
This example shows how the microcontroller configured in I2C Host mode writes to and reads data from an MCP23008 8-bit I2C I/O expander (client device), addressed in 7-bit mode, using interrupts.
For each use case, there are three different implementations, which have the same functionalities: one code generated with MPLAB® Code Configurator (MCC), one code generated using Foundation Services Library, and one bare metal code. The MCC generated code offers hardware abstraction layers that ease the use of the code across different devices from the same family. The Foundation Services generated code offers a driver-independent Application Programming Interface (API), and facilitates the portability of code across different platforms. The bare metal code is easier to follow, allowing a fast ramp-up on the use case associated code.