Summary of Interfacing the Microchip PIC18F Microcontroller Master Synchronous Serial Port (MSSP) to various I2C Devices
This article introduces the I2C bus, its master-slave, wired-OR pull-up resistor topology, and explains how a PIC18F14K22 microcontroller uses its MSSP module in I2C master mode to control multiple I2C devices. It describes bus idle states, START signaling, 7-bit addressing with a read/write bit, and contrasts I2C addressing with SPI chip select usage.
Parts used in the PIC18F14K22 I2C Master Project:
- Microchip PIC18F14K22 microcontroller
- Pull-up resistors for SDA and SCL lines
- I2C slave devices (e.g., temperature sensor)
- I2C slave devices (e.g., ADC)
- I2C slave devices (e.g., DAC)
- I2C slave devices (e.g., I/O expander)
- I2C slave devices (e.g., EEPROM)
The Inter-Integrated Circuit or I2C (read as I square C) bus has been introduced in 1980 by Philips, and has become a de-facto world standard for data exchange between Microcontroller and various devices such as temperature sensor, ADC (analog to digital converter), DAC (digital to analog converter), I/O expander, EEPROM, and many more. With more than thousand different IC devices have been manufactured with an I2C-bus interface, making the understanding of the working principle of this I2C bus is an essential knowledge that has to be acquired by anyone who want to involve in the embedded world professionally or just as hobbyist.
In this project we will learn of how to use the powerful 8-Bit Microchip PIC18F14K22 microcontroller Master Synchronous Serial Port (MSSP) in the I2C master mode to control various I2C devices simultaneously
The I2C Bus Protocol
The I2C bus use master and slave communication principle which mean the slave will response to any master request and only one master or one slave could use the I2C bus at the time (half-duplex communication). Therefore the master and slave have to be connected known as “Wired OR” connection using the pull-up resistors for both the I2C serial data (SDA) and serial clock (SCL) as shown on this following picture.
Unlike the SPI (Serial Peripheral Interface) slave devices, the I2C devices don’t have the chip select (CS) pin where the SPI master could simply drive the CS pin to logic “0” in order to communicate with the target SPI slave device, instead in I2C protocol the I2C master will transmit the I2C slave device unique address in order to communicate with it.
When the I2C bus is idle both of the SDA and SCL line will be logic “1”. When the I2C master want to start communicate first it will send the START signal by putting the SDA line to logic “0” then it start to send the 7-bit I2C slave address followed by 1-bit I2C bus transfer direction command (WRITE logic “0” or READ logic “1”). The 7-bits I2C slave address consists of the upper 4-bits (ID3, ID2, ID1, and ID0) whose are the device specific ID (identification) and encoded within each of the I2C slave device.
For more detail: Interfacing the Microchip PIC18F Microcontroller Master Synchronous Serial Port (MSSP) to various I2C Devices
- What microcontroller is used in the project?
The Microchip PIC18F14K22 microcontroller is used. - How does I2C differ from SPI in selecting a target device?
I2C transmits a 7-bit slave address and a read/write bit instead of using a chip select pin as in SPI. - What are the idle states of SDA and SCL on the I2C bus?
Both SDA and SCL are logic 1 when the I2C bus is idle. - How does the I2C master start communication?
The master sends a START signal by pulling SDA to logic 0, then transmits the 7-bit address and the read/write bit. - What is the purpose of pull-up resistors on SDA and SCL?
Pull-up resistors implement the wired OR connection and ensure SDA and SCL return to logic 1 when idle. - How many bits are in the I2C slave address used in this project?
The project uses a 7-bit I2C slave address plus one read/write bit. - What devices can be controlled over I2C according to the article?
Devices include temperature sensors, ADCs, DACs, I/O expanders, and EEPROMs. - Can multiple I2C devices share the bus?
Yes, multiple I2C devices share the bus; the master addresses each device by its unique address.