Summary of chipKIT Tutorial 6: Inter-Integrated Circuit (I2C) communication
This tutorial demonstrates using the chipKIT Wire library to read temperatures from two I2C sensors (Maxim DS1631 and Microchip TC74A0) on a chipKIT Uno32. It covers I2C basics, wiring (SDA to A4, SCL to A5, pull-ups, and DS1631 address pins set for 0x49), the sketch using Wire functions, and shows serial monitor outputs comparing both sensors.
Parts used in the I2C communication demo:
- chipKIT Uno32 board
- Maxim DS1631 digital temperature sensor
- Microchip TC74A0 digital temperature sensor
- Breadboard
- Jumper wires
- Pull-up resistors for SDA and SCL (1K to 10K)
- 3.3V power supply (from Uno32)
- Shunt jumpers JP6 and JP8 set to RG3 and RG2 positions
I2C or IIC (Inter-Integrated Circuit) is a simple bidirectional serial interface, which requires only 2 signal lines for data transfer. It was originally developed by Philips in 1980′s to provide easy on-board communications between a CPU and various peripheral chips in a TV set. Today, it is widely used in varieties of embedded systems to connect many low speed peripherals, such as external EEPROMs, sensors, LCD drivers, port expanders, real-time clocks, etc, to the host microcontroller.chipKIT Tutorial 6: Inter-Integrated Circuit (I2C) communication In this tutorial, we will explore the chipKIT Wire Library for establishing an I2C communication link between the chipKIT Uno32 board and two I2C sensors. The Uno32 board receives the sensor outputs through the I2C link and displays the results on the serial monitor window on the computer screen.

Theory
An I2C bus consists of two signal lines called SDA (data) and SCL (clock). Just line Arduino Uno, the chipKIT Uno32 board offers the SDA and SCL connections via analogue input pins A4 and A5 respectively. Each device connected to the I2C bus is software addressable by an unique 7-bit address. Multiple I2C devices can be connected to the same I2C bus as long as they have different addresses. A simple Master and Slave relationship exist at all times between the communicating devices. The Master device initiates a data transfer, generates clock signals and terminates the transfer. Any device addressed by the Master at any time is considered a slave. Both SDA and SCL are open-drain lines, and therefore, require two pull-up resistors during operation. A more detail look of the I2C Bus protocol and how the exchange of information takes place between Master and Slave has been discussed in one of my previous tutorials, Inter-Integrated Communication in PIC MCU. So I am not going to repeat that here again.
In this tutorial, we are going to experiment with two digital temperature sensors that support I2C communication. They are Maxim’s DS1631 and Microchip’s TC74 devices.

Similarly, the TC74 device is also a serially accessible digital temperature sensor that provides a temperature measurement as an 8-bit word. The resolution is thus 1 degree Celsius. Its features are highlighted below. It should be noted that there are no external pins for configuring the I2C address. This means that the 7-bit I2C address of TC74 is fixed and set by manufacturer. Eight versions of TC74 are available, namely TC74A0 through TC74A7, with different I2C address values. I am using TC74A0, which has the 7-bit address fixed to 1001000 (0x48).

Please read the datasheets of DS1631 and TC74 for more information on these devices.
Circuit Setup
Circuit diagram for connecting DS1631 and TC74A0 to chipKIT Uno32
Complete circuit layout on breadboard
Perhaps you have noticed that the four most significant bits of the I2C addresses of DS1631 and TC74A0 are same (1001). The remaining address bits of TC74A0 are fixed (000). But the same bits are configurable for DS1631 through its hardware pins. We will ground the pins A1 and A2, and pull-up pin A0 to VCC so that the I2C address of DS1631 would be 1001001 (0x49). We build the following circuit on a breadboard and power it through the 3.3V power supply from the Uno32 board. The SDA and SCL signal lines are connected to analog input pins A4 and A5, respectively. Note that the jumpers JP6 and JP8 must be placed in the RG3 and RG2 position in order to use these pins for I2C operation. See Exploring chipKIT Uno32 for more details on the functions of various shunt jumpers on the Uno32 board. The pull-up resistors for the I2C signal lines can be of value anywhere between 1K and 10K, at least for this experiment.
chipKIT Sketch
The Arduino’s standard Wire library is also implemented in MPIDE, which allows chipKIT Uno32 to communicate with I2C devices. The Wire library uses 7 bit addresses for addressing slave devices on the I2C bus. Following are the main functions available in the Wire library.
Wire.begin() initializes the Wire library and configures analog pins A4 and A5 as I2C pins. This should normally be called only once.
Wire.beginTransmission(address) begins a transmission to the I2C slave device with the given 7-bit address.
Wire.send(data) sends data to the slave device.
Wire.requestFrom(address, count) is used by Master to request a specific number of bytes from a slave device.
Wire.receive() is used by Master to retrieve a byte that was transmitted from a slave device after a call to Wire.requestFrom(address, count)
Wire.endTransmission() ends the data transmission.
Wire.available() returns the number of bytes available for retrieval with Wire.receive().
More details on the chipKIT specific Wire library can be found here.
Here’s the sketch written for requesting temperature readings from the DS1631 and TC74A0 devices and display them on the Serial Monitor window.
/*
Tutorial 6: I2C communication demo
Description: Explore the I2C serial communication protocol and interface
two I2C slave devices to chipKIT Uno32 using a common I2C bus.
Two devices: DS1631 and TC74A0 temperature sensors.
Board: chipKIT UNO32
Connect SDA to Arduino pin A4 (SDA)
Connect SCL to Arduino pin A5 (SCL)
Written by: Raj Bhatt (April 2014)
www.embedded-lab.com
*/
#include <Wire.h>
int DS1631_Address = 0x49; // 7-bit I2C address for DS1631
int TC74A0_Address = 0x48; // 7-bit I2C address for TC74A0
// setup loop
void setup(){
Serial.begin(9600);
Serial.println("IIC Test: Temperature sensors");
Wire.begin();
}
// Main Loop
void loop(){
float temp1 = Read_Temp_DS1631();
Serial.print("DS1631 reading: ");
Serial.print(temp1, 4);
Serial.println(" degC");
float temp2 = Read_Temp_TC74A0();
Serial.print("TC74A0 reading: ");
Serial.print(temp2, 2);
Serial.println(" degC");
delay(1000);
}
// Function sub-routine for reading temperature from DS1631
float Read_Temp_DS1631(){
float tempC1;
int MSbyte1, LSbyte1;
Wire.beginTransmission(DS1631_Address);
Wire.send(0x51); // Send Start Convert command
Wire.endTransmission();
delay(1000); // Wait until temperature conversion is done
Wire.beginTransmission(DS1631_Address);
Wire.send(0xAA); // Send Read Temperature Command
Wire.endTransmission();
Wire.requestFrom(DS1631_Address, 2); // Request two temperature bytes
while(Wire.available()) //
{
MSbyte1 = Wire.receive();
LSbyte1 = Wire.receive();
}
Wire.endTransmission();
LSbyte1 = LSbyte1>>4;
tempC1 = (float)MSbyte1 + (float)LSbyte1*0.0625;
return tempC1;
}
// Function sub-routine for reading temperature from TC74A0
float Read_Temp_TC74A0(){
float tempC2;
int MSbyte2;
Wire.beginTransmission(TC74A0_Address);
Wire.send(0x00); // Send Read Temperature command
Wire.endTransmission();
Wire.requestFrom(TC74A0_Address, 1); // Request a temperature byte
while(Wire.available()) //
{
MSbyte2 = Wire.receive();
}
Wire.endTransmission();
tempC2 = (float)MSbyte2;
return tempC2;
}
Output
Complete experimental setup
Temperature outputs from DS1631 and TC74A0
Upload the above sketch to the Uno32 board and then open the Serial Monitor window to display the temperature readings from the two sensors.
- What pins on the Uno32 are used for SDA and SCL?
Analog input pins A4 (SDA) and A5 (SCL) are used. - How are the DS1631 address pins configured for address 0x49?
Ground A1 and A2, and pull up A0 to VCC to set DS1631 address to 0x49. - Does the TC74A0 have a configurable I2C address?
No, the TC74A0 used (TC74A0) has a fixed 7-bit address 0x48. - What Wire library function initializes I2C on the Uno32?
Wire.begin() initializes the Wire library and configures A4 and A5 for I2C. - How many bytes does the sketch request from the DS1631?
The sketch requests two bytes from the DS1631 using Wire.requestFrom(DS1631_Address, 2). - What pull-up resistor values are recommended for SDA and SCL in this experiment?
Pull-up resistors between 1K and 10K are acceptable for this experiment. - How does the sketch read the TC74A0 temperature?
The sketch sends 0x00, requests one byte with Wire.requestFrom(TC74A0_Address, 1), then uses Wire.receive() to get the temperature. - What is the resolution of the TC74 temperature reading?
The TC74 provides an 8-bit temperature value with 1 degree Celsius resolution.



