IOT Protocols
IOT Protocols
EMBEDDEDXPRESS
Embedded Communications Protocols andInternet of
Things
COMMUNICATION:
Communication between electronic devices is like communication between humans. Both
sides need to speak the same language. In electronics, these languages are called communication
protocols. Luckily for us, there are only a few communication protocols we need to know when
building most electronics projects. In this series of articles, we will discuss the basics of the three
most common protocols: SPI, I2C and UART.
SPI, I2C, and UART are quite a bit slower than protocols like USB, Ethernet, Bluetooth,
and Wi-Fi, but they’re a lot simpler and use less hardware and system resources. SPI, I2C, and
UART are ideal for communication between microcontrollers and between microcontrollers and
sensors where large amounts of high speed data don’t need to be transferred.
DATA COMMUNICATION TYPES: (1) PARALLEL
(2) SERIAL: (I) ASYNCHRONOUS (II) SYNCHRONOUS
Parallel Communication:
In parallel communication, all the bits of data are transmitted simultaneously on
separate communication lines.
Used for shorter distance.
In order to transmit n bit, n wires or lines are used.
More costly.
Faster than serial transmission.
Data can be transmitted in less time.
Example: printers and hard disk
Serial Communication Basics:
In serial communication the data bits are transmitted serially one by one i.e. bit by bit
on single communication line
It requires only one communication line rather than n lines to transmit data from
sender to receiver.
Thus all the bits of data are transmitted on single lines in serial fashion.
Less costly.
Long distance transmission.
Example: Telephone.
Page 1 of 65
By Ezrah Buki On LinkedIn
Serial communication uses two methods:
Asynchronous.
Synchronous.
Asynchronous:
Transfers single byte at a time.
No need of clock signal
Example: UART (universal asynchronous receiver transmitter)
Synchronous:
Transfers a block of data (characters) at a time.
Requires clock signal
Example: SPI (serial peripheral interface),
I2C (inter integrated circuit).
Data Transmission: In data transmission if the data can be transmitted and received,
it is a duplex transmission.
Simplex: Data is transmitted in only one direction i.e. from TX to RX only one TX
and one RX only
Half duplex: Data is transmitted in two directions but only one way at a time i.e. two
TX's, two RX’s and one line
Full duplex: Data is transmitted both ways at the same time i.e. two TX's, two RX’s
and two lines
Page 2 of 65
By Ezrah Buki On LinkedIn
Table: Various Serial Communication Protocols
Serial Synchronous Data transfer
Type Duplex
Protocol /Asynchronous rate (kbps)
Page 3 of 65
By Ezrah Buki On LinkedIn
Microcontroller of our interest TM4C123 supports UART, CAN, SPI, I2C and USB
protocols. The five (UART, CAN, SPI, I2C and USB) above mentioned communication
protocols are available in most of the modern day microcontrollers. Before studying the
implementation and programming details of these protocols in TM4C123, it is required to
understand basic standards, features and applications. In the following sections, we discuss
fundamentals of the above mentioned communication protocols.
UART COMMUNICATION
In UART communication, two UARTs communicate directly with each other. The transmitting
UART converts parallel data from a controlling device like a CPU into serial form, transmits it in serial to
the receiving UART, which then converts the serial data back into parallel data for the receiving device.
Only two wires are needed to transmit data between two UARTs. Data flows from the Tx pin of the
transmitting UART to the Rx pin of the receiving UART:
UARTs transmit data asynchronously, which means there is no clock signal to synchronize the
output of bits from the transmitting UART to the sampling of bits by the receiving UART. Instead of a
clock signal, the transmitting UART adds start and stop bits to the data packet being transferred. These bits
define the beginning and end of the data packet so the receiving UART knows when to start reading the
bits.
When the receiving UART detects a start bit, it starts to read the incoming bits at a specific
frequency known as the baud rate. Baud rate is a measure of the speed of data transfer, expressed in bits
per second (bps). Both UARTs must operate at about the same baud rate. The baud rate between the
transmitting and receiving UARTs can only differ by about 10% before the timing of bits gets too far off.
Both UARTs must be configured to transmit and receive the same data packet structure.
Page 4 of 65
By Ezrah Buki On LinkedIn
HOW UART WORKS
The UART that is going to transmit data receives the data from a data bus. The data bus is used to
send data to the UART by another device like a CPU, memory, or microcontroller.Data is transferred
from the data bus to the transmitting UART in parallel form. After the transmitting UART gets the parallel
data from the data bus, it adds a start bit, a parity bit, and a stop bit, creating the data packet. Next, the data
packet is output serially, bit by bit at the Tx pin. The receiving UART reads the data packet bit by bit at its
Rx pin. The receiving UART then converts the data back into parallel form and removes the start bit, parity
bit, and stop bits. Finally, the receiving UART transfers the data packet in parallel to the data bus on the
receiving end:
UART transmitted data is organized into packets. Each packet contains 1 start bit, 5 to 9 data bits
(depending on the UART), an optional parity bit, and 1 or 2 stop bits:
START BIT
The UART data transmission line is normally held at a high voltage level when it’s not
transmitting data. To start the transfer of data, the transmitting UART pulls the transmission line from high
to low for one clock cycle. When the receiving UART detects the high to lowvoltage transition, it begins
reading the bits in the data frame at the frequency of the baud rate.
Page 5 of 65
By Ezrah Buki On LinkedIn
DATA FRAME
The data frame contains the actual data being transferred. It can be 5 bits to 9 bits long if a parity
bit is used. If no parity bit is used, the data frame can be 8 bits long. In most cases, the data is sent with the
least significant bit first.
PARITY
Parity describes the evenness or oddness of a number. The parity bit is a way for the receiving
UART to tell if any data has changed during transmission. Bits can be changed by electromagnetic
radiation, mismatched baud rates, or long distance data transfers. After the receiving UART reads the data
frame, it counts the number of bits with a value of 1 and checks if the total is an even or odd number. If the
parity bit is a 0 (even parity), the 1 bits in the data frameshould total to an even number. If the parity bit is
a 1 (odd parity), the 1 bits in the data frame should total to an odd number. When the parity bit matches the
data, the UART knows that the transmission was free of errors. But if the parity bit is a 0, and the total is
odd; or the parity bit is a1, and the total is even, the UART knows that bits in the data frame have changed.
STOP BITS
The Stop Bit, as the name suggests, marks the end of the data packet. It is usually two bits long
but often only on bit is used. In order to end the transmission, the UART maintains the data line at high
voltage (1).
2. The transmitting UART adds the start bit, parity bit, and the stop bit(s) to the data frame:
Page 6 of 65
By Ezrah Buki On LinkedIn
3. The entire packet is sent serially from the transmitting UART to the receiving UART. The
receiving UART samples the data line at the pre-configured baud rate:
4. The receiving UART discards the start bit, parity bit, and stop bit from the data frame:
5. The receiving UART converts the serial data back into parallel and transfers it to the data buson the
receiving end:
Page 7 of 65
By Ezrah Buki On LinkedIn
ADVANTAGES AND DISADVANTAGES OF UARTS
No communication protocol is perfect, but UARTs are pretty good at what they do. Here aresome pros
and cons to help you decide whether or not they fit the needs of your project:
ADVANTAGES
Only uses two wires
No clock signal is necessary
Has a parity bit to allow for error checking
The structure of the data packet can be changed as long as both sides are set up for it
Well documented and widely used method
DISADVANTAGES
The size of the data frame is limited to a maximum of 9 bits
Doesn’t support multiple slave or multiple master systems
The baud rates of each UART must be within 10% of each other
UART is one of the most simple and most commonly used Serial Communication techniques.
Today, UART is being used in many applications like GPS Receivers, Bluetooth Modules, GSM and
GPRS Modems, Wireless Communication Systems, RFID based applicationsetc.
Page 8 of 65
By Ezrah Buki On LinkedIn
MOSI (Master Output/Slave Input) – Line for the master to send data to the slave.
MISO (Master Input/Slave Output) – Line for the slave to send data to the master
SCLK (Clock) – Line for the clock signal.
SS/CS (Slave Select/Chip Select) – Line for the master to select which slave to send data to.
*In practice, the number of slaves is limited by the load capacitance of the system, which reduces the ability of
the master to accurately switch between voltage levels.
SLAVE SELECT
The master can choose which slave it wants to talk to by setting the slave’s CS/SS line to a low
voltage level. In the idle, non-transmitting state, the slave select line is kept at a high voltage level.
Multiple CS/SS pins may be available on the master, which allows for multiple slaves to be wired in
parallel. If only one CS/SS pin is present, multiple slaves can be wired tothe master by daisy-chaining.
MULTIPLE SLAVES
SPI can be set up to operate with a single master and a single slave, and it can be set up with
multiple slaves controlled by a single master. There are two ways to connect multiple slaves to the master.
If the master has multiple slave select pins, the slaves can be wired in parallel like this:
Page 9 of 65
By Ezrah Buki On LinkedIn
If only one slave select pin is available, the slaves can be daisy-chained like this:
Page 10 of 65
By Ezrah Buki On LinkedIn
STEPS OF SPI DATA TRANSMISSION
1. The master outputs the clock signal:
2. The master switches the SS/CS pin to a low voltage state, which activates the slave:
3. The master sends the data one bit at a time to the slave along the MOSI line. The slave readsthe bits as
they are received:
4. If a response is needed, the slave returns data one bit at a time to the master along the MISOline. The
master reads the bits as they are received:
Page 11 of 65
By Ezrah Buki On LinkedIn
ADVANTAGES
No start and stop bits, so the data can be streamed continuously without interruption
No complicated slave addressing system like I2C
Higher data transfer rate than I2C (almost twice as fast)
Separate MISO and MOSI lines, so data can be sent and received at the same time
DISADVANTAGES
Uses four wires (I2C and UARTs use two)
No acknowledgement that the data has been successfully received (I2C has this)
No form of error checking like the parity bit in UART
Only allows for a single master
Page 12 of 65
By Ezrah Buki On LinkedIn
I2C COMMUNICATION PROTOCOL
Inter IC (i2c) (IIC) is important serial communication protocol in modern electronic systems.
Philips invented this protocol in 1986. The objective of reducing the cost of production of television
remote control motivated Philips to invent this protocol. IIC is a serial bus interface, can be implemented
in software, but most of the microcontrollers support IIC by incorporating it as hard IP (Intellectual
Property). IIC can be used to interface microcontroller with RTC, EEPROM and different variety of
sensors. IIC is used to interface chips on motherboard, generally between a processor chip and any
peripheral which supports IIC. IIC is very reliable wireline communication protocol for an on board or
short distances. I2C is a serial protocol for two-wire interface to connect low-speed devices like
microcontrollers, EEPROMs, A/D and D/A converters, I/O interfaces and other similar peripherals in
embedded systems
I2C combines the best features of SPI and UARTs. With I2C, you can connect multiple slaves to a
single master (like SPI) and you can have multiple masters controlling single, or multiple slaves. This is
really useful when you want to have more than one microcontroller logging data to a single memory card
or displaying text to a single LCD.
IIC protocol uses two wires for data transfer between devices: Serial Data Line (SDA) and Serial
Clock Line (SCL). The reduction in number of pins in comparison with parallel data transfer is evident.
This reduces the cost of production, package size and power consumption. IIC is also best suited protocol
for battery operated devices. IIC is also referred as two wire serial interface (TWI).
SDA (Serial Data) – The line for the master and slave to send and receive data.
SCL (Serial Clock) – The line that carries the clock signal.
I2C is a serial communication protocol, so data is transferred bit by bit along a single wire (the
SDA line).
Page 13 of 65
By Ezrah Buki On LinkedIn
Like SPI, I2C is synchronous, so the output of bits is synchronized to the sampling of bits by a
clock signal shared between the master and the slave. The clock signal is always controlled by the master.
Page 14 of 65
By Ezrah Buki On LinkedIn
Start Condition: The SDA line switches from a high voltage level to a low voltage level before the SCL
line switches from high to low.
Stop Condition: The SDA line switches from a low voltage level to a high voltage level after the SCL line
switches from low to high.
Address Frame: A 7 or 10 bit sequence unique to each slave that identifies the slave when the master
wants to talk to it.
Read/Write Bit: A single bit specifying whether the master is sending data to the slave (low voltage level)
or requesting data from it (high voltage level).
ACK/NACK Bit: Each frame in a message is followed by an acknowledge/no-acknowledge bit. If an
address frame or data frame was successfully received, an ACK bit is returned to the sender from the
receiving device.
ADDRESSING
I2C doesn’t have slave select lines like SPI, so it needs another way to let the slave knowthat data
is being sent to it, and not another slave. It does this by addressing. The address frame is always the first
frame after the start bit in a new message.
The master sends the address of the slave it wants to communicate with to every slave connected
to it. Each slave then compares the address sent from the master to its own address.If the address matches,
it sends a low voltage ACK bit back to the master. If the address doesn’t match, the slave does nothing and
the SDA line remains high.
READ/WRITE BIT
The address frame includes a single bit at the end that informs the slave whether the master wants
to write data to it or receive data from it. If the master wants to send data to the slave, the read/write bit is a
low voltage level. If the master is requesting data from the slave, the bit is a high voltage level.
Page 15 of 65
By Ezrah Buki On LinkedIn
The data frame is always 8 bits long, and sent with the most significant bit first. Each dataframe is
immediately followed by an ACK/NACK bit to verify that the frame has been received successfully. The
ACK bit must be received by either the master or the slave (depending on who is sending the data) before
the next data frame can be sent.
After all of the data frames have been sent, the master can send a stop condition to the slave to halt
the transmission. The stop condition is a voltage transition from low to high on the SDA line after a low to
high transition on the SCL line, with the SCL line remaining high.
2. The master sends each slave the 7 or 10 bit address of the slave it wants to communicatewith, along
with the read/write bit:
Page 16 of 65
By Ezrah Buki On LinkedIn
3. Each slave compares the address sent from the master to its own address. If the address matches, the
slave returns an ACK bit by pulling the SDA line low for one bit. If the address from the master does not
match the slave’s own address, the slave leaves the SDA line high.
Page 17 of 65
By Ezrah Buki On LinkedIn
5. After each data frame has been transferred, the receiving device returns another ACK bit tothe
sender to acknowledge successful receipt of the frame:
6. To stop the data transmission, the master sends a stop condition to the slave byswitching SCL
high before switching SDA high:
Page 18 of 65
By Ezrah Buki On LinkedIn
MULTIPLE MASTERS WITH MULTIPLE SLAVES
Multiple masters can be connected to a single slave or multiple slaves. The problem with multiple
masters in the same system comes when two masters try to send or receive data at the same time over the
SDA line. To solve this problem, each master needs to detect if the SDA line is low or high before
transmitting a message. If the SDA line is low, this means that another master has control of the bus, and
the master should wait to send the message. If the SDA line is high, then it’s safe to transmit the message.
To connect multiple masters to multiple slaves, use the following diagram, with 4.7K Ohm pull-up
resistors connecting the SDA and SCL lines to Vcc:
ADVANTAGES
Only uses two wires
Supports multiple masters and multiple slaves
ACK/NACK bit gives confirmation that each frame is transferred successfully
Hardware is less complicated than with UARTs
Well known and widely used protocol
Page 19 of 65
By Ezrah Buki On LinkedIn
DISADVANTAGES
Slower data transfer rate than SPI
The size of the data frame is limited to 8 bits
More complicated hardware needed to implement than SPI
The major goal of USB was to define an external expansion bus to add peripherals to a PC in easy
and simple manner.
USB offers users simple connectivity. It eliminates the mix of different connectors for different
devices like printers, keyboards, mice, and other peripherals. That means USB-bus allows many
peripherals to be connected using a single standardized interface socket. It supports all kinds of data, from
slow mouse inputs to digitized audio and compressed video.
USB also allows hot swapping. The "hot-swapping" means that the devices can be plugged and
unplugged without rebooting the computer or turning off the device. That means, when plugged in,
everything configures automatically. Once the user is finished, they can simply unplug the cable out; the
host will detect its absence and automatically unload the driver. This makes the USB a plug-and-play
interface between a computer and add-on devices.
USB is now the most used interface to connect devices like mouse, keyboards, PDAs, game-pads
and joysticks, scanners, digital cameras, printers, personal media players, and flash drives to personal
computers.
USB sends data in serial mode i.e. the parallel data is serialized before sends and de- serialized
after receiving.
The benefits of USB are low cost, expandability, auto-configuration, hot-plugging and outstanding
performance. It also provides power to the bus, enabling many peripherals to operate without the added
need for an AC power adapter.
USB1.0: USB 1.0 is the original release of USB having the capability of transferring 12Mbps,
supporting up to 127 devices. This USB 1.0 specification model was introduced in January 1996.
USB1.1: USB 1.1 came out in September 1998. USB 1.1 is also known as full-speed USB. This
version is similar to the original release of USB; however, there are minor modifications for the hardware
and the specifications. USB version 1.1 supported two speeds, a full speed mode of 12Mbits/s and a low
speed mode of 1.5Mbits/s.
Page 20 of 65
By Ezrah Buki On LinkedIn
USB2.0: Hewlett-Packard, Intel, LSI Corporation, Microsoft, NEC, and Philips jointly led the
initiative to develop a higher data transfer rate than the 1.1 specifications. The USB 2.0 specification was
released in April 2000 and was standardized at the end of 2001.
Supporting three speed modes (1.5, 12 and 480 Mbps), USB 2.0 supports low-bandwidth devices
such as keyboards and mice, as well as high-bandwidth ones like high-resolution Web- cams, scanners,
printers and high-capacity storage systems.
USB 2.0, also known as hi-speed USB. This hi-speed USB is capable of supporting a transfer rate
of up to 480 Mbps, compared to 12 Mbps of USB 1.1. That's about 40 times as fast! Wow!
USB3.0: USB 3.0 is the latest version of USB release. It is also called as Super-Speed USB
having a data transfer rate of 4.8Gbps (600 MB/s). That means it can deliver over 10x the speed of today's
Hi-Speed USB connections.
The USB 3.0 specification was released by Intel and its partners in August 2008.
Products using the 3.0 specifications are come out in 2010.
The USB "tiered star" topology:
The USB system is made up of a host, multiple numbers of USB ports, and multiple peripheral
devices connected in a tiered-star topology.
The host is the USB system's master, and as such, controls and schedules all communications
activities. Peripherals, the devices controlled by USB, are slaves responding to commands from the host.
USB devices are linked in series through hubs. There always exists one hub known as the root hub, which
is built in to the host controller.
Page 21 of 65
By Ezrah Buki On LinkedIn
USB connectors:
Connecting a USB device to a computer is very simple -- you find the USB connector on the back
of your machine and plug the USB connector into it. If it is a new device, the operating system auto-detects
it and asks for the driver disk. If the device has already been installed, the computer activates it and starts
talking to it.
Page 22 of 65
By Ezrah Buki On LinkedIn
All USB data is sent serially. USB data transfer is essentially in the form of packets of data, sent
back and forth between the host and peripheral devices. Initially all packets are sent from the host, via the
root hub and possibly more hubs, to devices.
Each USB data transfer consists of a…
1. Token packet (Header defining what it expects to follow)
2. Optional Data Packet (Containing the payload)
3. Status Packet (Used to acknowledge transactions and to provide a means of errorcorrection).
Page 23 of 65
By Ezrah Buki On LinkedIn
UART Register Map
TI Tiva TM4C123GH6PM UART has got several Special Function Registers (SFR‟s)
which needs to program with appropriate values to achieve required UART functionality. In
this section, UART0 is taken as example in which virtual connection is possible on TI Tiva
launch pad.
Page 24 of 65
By Ezrah Buki On LinkedIn
Where the SysClk is the working system clock connected to the UART and ClkDiv is
the value programmed into baud rate registers.
The baud-rate divisor (BRD) has the following relationship to the system clock,
where BRDI is the integer part of the BRD and BRDF is the fractional part, separated by a
decimal place.
TI Tiva Launchpad system clock is 16 MHz so desired Baud Rate can be calculated as:
Example:
System clock of TI Tiva Launchpad is16 MHz 16MHz is divided by 16 and it is fed
into UART. So UART operates at 1MHz frequency. So ClkDiv = 1MHz.
To generate a baud rate of 4800: 1MHz/4800 = 208.33
(a) 1MHz/4800 = 208.33, UARTIBRD=208 & UARTFBRD = (0.33×64) + 0.5 = 21.83 =21
(b) 1MHz/9600 = 104.166666, UARTIBRD = 104 & UARTFBRD = (0.16666×64) +0.5=11
(c) 1MHz/57600 = 17.361, UARTIBRD = 17 and UARTFBRD = (0.361 × 64) + 0.5 =23
(d) 1MHz/115200 = 8.680, UARTIBRD = 8 and UARTFBRD = (0.680 × 64) +0.5=44
Serial IR (SIR):
UART includes an IrDA (Infrared) serial IR encoder-decoder block. SIR block
converts the data between UART and half-duplex serial SIR interface. The SIR block
provides a digitally encoded output and decoded input to UART. SIR block uses UnTx and
UnRx pins for SIR interface. These pins are connected to IrDA SIR physical layer link. SIR
block supports half-duplex communication. The IrDA SIR physical layer specifies a
minimum 10-ms delay between transmission and reception. The SIR block has two modes of
operation normal mode and low power mode.
ISO 7816 Support: UART support ISO 7816 smartcard communication. The UnTx signal is
used as a bit clock and the UnRx signal is used as the half-duplex communication line
connected to the smartcard. Any GPIO signal can be used to generate the reset signal to the
smartcard.
Page 25 of 65
By Ezrah Buki On LinkedIn
UART Control Register (UARTCTL):
This is a 32-bit register. The most important bits are RXE, TXE, HSE, and UARTEN.
Page 26 of 65
By Ezrah Buki On LinkedIn
STP2 (Stop bit2): The stop bits can be 1 or 2. The default is 1 stop bit at the end of
each frame. If the receiving device is slow, we can use 2 stop bits by making the
STP2=1.
FEN (FIFO Enable): UART has an internal 16-byte FIFO (first in first out) buffer to
store data for transmission to keep the CPU getting interrupted for the reception and
transmission of every byte. Enabling FEN bit, we can write up to16 bytes of data
block into its transmission FIFO buffer and let transfer happen one byte at a time.
There is also a separate 16 byte FIFO for the receiver to buffer the incoming data.
Upon Reset, the default for FIFO buffer size is 1 byte.
WLEN (Word Length): The number of bits per character data in each frame can be 5,
6, 7, or 8. we use 8 bits for each character data frame. Default world length mode is 5.
BRK (Send Break): A Low level is continually output on the UnTx signal, after
completing transmission of the current character. For the proper execution of the
break command, software must set this bit for at least two frames (character periods).
PEN (Parity Enable): Parity is enabled and parity bit is added to the data frame by
making PEN = 1. Parity checking is also enabled.
EPS (Even Parity Select): Odd parity is performed, which checks for an odd number
of 1s when EPS = 0. Even parity generation and checking is performed during
transmission and reception, which checks for an even number of 1s in data and parity
bits when EPS = 1.
UART Data Register (UARTDR):
Data should be placed in data register before transmission. Only lower 8 bits are used.
In a similar way, the received byte should be read and saved in memory before it gets
overwrite by next byte. During reception, we use other four bits (8, 9, 10 and 11) to detect
error, parity etc. Another set of registers are used to check the source of error.
(UARTRSR/UARTRCR)
Page 27 of 65
By Ezrah Buki On LinkedIn
UART Flag Register (UARTFR):
The UART Flag Register holds one byte of data when FIFO buffer is disabled.
TXFE (TX FIFO Empty): Transmitter loads one byte for transmission from the FIFO
buffer.
When FIFO becomes empty, the TXFE is raised. The transmitter then frames the byte
and sends it out via TxD pin bit by bit serially.
RXFF (RX FIFO Full): When a byte of data is received, byte is placed in Data
register and RXFF (RX FIFO full) flag bit is raised after receiving the complete byte.
TXFF (TX FIFOI Full): When the transmitter is not busy, it loads one byte from the
FIFO buffer and the FIFO is not full anymore and the TXFF is lowered. We can
monitor TXFF flag and upon going LOW we can write another byte to the Data
register.
UART Transmission
Step to perform UART Transmission:
Page 28 of 65
By Ezrah Buki On LinkedIn
Program the integer part and fractional part into baud rate registers: UARTIBRD and
UARTFBRD for UART0.
Program UARTCC to select the system clock as UART clock.
Set the bits in UARTLCRH register for 1 stop bit, no interrupt, no FIFO use, and for 8
-bit data size (for UART 0).
Program TxE and RxE in UARTCTL to enable transmitter and receiver.
Make PA0 and PA1 pins to use as digital pins.
Configure PA0 and PA1 pins for UART.
Loop the program for wait on TxD output. Monitor the TXFF flag bit and when it
goes low, write a data into data register.
Monitor the RXFE flag bit in UART Flag register and when it goes LOW read the
received byte from Data register and save before it gets overwrite.
Basic UART programing
Example 1:
Program to send the characters "HELLO" to HyperTerminal of PC
#include <stdint.h>
#include "tm4c123gh6pm.h"
void UART0Tx(char c);
void delayMs(int n);
int main(void)
SYSCTL->RCGCUART |= 1; /* enable clock supply to UART*/
SYSCTL->RCGCGPIO |= 1; /* enable clock supply to PORTA */
/* UART0 initialization */
UART0->CTL = 0; /* disable UART0 */
UART0->IBRD = 104; /* 9600 baud rate
UART0->FBRD = 11; /* fractional portion*/
UART0->CC = 0; /* configured to system clock */ UART0-
>LCRH = 0x60; /* 8-bit, no parity, 1-stop bit, no FIFO */UART0-
>CTL = 0x301; /* configure UART0 and TXE, RXE*/
/* UART0 TX0 and RX0 use PA0 and PA1. Set them up. */
GPIOA->DEN = 0x03; /* Make PA0 and PA1 as digital */
GPIOA->AFSEL = 0x03; /* Use PA0, PA1 alternate function */
GPIOA->PCTL = 0x11; /* configure PA0 and PA1 for UART */
delayMs(1); /* wait for output line to stabilize */
for(;;)
{
UART0Tx('H');
UART0Tx('E');
UART0Tx('L');
UART0Tx('L ');
UART0Tx('O');
}
}
/* UART0 Transmit */
void UART0Tx(char c)
{while((UART0->FR & 0x20) != 0); /* wait until Tx buffer not full */
UART0->DR = c; /* before giving it another byte */
}
Page 29 of 65
By Ezrah Buki On LinkedIn
Example 2:
Program to receive data serially via UART0
#include <stdint.h>
#include "tm4c123gh6pm.h"
char UART0Rx(void);
void delayMs(int n);
int main(void)
{
char c;
SYSCTL->RCGCUART |= 1; /* enable clock supply to UART*/
SYSCTL->RCGCGPIO |= 1; /* enable clock supply to PORTA */
/* UART0 initialization */
UART0->CTL = 0; /* disable UART0 */
UART0->IBRD = 104; /* 9600 baud rate */
UART0->FBRD = 11; /* fractional portion*/
UART0->CC = 0; /* configured to system clock */ UART0-
>LCRH = 0x60; /* 8-bit, no parity, 1-stop bit, no FIFO */
UART0->CTL = 0x301; /* configure UART0 and TXE, RXE */
/* UART0 TX0 and RX0 use PA0 and PA1. Set them up. */ GPIOA-
>DEN = 0x03; /* Make PA0 and PA1 as digital */
GPIOA->AFSEL = 0x03; /* Use PA0, PA1 alternate function */
GPIOA->PCTL = 0x11; /* configure PA0 and PA1 for UART */
for(;;)
{
c = UART0Rx(); /* get a character from UART */
}
}
/* UART0 Receive */
char UART0Rx(void)
{
char c;
while((UART0->FR & 0x10) != 0); /* wait until the buffer is not empty */ c
= UART0->DR; /* read the received data */
return c; /* and return it */
}
Page 30 of 65
By Ezrah Buki On LinkedIn
Four transmission speeds:
o Standard (100 Kbps)
o Fast-mode (400 Kbps)
o Fast-mode plus (1 Mbps)
o High-speed mode (3.33 Mbps)
Clock low timeout interrupt
Dual slave address capability
Glitch suppression
Master and slave interrupt generation
Master generates interrupts when a transmit or receive operation completes (or aborts
due to an error)
Slave generates interrupts when data has been transferred or requested by a master or
when a START or STOP condition is detected
Master with arbitration and clock synchronization, multi-master support, and 7-bit
addressing mode.
I2C Network:
There are four on chip IIC modules in this Tiva microcontroller. The base address of
each IIC module is shown in below table:
Clock should be enabled to IIC module and system control register (SYSCTL) RCGCI2C
needs to be programmed.
Page 31 of 65
By Ezrah Buki On LinkedIn
To enable the clock SYSCTL ->RCGCI2C | = 0x0F will enable clock to all four modules.
Clock Speed: I2CMTPR (I2C Master Timer Period) register is programmed to set the clock
frequency for SCL.
Page 32 of 65
By Ezrah Buki On LinkedIn
The HS bit in the I2CMTPR register needs to be set for the TPR value to be used in High-
Speed mode.
Table: TPR Values for High-Speed Mode
Slave Address:
In a master device, the slave address is stored in I2CMSA. Addresses in I2C
communication is 7-bits. I2CMSA stores D7 to D1 bits and LSB of D0 indicate master is
receiver of transmitter.
Data Register:
In transmit mode, a byte of data will be placed in I2CMDR (I2C Master Data
Register) for transmission.
Page 33 of 65
By Ezrah Buki On LinkedIn
Control and Status Flag Register:
The I2CMCS (I2C Master Control/Status) register is programmed for both control
and status. I2CMCS register configures the I2C controller operation. The status whether a
byte has been transmitted. That is, transmission buffer is empty and ready to transmit the next
byte. After writing a data into I2C Data register and the slave address into I2C Master Slave
address register, we can configure I2CMCS register for the I2C to start a data transmission
from Master to slave device. Writing 0x07 to I2CMCS register has all the three of STOP = 1,
RUN = 1, and START = 1 in it. To check the status of transmission, we poll the BUSBSY bit
of I2CMCS register. BUSBSY bit goes low after transmission complete. Program should also
check the ERROR bit to confirm that no error has occurred during transmission. For any error
in transmission, detected by transmitter or raised by slave, the ADRACK and DATACK will
be set. The bit ARBLST should be polled, to confirm transmitter has got access to bus and
not lost arbitration.
Page 34 of 65
By Ezrah Buki On LinkedIn
Configuring GPIO for I2C Network:
GPIO pins are configured for I2C as follows:
Enable the clock to GPIO pins by using system control register RCGCGPIO.
Set the GPIO AFSEL (GPIO alternate function) for I2C pins.
Enable digital pins in the GPIODEN register.
I2C signals are assigned to specific pins using GPIOCTL register.
(a) (b)
Figure: Data transmission using (a) Master Single Transmit, (b) Single Master Receive
Page 35 of 65
By Ezrah Buki On LinkedIn
Implementing and Programming SPI:
Serial peripheral interface (SPI) is a serial communication interface originally
designed by Motorola in late eighties. SPI and I2C came into existence almost at the same
time. Most of the modern day microcontrollers will support SPI protocol. Both SPI and I2C
offer good support for communication with low-speed devices, but SPI is better suited to
applications in which devices transfer data streams. Some devices use the full-duplex mode to
implement an efficient, swift data stream for applications such as digital audio, digital signal
processing, or telecommunications channels, but most off-the-shelf chips stick to half-duplex
request/response protocols.
SPI is used to talk to a variety of peripherals, such a
Sensors: temperature, pressure, ADC, touchscreens, video game controllers
Control devices: audio codecs, digital potentiometers, DAC
Camera lenses: Canon EF lens mount
Memory: flash and EEPROM
Real-time clocks
LCD, sometimes even for managing image data
Any MMC or SD card
Description: SPI is a synchronous serial communication protocol like I2C, where master
generates clock and data transfer between master and slave happens with respect to clock.
Both master and slave devices will have shift registers connected to input (MISO for master
and MOSI for slave) and output (MOSI for master and MISO for slave) as shown in figure.
Page 36 of 65
By Ezrah Buki On LinkedIn
CPHA=0 means sample data on the leading (first) clock edge, while CPHA=1 means
sample data on the trailing (second) clock edge. The idle value of the clock is zero the leading
clock edge is a positive edge but if the idle value of the clock is one, the leading clock edge is
a negative edge.
In SPI protocol both master and slaves use the same clock for communication When
CPOL= 0 the idle value of the clock is zero while at CPOL=1 the idle value of the clock is
one.
CPHA=0 means sample data on the leading (first) clock edge, while CPHA=1 means
sample data on the trailing (second) clock edge. The idle value of the clock is zero the leading
clock edge is a positive edge but if the idle value of the clock is one, the leading clock edge is
a negative edge.
Page 37 of 65
By Ezrah Buki On LinkedIn
Separate transmit and receive FIFOs, each 16 bits wide and 8 locations deep
Programmable data frame size from 4 to 16 bits
Internal loopback test mode for diagnostic/debug testing
Standard FIFO-based interrupts and End-of-Transmission interrupt
Efficient transfers using Micro Direct Memory Access Controller (μDMA)
Separate channels for transmit and receive
Receive single request asserted when data is in the FIFO; burst request asserted when
FIFO contains 4 entries
Transmit single request asserted when there is space in the FIFO; burst request
asserted
When four or more entries are available to be written in the FIFO.
Most SSI signals are alternate functions for some GPIO signals and default to be
GPIO signals at reset. The exceptions to this rule are the SSI0Clk, SSI0Fss, SSI0Rx, and
SSI0Tx pins, which default to the SSI function. The AFSEL bit in the GPIO Alternate
Function Select (GPIOAFSEL) register should be set to choose the SSI function.
Each data frame is between 4 and 16 bits long depending on the size of data
programmed and is transmitted starting with the MSB. There are three basic frame types that
can be selected by programming the FRF bit in the SSICR0 register:
Texas Instruments synchronous serial
Freescale SPI
Microwire
For all three formats, the serial clock (SSInClk) is held inactive while the SSI is idle,
and SSInClk transitions at the programmed frequency only during active transmission or
reception of data. The idle state of SSInClk is utilized to provide a receive timeout indication
that occurs when the receive FIFO still contains data after a timeout period.
For Freescale SPI and MICROWIRE frame formats, the serial frame (SSInFss) pin is
active Low, and is asserted (pulled down) during the entire transmission of the frame.
We focus on the SPI features of SSI module. This microcontroller supports four SSI
modules. The SSI modules are located at the following base addresses:
Table: SPI Modules base address
Clock to SSI: RCGCSSI register is used to enable the clock to SSI modules. We need
to write RCGSSI = 0x0F to enable the clock to all SSI modules.
Figure: Synchronous Serial Interface Run Mode Clock Gating Control CRCG (SSI) Register
Page 38 of 65
By Ezrah Buki On LinkedIn
Configuring the SSI:
SSICR0 (SSI control register 0) is used to configure the SSI. The generic SPI is used
to transfer the byte size of data, the SSI in Tiva microcontroller allows transfer of data
between 4 bits to 16bits.
Bit Rate:
SSI module clock source can be either from System Clock or PIOSC (Precision
Internal Oscillator). The selected frequency is fed to pre-scaler before it is used by the Bit
Rate circuitry. The CPSDVSR (CPS Divisor) value comes from the pre-scaler divisor
register. The lower 8 bits of SSICPSR (SSI Clock Prescale) register are used to divide the
CPU clock before it is fed to the Bit Rate circuitry. Only even values can be used for the pre-
scaler since the D0 must be 0. For the pre-scaler register, the lowest value is 2 and the highest
is 254.
The SSICR0 (SSI Control register 0) allows the Bit Rate selection among other
things. The output of clock pre-scaler circuitry is divided by 1 + SCR and then used as the
SSI baud rate clock. The value of SCR can be from 0 to 255. The below formula is used to
calculate the bit rate.
Bit Rate (BR): BR=SysClk/(CPSDVSR × (1 + SCR))
Page 39 of 65
By Ezrah Buki On LinkedIn
Example:
For a Bit Rate=50 KHz and SCR=03 in SSICR0 register.
The pre-scaler register value for a given system clock frequency of 16MHz, the BR
can be calculated using above formula as:
BR = SysClk / (CPSDVSR × (1 + SCR))
50 KHz = 16 MHz / (X × (1 + 3).
The pre-scaler value is 0x50 in Hex.
SPI module can act like slave or a master. The value in a MS bit in SSI control
register 1 (SSICR1) decide the microcontroller as master or slave. SSE bit in the SSICR1
register is used to enable/ disable the SPI.
Page 40 of 65
By Ezrah Buki On LinkedIn
SPI data Transmission:
To perform SPI data transmission, follow the steps given below:
Enable the clock to SPI module in system control register RCGCSSI.
Before initialization, disable the SSI via bit 1 of SSICR1 register.
Set the Bit Rate with the SSICPSR prescaler and SSICR0 control registers.
Select the SPI mode, phase, polarity, and data width in SSICR0 control register.
Set the master mode in SSISCR1 register.
Enable SSI using SSICR1 register.
Assert slave select signal.
Wait until the TNF flag in SSISR goes high, then load a byte of data into SSIDR.
Wait until transmit is complete that is, transmit FIFO empty and SSI not busy.
De-assert the slave signal
NVIC interrupt for SSI:
Interrupt handler can be used for transmission and reception of data. By enabling the
interrupt in SSIIM (SSI Interrupt mask) register, NVIC interrupt controller will enable
interrupts from SSI and execute the corresponding interrupt service routine. All SSI interrupts
are masked upon reset.
Page 41 of 65
By Ezrah Buki On LinkedIn
void SSI1Write(unsigned char data)
{
GPIOF->DATA &= ~0x04; /* assert SS low */ while((SSI1-
>SR & 2) == 0); /* wait until FIFO not full */ while(SSI1->SR &
0x10); /* wait until transmit complete */ GPIOF->DATA |= 0x04;
/* keep SS idle high */
void init_SSI1(void)
{
SYSCTL->RCGCSSI |= 2; /* enable clock to SSI1 */
/* configure PORTD 3, 1 for SSI1 clock and Tx */
GPIOD->DEN |= 0x09; /* and make them digital */
GPIOD->AFSEL |= 0x09; /* enable alternate function */
GPIOD->PCTL &= ~0x0000F00F; /* assign pins to SSI1 */
GPIOD->PCTL |= 0x00002002; /* assign pins to SSI1 */
/* configure PORTF 2 for slave select */
GPIOF->DEN |= 0x04; /* make the pin digital */
GPIOF->DIR |= 0x04; /* make the pin output */
GPIOF->DATA |= 0x04; /* keep SS idle high */
/* SPI Master, POL = 0, PHA = 0, clock = 4 MHz, 16 bit data */
SSI1->CR1 = 0; /* disable SSI and make it master */
SSI1->CC = 0; /* use system clock */
SSI1->CPSR = 2; /* prescaler divided by 2 */
SSI1->CR1 |= 2; /* enable SSI1 */
}
void SystemInit(void)
{
SCB->CPACR |= 0x00f00000;
}
Case Study: Tiva based embedded system application using the interface protocols for
communication with external devices “Sensor Hub BoosterPack”
Page 42 of 65
By Ezrah Buki On LinkedIn
Weather broadcasting system require some smart technique to monitor the weather
conditions of different places. It is useful for the meteorological department for the detection
of the environmental condition with the help of a balloon. In this case study we are using four
sensors Accelerometer, gyroscope, temperature sensor and pressure sensor. The Tiva booster
pack with various sensors is mounted on the balloon and accelerometer used for the detection
of acceleration of the balloon and gyro scope is used for the position detection of the balloon
and pressure and temperature sensor senses pressure and temperature of the environment
respectively. These all gathered information sent to the ground station with the help of
satellite communication system installed at the balloon and the meteorological department‟s
ground station. The collected information is used for the public weather broadcasting.
Figure: Flowchart for Interfacing TIVA with Sensor Hub Booster Pack
Page 43 of 65
By Ezrah Buki On LinkedIn
Embedded Networking Fundamentals:
Introduction:
Embedded networking technologies such as ZigBee, NFC, Bluetooth, Wi-Fi etc. are
key elements in designing internet enabled applications. For example, in a residential set-up,
these enable control of all devices remotely, even if there is no one physically present in the
house. Such a „Smart home’ allows the owner to monitor and control all smart equipment
including power controls, security devices such as surveillance camera, etc. remotely. That is
possible by using Wi-Fi technology, gateway solutions that provide connection to Cloud and
of course the Internet to access the devices. Other typical application areas are monitoring,
smart Grid, Smart Transport, smart plug, wearable devices, health monitoring etc.
Page 44 of 65
By Ezrah Buki On LinkedIn
Microcontrollers are used to design intelligent embedded systems such as
smartphones, netbooks, digital TVs, mp3 players, smart-watches, smart-sensors, etc. These
smart things can be connected together to form an embedded network that imparts
intelligence to bigger things like homes, buildings, fields, forests and cities. The above figure
shows different sensors and systems involved in a typical smart-home application. An
embedded network of smart things like automatic home appliances, lights, door sensors,
CCTV cameras, refrigerators, etc. can provide smart-home users with more convenient and
high-quality living experience.
Page 45 of 65
By Ezrah Buki On LinkedIn
In the smart home application shown in the below figure TCP/IP protocol can be used
over Ethernet to provide Internet connectivity to the outside world. As shown in figure, this
will enable the user to monitor or control the smart home functions from anywhere in the
world using a PC, laptop or a smartphone.
Page 46 of 65
By Ezrah Buki On LinkedIn
Multi-Stakeholder Support: IPv6 provides for end devices to have multiple addresses
and an even more distributed routing mechanism than the IPv4 Internet. This allows
different stakeholders to assign IoT end-device addresses that are consistent with their
own application and network practices. Thus multiple stakeholders can deploy their
own applications, sharing a common sensor/actuation infrastructure, without
impacting the technical operation or governance of the Internet.
Internet of Things (IOT):
Klevin Ashton introduced the term “Internet of Things” (IOT), to the world of
technology in 1999. Since then, IoT has generated a lot of interest, and it is expected that the
number of „things‟ connected to IoT will grow from 20 billion things in 2015 to an estimated
200 billion by 2020. It refers to a scenario in which all the real-life things (including objects,
people and animals) are connected to internet, and can transfer data over it preferably to a
cloud. This data can then be used by businesses and the people, to create a world of new
possibilities and to benefit from it. Fig. 5.7 shows the three main components of IoT i.e.
things, data (cloud) and the people. For e.g. a smart refrigerator can sense the quantity of
items inside it, and then automatically generate a shopping list to be ordered on-line. This list
is put by the smart refrigerator on the cloud, where the best deals are offered for online
purchase.
Page 47 of 65
By Ezrah Buki On LinkedIn
IOT is considered as a scenario of accessing any information from anywhere and
accessible to everyone. This is described as follows:
Anything: Eventually, any device, appliance or entity will be seamlessly connected to the
Internet. Connectivity will not be the main feature of the device, but will extend the device’s
capabilities.
Anywhere: Any conceived wireless connectivity framework should be abstract enough to
run from any location – both geographically and from a network topology perspective. The
former refers to Internet-based ubiquity; the latter, refers to the ability to clone the framework
into intranet environments where Internet access is limited or undesired. Acknowledging the
structure of the Internet beyond the public domain is important to enable the expansion of the
IoT paradigm.
Anyone: Currently, not all things are connected to the IoT. But an IoT ecosystem that is easy
to use and secure is not that far away. This will make the IoT accessible to anyone. Anyone
will be able to connect their product to the Internet, and also customize it to their personal
preferences.
Applications of IOT:
With the industry’s broadest IoT-ready portfolio of wired and wireless connectivity
technologies, microcontrollers, processors, sensors and analog signal chain and power
solutions, TI offers cloud ready system solutions. From high-performance home, industrial
and automotive applications to battery-powered wearable and portable electronics or energy-
harvested wireless sensor nodes, TI makes developing applications easier with hardware,
software, tools and support to get anything connected as an IoT device.
In automotive appliances, IoT is mainly used for infotainment purposes such as
connecting between the phones and the speakers of the car, activating the engine through
voice control etc.
The IoT paradigm discussed may be encountered in a wide variety of venues that span
across various activity circles throughout the day using different kinds of devices. In the
personal area network we encounter wearable devices for entertainment and location
tracking. For example, it can be a Bluetooth headset or a GPS tracker. These devices facilitate
the user to help enhance their health and wellness, and to gather information around the user.
At home we are surrounded with an ever-growing number of appliances, multimedia devices
and other consumer gadgets.
Page 48 of 65
By Ezrah Buki On LinkedIn
In home automation systems, IoT applications include monitoring and controlling the
devices inside a home in an intelligent way. They include lighting and temperature control
among the connected appliances for effective use of energy.
While on-the-go, we use private or public transportation vehicles and infrastructure to
improve our mobility time utilization. In industries, sensors might be introduced for
production efficiency, maintenance and failure management. And at a metropolitan level
smart building management systems include smart cities equipped with smart city lights,
residential e-meters, surveillance cameras for traffic control, pipeline leak detection etc.
Healthcare IoT applications include remote monitoring of patients for example heart rate,
blood pressure level etc.
Architecture of IOT:
The IoT players: We need to get a wider view of the IoT playground. To do that, the key
players must first be identified. We classify the players into three clusters: users, things and
services
Users are human participants that use services and their own end equipment’s. They
mostly consume information and may inspire actions through profile settings and
other decision making processes.
Things are physical or virtual endpoints representing either a data source, data sink or
both. They feed or consume information to and from the Internet.
Services are information aggregators and may provide tools for data analysis of
different kinds. In some cases can be used to carry out actions requested by clients,
either users or things.
Page 49 of 65
By Ezrah Buki On LinkedIn
The different devices and environments needed in IoT can be layered as shown in the
figure. The sensors and devices needed in the IoT environment are the bottom layer. The
different types of sensors can be temperature, pressure, moisture etc. The data captured by the
sensors needs to be processed using processors and enabling technologies. The technologies
include RFID detection, motion sensing etc. Some of the technologies that enable these
devices are discussed further in the Wireless Sensor networks section. Examples include
Bluetooth, Wi-Fi etc. The processed data can be stored using cloud infrastructures and thus in
turn provide different IoT services. The different types of IoT services include Home
automation, healthcare services, energy management, emergency services among others.
Page 50 of 65
By Ezrah Buki On LinkedIn
Challenges of IOT:
Preparing the lowest layers of technology for the horizontal nature of the IoT requires
manufacturers to deliver on the most fundamental challenges, including:
Connectivity: There is not one connectivity standard that “wins” over the others. There are a
wide variety of wired and wireless standards as well as proprietary implementations used to
connect the things in the IoT. The challenge is getting the connectivity standards to talk to
one another with one common worldwide data currency.
Power management: More things within the IoT need to be battery powered or use energy
harvesting to be more portable and self-sustaining. Line-powered equipment need to be more
energy efficient. The challenge is making it easy to add power management to these devices
and equipment. Wireless charging incorporates connectivity with charge management.
Complexity: Manufacturers are looking to add connectivity to devices and equipment that
has never been connected before to become part of the IoT. Ease of design and development
is essential to get more things connected especially when typical RF programming is
complex. Additionally, the average consumer needs to be able to set-up and use their devices
without a technical background
Rapid evolution: The IoT is constantly changing and evolving. More devices are being
added everyday and the industry is still in its naissance. The challenge facing the industry is
the unknown; unknown devices, unknown applications, unknown use cases. Given this, there
needs to be flexibility in all facets of development. Processors and microcontrollers that range
from 16–1500 MHz to address the full spectrum of applications from a microcontroller
(MCU) in a small, energy-harvested wireless sensor node to high-performance, multi-core
processors for IoT infrastructure. A wide variety of wired and wireless connectivity
technologies are needed to meet the various needs of the market. Last, a wide selection of
sensors, mixed-signal and power-management technologies are required to provide the user
interface to the IoT and energy-friendly designs.
There are several fundamental features that a “thing” has to encompass to be a good
IoT solution. Among these, the most important features are energy efficiency,
security, data handling and simplicity.
Energy Efficiency: As the number of devices grows, even small amounts of excessive power
are a noticeable waste. When it comes to power, the challenge is to ensure that adding
Internet connectivity does not impose a change to the power supply. In other words, ideally it
should fit within the existing power budget headroom. The TIVA Launchpad, being an ultra-
low power MCU ensures that the IoT application takes minimal power.
Page 51 of 65
By Ezrah Buki On LinkedIn
Security: Security is always a challenge in data networks. This challenge intensifies in the
case of the IoT simply because there are more entry points thereby creating more penetration
points. This increased system vulnerability makes the battle for security inevitable. In an IoT
solution, threats also take a new level of magnitude since it is not just data that is put at risk.
With IoT the damage potential is much higher (e.g., opening a door remotely, taking a
burglar alarm system offline). There will surely be a never-ending fight towards better
security. This provides inbuilt security features to address major security requirements.
Data handling: Massive deployment of endpoints results in higher node density. This
requires demand for higher capacity. Furthermore, large quantities of data that are generated
create a need for accessible storage. In addition, real network latency introduces a challenge
to limited resource systems. The TI wireless modules provide easy interfacing with the TIVA
Launchpad to provide connectivity that suits the need of the IoT application.
Overview of Wireless Sensor Networks and DesignExamples:
Wireless Sensor Networks (WSNs) are networks of tiny, battery powered sensor
nodes with limited onboard processing, storage and radio capabilities. Recent advances in
micro-electro-mechanical systems (MEMS) technology, embedded electronics and wireless
communication have made it possible to develop low-power and low-cost sensor nodes that
are small in size and communicate using wireless medium over short distances. The sensor
units in the nodes can sense any desired parameter (like temperature, pressure humidity,
movement etc.) in an area that is covered by the network. The sensed data is then relayed
through the network to the base station, where information can be generated and acted upon
to serve the purpose for which the network has been deployed.
WSNs are on the verge of being utilized for many challenging real-life applications
like early earthquake warning systems, battlefield surveillance, environment and habitat
Page 52 of 65
By Ezrah Buki On LinkedIn
monitoring, healthcare, smart homes and buildings etc... This involves deploying a large
number of nodes in the area to be sensed by the network. This large-scale deployment often
requires the nodes to possess self-organizing capability to form a network without any human
intervention. A typical cluster-based sensor network topology as shown in Figure consists of
a base station, cluster-head nodes and sensor nodes. The base station is normally connected to
the outside world through internet link or a user terminal.
Page 53 of 65
By Ezrah Buki On LinkedIn
figure. The function performed by each layer in implementing an end-to-end communication
system is described below:
Physical Layer:
This layer specifies the physical medium used to transmit bits between
communicating systems. In wired systems, the physical layer may specify the use of copper
wires or fiber optic cable for wired systems. Similarly for wireless technology like ZigBee,
the physical layer specifications mention the use of 2.4 GHz ISM frequency band as one of
the options for communication.
Data Link Layer:
When two or more nodes try to use the physical media simultaneously for data
transfer, the data packets may collide and, the nodes need to try again for access to the media.
In this case, data link layer acts as a local traffic cop to regulate the medium access by the
nodes of the network. Another important role of the data link layer can be to detect and
correct the errors that may occur when data is transferred on the medium.
Network Layer:
The primary function of network layer is to forward data packets (received from
higher layers) from one point to another over the network. The data packets may travel across
many different networks, guided on the way by gateway and router devices, to their final
destination.
Transport Layer:
This layer provides a reliable end-to-end connection oriented data transfer along with
error and flow control services. Transmission Control Protocol (TCP) is the most common
transport layer protocol used on Internet.
Session Layer:
This layer ensures that the data presented to the application layer is in proper format
and ready to be used. For example, data transmitted in EBCDIC-code by the sender may be
converted at the receiver end by presentation layer to ASCII code format used by the
application layer.
Page 54 of 65
By Ezrah Buki On LinkedIn
Application layer:
The protocols used in this layer define the user interface that finally displays the
information to the user.
Wi-Fi:
Wi-Fi is a wireless local area network (WLAN) technology that allows electronic devices to
network using the 2.4 GHz or 5 GHz ISM radio bands. It is based on the IEEE 802.11 MAC
and physical layer standards for WLAN and is the most pervasive choice for connectivity
with the Internet, especially in the home LAN environment. Wi-Fi supports very fast data
transfer rates, but consumes a lot of power which makes it unviable for low-power
applications. Nevertheless, the embedded networks, wireless sensor network applications and
Internet-of-Things implementations explicitly make use of Wi-Fi as a preferred choice for
connectivity to the Internet.
Adding Wi-Fi capability to the Microcontroller:
To illustrate the use of wireless connectivity in embedded networks, this section discusses the
usage of Wi-Fi technology with a microcontroller. Wi-Fi is very widely used to provide
connectivity between user and embedded systems. For example, a user can interact with
Page 55 of 65
By Ezrah Buki On LinkedIn
utility systems (like AC, Garage door, Coffee machine, etc.) in a smart-home using a
smartphone, provided both (smart-home and smartphone) are connected to the internet.
TI provides low-power and easy-to-use Wi-Fi solutions that include battery-operated
Wi-Fi designs with more than a year of battery life on two AA batteries. TI’s Simple Link
Wi-Fi CC3100 module is a wireless network processor with on-chip Wi-Fi, internet, and
robust security protocols. It can be used to connect any low-cost microcontroller (MCU). A
functional block diagram of CC3100 module is shown in the below figure.
Page 56 of 65
By Ezrah Buki On LinkedIn
Embedded Wi-Fi:
It is important to understand the hardware and software architecture of any device
before using it in a design. Figure 5.17 shows the hardware architecture for SimpleLink Wi-
Fi CC3100 module, that can be used to provide Wi-Fi connectivity to any micro-controller
based system. It consists mainly of two parts:
I. Wi-Fi Network Processor Subsystem
II. Power-management Subsystem
Wi-Fi Network Processor Subsystem:
The Wi-Fi Network Processor subsystem mainly consists of the following:
1) Dedicated ARM MCU – It executes the Wi-Fi and Internet protocols required to
communicate over the Internet using Wi-Fi connectivity.
2) ROM–stores pre-programmed Wi-Fi driver and multiple Internet protocols
3) TCP/IP Stack – supports communication with Figure Hardware Architecture for
CC3100 computer systems on the Internet
4) Crypto Engine – provides fast, and secure Wi-Fi as well as Internet connectivity
5) 802.11 b/g/n Radio, Baseband and Medium Access Control - for wireless
transmission and reception of data
6) SPI/ UART Interface – connects the CC3100 module to the host MCU.
Page 57 of 65
By Ezrah Buki On LinkedIn
Power Management Subsystem:
The power management subsystem of CC3100 module provides the CC3100 module
with an integrated DC-to-DC converter with a wide range of power supply from 2.3 to 3.6 V.
This subsystem enables low-power consumption modes such as hibernate with RTC mode,
which requires approximately 7 μA of current.
Features of Wi-Fi supported by CC3100 chip:
The Wi-Fi network processor sub-system in SimpleLink Wi-Fi CC3100 device
integrates all protocols for Wi-Fi and Internet, greatly minimizing MCU software
requirements. With built-in security protocols, SimpleLink Wi-Fi provides a simple yet
robust security experience. This section discusses the features of Wi-Fi supported by the
CC3100 device. A list of features and the functionality provided by them is given in below
Table.
Table: Wi-Fi features
Page 58 of 65
By Ezrah Buki On LinkedIn
The SimpleLink Host Driver includes a set of six logical and simple API modules:
Device API – Manages hardware-related functionality such as start, stop, set, and get
device configurations.
WLAN API – Manages WLAN, 802.11 protocol-related functionality such as device
mode (station, AP, or P2P), setting provisioning method, adding connection profiles,
and setting connection policy.
Socket API – The most common API set for user applications, and adheres to BSD
socket APIs.
NetApp API – Enables different networking services including the Hypertext
Transfer Protocol (HTTP) server service, DHCP server service, and MDNS
client\server service.
NetCfg API – Configures different networking parameters, such as setting the MAC
address, acquiring the IP address by DHCP, and setting the static IP address.
File System API – Provides access to the serial flash component for read and write
operations of networking or user proprietary data.
Building IoT applications using CC3100 user API:
Get whether application using CC3100:
This application demonstrates how to connect to openweathermap.org server and
request for weather details of a city. The application opens a TCP socket w/ the server and
sends a HTTP Get request to get the weather details. The received data is processed and
displayed on the console window as shown below.
Page 59 of 65
By Ezrah Buki On LinkedIn
Figure: Get Weather Application Console Window
Page 60 of 65
By Ezrah Buki On LinkedIn
To perform this application, we need to set an IP address for the device CC3100 with
TIVA Launchpad. We can set IP address for the device CC3100 statically or dynamically as
we discussed in the session. The below steps demonstrates the configuration of a static IP
address for CC3100 TIVA Launchpad. Here the device connects to the Access Point (APwith
the configured static IP. The static IP address is stored inside the non-volatile memory of
CC3100.The basic steps for assigning IP address to a CC3100 device are given in the
flowchart shown in figure.
In this case study the module CC3100 is configured as a Wireless Local Area
Network (WLAN) Station to connect to the internet and open weather.org as a server. A
wireless local area network (WLAN) is a wireless computer network that connects two or
more devices without wires within a confined area for example within a building. This
facilitates the users to stay connected without physical wiring constraints and also access
Internet. Wi-Fi is based on IEEE 802.11 standards including IEEE 802.11a and
IEEE802.11b.
Page 61 of 65
By Ezrah Buki On LinkedIn
All nodes that connect over a wireless network are referred to as stations (STA).
Wireless stations can be categorized into Wireless Access Points (AP) or clients. Access
Points (AP) work as the base station for a wireless network. The Wireless clients could be
any device such as computers, laptops, mobile devices, smartphones etc. The flowchart for
this case study is shown in figure.
Page 63 of 65
By Ezrah Buki On LinkedIn
Case Study: Tiva based Embedded Networking Application:
“Smart Plug with Remote Disconnect and Wi-Fi Connectivity”:
In this application, the WiFi enabled Smart plug helps you to control any connected
device from home or remotely from anywhere in the world with internet access such as home
appliances like control portable heaters or window ac, turn on a light, Smart Grid and in
building automation. A smart plug is an electronic device, generally connected to other
devices or networks via different wireless protocols such as Bluetooth, NFC, WiFi, 3G, etc.,
that can operate to some extent interactively and autonomously.
Now an day all application like home automation and building automation requires
two main aspects of Smart Plug technology.
Android and cloud based remote access.
Remote disconnect and Wi-Fi connectivity based upon power consumption.
In this case study the WiFi enabled Smart Plug utilizes a TIVA Launchpad to monitor the
energy consumption for a single load and control the high-voltage side of the design. This
data is then passed to a CC3100 module to communicate the data over Wi-Fi to a Cloud
server. A solid state relay enables the application to control the load, based on its energy
consumption. And this system is powered from a highly compact and efficient UCC28910D
High-Voltage Flyback Switcher with Primary-Side Regulation and Output Current Control.
Page 64 of 65
By Ezrah Buki On LinkedIn
Figure: Flow chart of Smart Plug with Wi-Fi connectivity
Page 65 of 65
By Ezrah Buki On LinkedIn