How to communicate with digital devices like sensors, ADC, DAC for IOT (over I2C and SPI protocols)

Digital devices like sensors are the key element for the highly-connected ‘Internet of Things’ (IoT) networks that are increasingly being used in ‘smart city’ and ‘smart grid’ designs. Digital interfaces for the latest sensors, like temperature sensors, pressure sensors, humidity sensors are simplifying the interface to the IoT to enhance the reliability and functionality of systems. The Internet of Things starts with measurement. Being able to take data from devices anywhere in the world, linked up via the Internet to ‘big data’ information systems, provides the foundation for control and optimization. This is at the heart of smart city and smart grid developments around the world. Connecting sensors up to the Internet of Things is relatively simple in some cases, and in others needs more consideration.

There are two widely used interfaces for connecting digital devices to the Internet of Things are I2C and SPI interfaces.

I2C Interface

I²C (Inter-Integrated Circuit), pronounced I-squared-C, is a multi-master, multi-slave, packet switched, single-ended, serial computer bus invented in 1982 by Philips Semiconductor (now NXP Semiconductors). It is widely used for attaching lower-speed peripheral devices (like micro-controllers, EEPROMs, A/D and D/A converters, I/O interfaces and other similar peripherals in embedded systems) to processors and microcontrollers in short-distance, intra-board communication.

I2C bus is popular because it is simple to use, there can be more than one master, and only two wires with pull-up resistors are needed to connect almost unlimited number of I2C devices. I2C can use even slower micro-controllers with general-purpose I/O pins since they only need to generate correct Start and Stop conditions in addition to functions for reading and writing a byte. Each slave device has a unique address. Transfer from and to master device is serial and it is split into 8-bit packets. All these simple requirements make it very simple to implement I2C interface even with cheap micro-controllers that have no special I2C hardware controller. You only need 2 free I/O pins and few simple i2C routines to send and receive commands.

The initial I2C specifications defined maximum clock frequency of 100 kHz. This was later increased to 400 kHz as Fast mode. There is also a High speed mode which can go up to 3.4 MHz and there is also a 5 MHz ultra-fast mode.

Suppose, you are making IOT related project, then you might by using some sensors like temperature sensor etc. Suppose, we take TMP102 (from TI) which is Low-Power Digital Temperature Sensor having I2C interface. You connect your Controller to the temperature sensor with two lines I.e. SDA (Data Line) and SCL (Clock Line). Then using this interface, you can read temperature any time.

Below the is the application diagram of temperature sensor for IOT projects.

SPI Interface

The Serial Peripheral Interface bus (SPI) is a synchronous serial communication interface specification used for short distance communication, primarily in embedded systems. The interface was developed by Motorola in the mid 1980s and has become a de facto standard. SPI devices communicate in full duplex mode using a master-slave architecture with a single master. The master device originates the frame for reading and writing. Multiple slave devices are supported through selection with individual slave select (SS) lines. If there are three slave devices, then there will be three slave select pins. The SS line is normally held high, which disconnects the slave from the SPI bus. Just before data is sent to the slave, that particular slave select line is brought low, which activates the slave. When you’re done using the slave, the line is made high again.

Generally, SPI is used at 4MHz speed which is faster than I2C interface. So SPI is used where output from any sensor is required at high speed in order to process that data and take action as early as possible.

Suppose, you arranged many sensors for auto driving car, and data from each sensor is very important and decision making, then you would be working with high speed interface line SPI.

Or, for any Radio chain, you need to configure ADC / DAC at high speed, so you would be interfacing ADC / DAC over SPI interface.

For Example, ADT7320 is temperature sensor from Analog, over SPI interface.

Improvements in digital process technology and packaging are allowing sensors to have digital interfaces either integrated onto the same silicon or included in the same packaging. This is opening up the sensor technology for the Internet of Things over easy to implement protocols like SPI and I2C.

You may also like...