I2C protocol, explained

by Yaro

Introduction

TakkTile products rely on I2C communication to transfer the pressure data from the sensors. The two main components which use this digital protocol are micro-controller and the MEMS barometers. The micro-controller is Attiny24 and the barometric sensor is MPL115A2.

MEMS barometer - MPL115A2

The MPL115A2 MEMS barometer is using the standard I2C protocol.
The datasheet is here
Great application note (AN3785) explaining the I2C protocol is here
An example of code from Adafruit is here

The important note here is that chip-select pin of the sensor (Pin 5 - RST) should be driven high. Only then the communication interface of the sensor is activated and the pressure and temperature data can be retrieved.

I2C Commands (simplified for communication)

  • Device Address + write bit “To Write” = 0xC0
  • Device Address + read bit “To Read” = 0xC1
  • Command to Write “Convert Pressure and Temperature” = 0x12
  • Command to Read “Pressure ADC High byte” = 0x00
  • Command to Read “Pressure ADC Low byte” = 0x01
  • Command to Read “Temperature ADC High byte” = 0x02
  • Command to Read “Temperature ADC Low byte” = 0x03
  • Command to Read “Coefficient data byte 1 High byte” = 0x04

The flow of steps required to read the data is summarized in the table below:

Step Task Command
1 Start data conversion 0xC0 0x12
2 Wait for data to be processed. Datasheet says 1.6ms
3 Read the pressure and the temperature 0xC0 0x00 0xC1 (and read 4 bytes)

Chip-Select (Attinys)

The Attiny24 micro-controller is implemented to perform the chip-select function, i.e. select the sensor which should be sampled. The micro-controller listens to the I2C lines and has its digital outputs connected to the chip-select pins of the MEMS Barometer. When the chip-select pin of the sensor is driven high by the micro-controller it's communication interface is activated and then pressure and temperature data can be retrieved.

TakkTile_ArrayCircuit.png

The I2C address of the micro-controller is assigned to it when it is powered up. There could be up to 8 micro-controllers on the same line.

For example, the TakkStrip is using three dedicated pins for address assignment.

The address corresponds to the following table:

# A2 A1 A0 Address (Hex)
1 - - - 0x
2 - - X 1x
3 - X - 2x
4 - X X 3x
5 X - - 4x
6 X - X 5x
7 X X - 6x
8 X X X 7x

Enabling the sensors

Once the micro-controller is powered, it listens to the commands on the data lines. A custom approach was developed here to optimize the communications. In this case the I/O command is encrypted into the address. As such, the upper nibble of the address is used for addressing and the lower nibble is the command for enabling or disabling the sensor.

Even numbers are reserved for switching the sensors ON.
Odd numbers are reserved for switching the sensors OFF.

The table to illustrate the assigned commands:

Sensor 1 2 3 4 5
ON x0 x2 x4 x6 x8
OFF x1 x3 x5 x7 x9
* where x is the TakkStrip address.

For example;
Switching ON the first sensor of the TakkStrip with address 6x the master will need to send 60.
Switching OFF the first sensor, the master will need to send 61.

Enabling/Disabling all the sensors

MPL115 requires a command to start converting the pressure data. The conversion process takes about 1.6ms. An optimized approach was developed here where the micro-controller activates all the sensors together. Then the host can send the "start conversion" command, and all the activated sensors will start performing the command. Finally, the sensors could be read in a series.

The commands which are used to enable/disable all the sensors are:
ON - 0x0C
OFF - 0x0D

The process to read from a few sensors then becomes:

Step Task Command
1 Activate all the sensors 0x0C
2 Start data conversion 0xC0 0x12
3 Disable the sensors 0x0D
4 Wait for data to be processed. Datasheet says 1.6ms
5 Activate the first sensor (micro-controller address is 0x3x) 0x30
6 Read the pressure and the temperature 0xC0 0x00 0xC1 (and read 4 bytes)
7 Deactivate the first sensor 0x31
8 Activate the second sensor (micro-controller address is 0x3x) 0x32
9 Read the pressure and the temperature 0xC0 0x00 0xC1 (and read 4 bytes)
10 Deactivate the second sensor 0x33

Questions ?

Contact us: here

wordpress com stats

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial 3.0 License