Draft Copy - MSP430 Book PDF
Draft Copy - MSP430 Book PDF
The objective of this book is to serve as an introduction to Microcontrollers for Embedded Systems. In
the first chapter of the book, the reader will gain a basic understanding of embedded systems and its
applications.
The reader will be introduced to topics such as architecture consideration of an embedded system;
difference between CISC and RISC; Von-Neumann and Harvard Architecture.
The chapter also includes an introduction to TI‟s MSP430x2xx and MSP430x5xx microcontrollers and
their architectural features. Additionally, variants of MSP430 microcontroller family and their
comparison along with application segments are also covered.
Topic Page
1.1 Introduction ....................................................................................................................................2
1.2 Embedded system overview .........................................................................................................3
1.3 Embedded application development process................................................................................4
1.4 Applications ...................................................................................................................................6
1.5 Features and architecture considerations .....................................................................................6
1.6 CISC Vs RISC design philosophy .............................................................................................. 12
1.7 Von-Neumann Vs Harvard architecture ..................................................................................... 12
1.8 Choosing a Microcontroller for an Embedded System ............................................................... 14
1.9 On-chip peripherals and Register sets of MSP430F5529 .......................................................... 17
1.10 Addressing Modes .................................................................................................................... 20
1.11 Instruction format ...................................................................................................................... 21
1.12 Instruction set ........................................................................................................................... 22
1.13 Variants of MSP430 family ....................................................................................................... 24
1.14 Sample Applications of Embedded System on MSP430 Microcontroller ................................. 26
1.15 Summary .................................................................................................................................. 28
1.16 Review Questions..................................................................................................................... 29
1.17 Exercises .................................................................................................................................. 30
1.1 Introduction
Today, embedded systems are used across a variety of devices right from toys to appliances such as
automatic washing machines, TV remotes, handheld gadgets etc. These systems are built with the
help of a control unit known as the CPU core, which consists of microcontrollers. Microcontrollers can
be categorised based on the amount of data they can process. For example, TI‟s 16-bit
microcontroller's process 16 bits of data and at the same time dissipate very less power as compared
to other controllers of the same class.
Embedded systems also consist of high resolution ADCs, multipliers and high resolution PWMs; thus
targeting low power real time applications like consumer electronics, tests and measurement devices
etc. One such low power application is in portable medical devices such as pulse oximeter.
Pulse oximeter is a device that is used to measure the oxygen levels of a patient. TI‟s MSP430 16-bit
low power controllers provide a single chip solution for the designers. The operation is described
below:
Application Software
Hardware
The market for embedded systems is growing steadily, with several billion embedded computers being
sold every year. However, there exist certain challenges when it comes to the design of embedded
systems:
The application must be focused.
The application must have a real time requirement.
The system must have zero or very minimum user interaction.
The system must co-operate with the environment.
The system must be highly reactive.
The system must be smaller in size, low weight and must use limited memory.
The system must be low cost, safe and reliable
1.4 Applications
An embedded system may be a standalone system or it may be a part of larger system. Hence it finds
applications in:
Computer industry: CD drives control, key board control, display control, mouse, printer etc.
Electronic industry: Photo copier, scanner, digital diary, remote controller, data acquisition
systems, testing and measuring instruments, games and toys, exercise equipments, washing
machine, audio/video equipments, alert systems etc.
Communication industry: Fax machine, telephones, mobile phones, networking devices,
ATM etc.
Automotive industry: Electronic ignition, braking systems, power windows, fuel indication,
Engine Automation etc.
Military: Smart weapons, missile guiding systems, pagers, global positioning systems etc.
Medical industry: All type of medical instruments such as ECG machine, pacemaker, dialysis
machine, CT scanner, drug delivery systems etc.
The number of components in the architecture, their capacity and efficiency depends on the
development of technology, application requirement and the manufacturers.
The figure 6 shows the chief difference between the Microprocessor and Microcontroller due to the
advancement of technology. The Microprocessor has a CPU, a few registers for data transfer and
control units. On the other hand, a Microcontroller has a CPU, internal memory (program and data
memory), input/output ports, Serial communication interface and peripherals required for the
application design. The figure 7 shows the possibility of peripherals (I/O devices) present in the
architecture of embedded processor chip irrespective of the manufacturers.
DMA Controller helps peripheral devices to perform data transfer directly with memory without the
involvement of the CPU, thereby increasing the data transfer speed.
A/D converter is the analog to digital converter, which converts analog signals into digital information
for further processing. Some microcontrollers will have more than one A/D converter with different
resolutions.
Power Management Controller does the power up or power down operations when necessary for the
processor.
Capture/Compare unit records the timer values and compares it with the set values by the application.
When both values are equal, it triggers an event.
D/A converter is the digital to analog converter that converts processed digital information into analog
as required to drive the devices or display.
Cryptography accelerator is used to generate random numbers, hashing and supports for network
security.
Timer is a peripheral used to generate time delay and it can also act as a counter to count external
events.
Ethernet port reduces hardware complexity and supports network based communications like internet
and intranet oriented data transfer etc.
Real Time Clock helps to monitor round the clock events to be controlled.
A Multiply accumulate circuit facilitates fast multiplication of data and also multiplication followed by
summing.
PWM is the pulse width modulation channel whose pulse width can be varied to execute various
applications such as motor control, audio generation etc.
Joint Test Action Group (JTAG) interface provides support for programming and debugging the
processors.
Filters may be high pass or low pass and are used to produce high frequency or low frequency signals
required for applications.
Switch Mode Pump is a boost converter used for voltage conversion i.e. from low voltage to high
voltage.
SPI is a serial peripheral interface which supports for synchronous serial communication.
Phase locked Loop (PLL) is the clock source for other required peripherals in the processor.
I2C bus is the two wire serial bus that supports the processor to communicate with a large number of
external peripherals.
Spectrum Spreader is an important peripheral to reduce the Electro Magnetic Interference (EMI)
problem that must be reduced for final product certification.
Clock doubler allows the user to use a crystal oscillator, which can produce half the value of
frequency required for normal operation of the processor since it doubles it internally. This feature
helps reduce power consumption and radiated emission.
Watchdog timer is another important peripheral used to monitor the operation of processor and reset
it due to malfunction.
1.5.3 Memory
The embedded processor chip has two types of memory - program memory and data memory. The
capacity and operating speed of the memory varies based on the manufacturer, version of the chip as
well as the application requirement. Program memory is called non-volatile memory since the data is
protected even after power shut down. But data memory is called Volatile memory and it loses its data
during power shut down. For example, Read Only Memory (ROM) is non-volatile program memory
while Random Access Memory (RAM) is data memory.
Read Only Memory (ROM)
ROM is used to store data permanently in an embedded system. Therefore, it is used to store the
application program for which the embedded system is designed. The CPU of the embedded
processor can access and read this memory to execute the application. The program stored in the
ROM cannot be modified since it is protected. It can only be modified by the respective application
developer. The ROM can be internal or external to the microcontroller. The external interfacing ROM
capacity depends on the address bus width of the microcontrollers. Based on the technology age,
manufacturer, and version of the chip, following are the types of ROM in the embedded processors
used for program storage.
Mask ROM of an embedded processor chip is programmed during the fabrication process and cannot
be reprogrammed. Since they are application specific processors, their application is decided prior to
fabrication. The cost of the Mask ROM processor chip is also less for mass production.
PROM or Programmable ROM is known as One Time Programmable (OTP) memory since it can be
programmed only once by PROM programmer or PROM burner. The application programme can be
stored only once in the embedded processor chip with PROM and cannot be reprogrammed or
modified. This type of processor chip can be used for specific applications.
EPROM or Erasable Programmable ROM was introduced in the market to overcome the
disadvantages of PROM. The EPROM can also be programmed like PROM using the programmer.
But the programme can be erased and reprogrammed more than once. The memory can be erased
entirely or partially by exposing it to ultra violet (UV) rays. The UV rays can enter the die through the
window provided for the memory. The application program in the EPROM for embedded processor
chip can be modified by reprogramming it. Therefore, an processor chip with EPROM in the market is
unprogrammed, allowing it to be programmed as per user applications.
EEPROM or Electrically Erasable Programmable ROM can be programmed and reprogrammed
more than once just like an EPROM. However, since electrical input is used to erase the contents of
the memory, individual bytes can be erased instead of entire memory. Once the information is written
inside the memory, it remains there until it is erased and new information is written. EEPROM is used
as an internal memory component in a huge number of embedded processors.
Flash memory was introduced for faster erasing and reprogramming. The information can be erased
in fraction of seconds and hence the name flash. The memory can be written or erased as sectors or
blocks instead of bytes. To program flash memory, flash programmers are used and like EEPROM,
flash memory can also be erased and reprogrammed more than once. It is a popular memory used at
present in all embedded processors.
Static RAM (SRAM) has the better life time for data than Dynamic RAM (DRAM).The static RAM uses
flip-flop in its cell to store data but dynamic RAM uses capacitor. Since the capacitor leaks charge, it
has to be refreshed periodically to hold the data. Hence the SRAM is faster than DRAM, but
expensive.
RAM (random access memory), commonly referred to as main memory, is memory in which any
location within it can be accessed directly and whose content can be changed more than once (the
number depending on the hardware).
1.5.4 Timer
Timer is a peripheral which is used to create accurate time delay between two events. It is a register
and counts the number of clock cycles. The number of registers and their size varies depending on the
manufacturers. Commonly, the size of the registers is 8/10/16 bits. Therefore, the count starts from 0
and reaches the maximum value of 255/1023/65535 respectively. Then the counting again begins from
0. During this period, the timer overflows and generates an interrupt. The timer peripheral can also be
used as a counter and it can count the external events. When the count reaches the desired value,
interrupt can also be generated.
important criterion is the speed and time synchronization between the microcontroller and I/O devices.
The data transfer rate of the I/O devices is usually several times lower than the microcontroller and
hence the suitable mechanism has to be adopted to match the speed and time to avoid the data loss.
Memory mapped I/O
It is essential to interface the required I/O devices with embedded processors to complete the
application design. One of the important devices to interface, especially with the microprocessor, is
memory. Memory is a group of registers and data stored in the individual register and accessed by its
address. The address is in the form of binary numbers and can be identified by the address bus of the
microprocessor. The width of the address bus varies depending on type and manufacturers. As a
result, the memory accessing capacity of the microprocessor is also varied. Similarly, the I/O devices
can also be identified and accessed by its address from the memory space. This technique is called as
a memory mapped I/O technique. But microcontrollers have parallel and serial I/O ports through which
the I/O devices can be interfaced. The MSP430 also follows the memory mapped I/O technique since
their ports acts as a register. The entire port or else the individual port pin can also be configured as
input or output.
I/O mapped I/O
The peripheral devices or I/O devices interfaced with the processor can also be accessed by a
separate device address. This technique is called I/O mapped I/O technique. Separate instructions are
available in the instruction set of the processor to access the I/O devices that make use of this
technique.
Therefore, Texas Instruments MSP430 Microcontrollers are designed as low power microcontrollers
since they are intended for use in various kinds of applications as well as product development. MSP
stands for Mixed Signal Processor and its architectural low power modes support for the extended
battery of portable products. The digital controlled oscillator (DCO) gives consent to the controller to
wake up from the low power modes and enter in to the active mode within 3.5 µs typically. Another
significant criterion for the selection of processor chip is the support for program coding efficiency.
Since the MSP 430 is a 16 bit RISC machine designed with 16 bit registers and constant generators,
its coding efficiency is highly enhanced. The bootstrap loader (BSL) facility of the controller aids to
program the memory using UART interface. The MSP430 memory can also be programmed using
JTAG interface since MSP430 family supports the standard JTAG interface. Apart from these standard
facilities, MSP430 memory can also be programmed using SPY – Bi – Wire interfacing technique. The
figures 10 and 11 show the Pin configuration of MSP430x5xxx series such as MSP430F5529,
MSP430F5527, MSP430F5525 etc and its block diagram respectively. The MSP430x5xxx series
microcontrollers are available in ball grid array (BGA) as well as low profile quad flat (LQPF) packages
for the application development. The Table 1 shows the nomenclature of MSP430F5529.
F Device type
5 Series
(2 series – up to 16 MHz,
V: Overflow bit. When the result of arithmetic operation overflows, this bit is set.
SCG1: System clock generator 1.Turns off the SMCLK when this bit is set.
SCG0: System clock generator 0.Turns off the DCO when this bit is set.
Osc off: Oscillator off. Turns off the LFXT1 crystal oscillator when this bit is set.
CPU off: CPU off. Turns off the CPU when this bit is set.
GIE: General interrupt enable. Enables maskable interrupts when this bit is set and Vice versa.
N: Negative bit. When the result of arithmetic operation is negative, this bit is set.
Z: Zero bit. When the result of arithmetic operation is zero, this bit is set.
C: Carry bit. When the result of arithmetic operation produces carry, this bit is set.
The constant generators CG1 and CG2 (Registers R2 & R3) are used to generate the six commonly
used constants without the need of the additional program code. It also reduces the code memory
requirement to retrieve the constants.
1.9.2 Memory
MSP430F5529 microcontroller is provided with 16 bit address bus and hence it is capable of accessing
16
2 = 65,536 = 64 Kbytes memory. Therefore, the memory address starts at 0x0000h and ends at
0xFFFFh. The flash portion has a number of segments in the memory and can be programmed using
any of the methods mentioned in section 1. The 8 bit data or 16 bit data can be written into the flash
memory. The information memory has four segments (A to D) and each segment has 64 bytes each.
Flash memory can be erased in one step or individual segments can be erased. The individual
segment of the information memory can be erased or can be erased as a group.
Auxiliary clock (ACLK), Main clock (MCLK), Sub main clock (SMCLK), ACLK/n where n=2, 4, or 8. This
module is designed to achieve low cost and low power consumable devices.
1.9.10 Comparator_A+
The comparator_A+ module is designed to monitor external analog signals as well as support for
precision analog-to-digital conversions and battery voltage supervision.
1.9.11 ADC12_A
The ADC12_A module is a 12-bit analog-to-digital convertor that is implemented by a 12-bit
successive approximation register (SAR), sample select control, reference generator, and a
conversion and control buffer. The convertor also allows the converted sample to be stored without
any CPU intervention.
The content of the source address (PC+X) is moved to the destination address (PC+Y).Hence
the program counter is altered and continued with next instruction.
Let, ED and TO be user defined labels. The instruction copies the content of the source
address ED to the destination address TO.
Let, R10 = 0FA55h and R11 = 002A5h. The content of 0FA55h is considered as an address
from which the content is copied to 002A5h.
Let, R10 = 0FA55h and R11 = 010A5h. The content of 0FA55h is considered as an address
from which the content is copied to 010A5h.Then R10 value 0FA55h is incremented by 1 for
byte operation and incremented by two for word operation.
The instruction copies the immediate constant 45 to the destination address specified by TO +
it‟s content.
Let TO = 0FF16h and its content is 01192h. Therefore the constant 45 is copied to the address
010A8h which is generated by 0FF16h + 01192h.
All the single operand and dual operand instructions are used with the extension .B or .C. The
instructions may be byte or word instructions. The byte data or byte peripherals are accessed by byte
instructions and word instructions are used to access word data or word peripherals. When no
extension is used, the default instruction is a word instruction.
The following fields are used to define the source and destination of an instruction:
src The source operand defined by As and S-reg
dst The destination operand defined by Ad and D-reg
As The addressing bits responsible for the addressing mode used for the source (src)
S-reg The working register used for the source (src)
Ad The addressing bits responsible for the addressing mode used for the destination (dst)
D-reg The working register used for the destination (dst)
B/W Byte or word operation
The source and destination are mentioned in the instruction and when this instruction is executed, the
content of source is copied to the destination.
content of the carry flag is copied to the most significant bit (MSB) of destination register, MSB to the
next bit till the least significant bit (LSB).
When this conditional jump instruction is executed, the program control is transferred to the label
mentioned for the satisfied condition. Otherwise the instruction followed by this is executed.
The above comparison table highlights the important differences between various MSP series devices.
TI has an MSP devices portfolio starting from basic Launchpad G2 to FRAM based devices.
MSP430x5xx comprises one 10 bit and one 12 bit SAR ADC giving higher resolution and more analog
channels than MSP430x2x/4x controllers which use slope type or sigma delta ADC. MSP430x5xx also
has a higher memory of 512KB flash than 128KB of MSP430x2xx/4xx controllers, thus increasing the
code storing capacity of the controller. It also has 4 16 bit timers as compared to only 2 timers in 2xx
and 4xx series controllers. The only feature where 4xx series can compete with 5xx devices is the
multiplier as both of them carry 32 bit multiplier. All of the above features make MSP430x5xx controller
a heavyweight in industrial application, portable medical devices and consumer electronics products.
Texas Instruments has come out with two Launchpad evaluation kits based on the MSP430x2xx and
MSP430x5xx microcontrollers.
MSP-EXP430G2 evalu ation kit consists of an MSP430G2553 device by default and also supports
other MSP430G2xxx and MSP430F5xxx devices. The other Launchpad evaluation kit MSP430F5529
succeeds the EXP430G2 in terms of advanced features and the use of flash memory as compared to
flash value line as used by G2 series devices.
Below is the pin diagram for MSP-EXP430G2533
The MSP430F5529 launchpad evaluation kit consists of a 40 pin booster pack interface , thus
providing more general purpose I/O pins as compared to G2 development kit. It also consists of
a power header , push buttons, LEDs and a USB connection for programming purpose. Except these,it
also has an emulator which is connected with the device and is majorly used for debugging.
Example: 2
Embedded System Based Automatic Irrigation System with Wireless Monitoring
Water is precious and every drop is turning to be a very valuable resource in the present scenario.
Development of micro irrigation systems and better water resource management are essential for
improving agricultural productivity in the country. In the past, canal irrigation system led to over
irrigation the land. Instead, maintaining moisture at just adequate levels allows for more efficient
utilization of water, enhancing agricultural productivity. Therefore, it requires a device that could
automatically control water supply based on the soil condition. The device would be installed in the
agricultural field where it would be subject to adverse conditions and may or may not be monitored by
human personnel at regular intervals. Hence it has to be reliable, consume less power and also be
cost efficient. In short, an embedded system is the only desirable solution and has to be developed
and dedicated to the agricultural field.
Figure 22: Basic Block of Embedded System Based Automatic Irrigation System
The figure 22 shows the basic block of the automatic irrigation system. This simple block consists of a
soil moisture sensor, signal conditioning circuit, Microcontroller, Motor with driver and GSM modem.
Soil moisture sensor produces the output signal based on the wet and dry conditions of the soil and
the output is tuned by the signal conditioning circuit to the required level. Microcontroller processes the
data from the signal conditioning circuit, takes a decision to drive the irrigation motor and transfers the
status of the motor to the farmer‟s mobile phone with the support of interfaced GSM modem.
1.15 Summary
1.17 Exercises
By the end of the first chapter of this book, readers were able to gain a basic understanding of
embedded systems and its applications. Building on this, the second chapter will cover the
configuration process for various components/peripherals of the microcontroller.
Readers will learn about mapping of Peripheral devices with the system as well as various Registers
dedicated to the system. They will also understand how the system can handle the Interrupt.
The chapter will also cover low power aspects of MSP430 and help readers study the FRAM as
nonvolatile memory and understand its contribution in low power devices.
Topic Page
2.1. Introduction ................................................................................................................................ 32
2.2. Microcontroller Fundamentals for Basic Programming ............................................................. 32
2.3. Peripheral address and ranges ................................................................................................. 36
2.4. I/O pin multiplexing& its relevance ............................................................................................ 43
2.5. Pull up/down registers ............................................................................................................... 44
2.6. GPIO control .............................................................................................................................. 45
2.7. Interrupts and interrupt programming. ....................................................................................... 52
2.8. MSP430 Interrupts ..................................................................................................................... 54
2.9. Interrupt priority and Interrupt vector table ................................................................................ 56
2.10. Interrupt programming ............................................................................................................. 57
2.11 System clocks and Low power modes ..................................................................................... 66
2.12 Requirements of Low Power embedded system ...................................................................... 72
2.13. Active vs Standby current consumption .................................................................................. 79
2.14. Ferroelectric Random Access Memory (FRAM) ...................................................................... 81
2.15. Summary ................................................................................................................................. 87
2.16. Review questions .................................................................................................................... 88
2.17. Exercises ................................................................................................................................. 89
2.1. Introduction
Demand for microcontrollers in the design of an effective embedded system is increasing every day.
More peripherals with higher capability and low power operative CPU core in the microcontroller chip
sets are being used in embedded systems.
A microcontroller interacts in many ways with the real world through its peripherals. Here are some
great examples to highlight how peripherals play important role in embedded system: Microcontroller
receives inputs from a human through switches. At the same time, it turns external devices on or off
through a GPIO peripheral. A microcontroller generates accurate and precise time delay through a
timer peripheral. A microcontroller reads the sensor data through ADC channel.
Peripheral devices can be either external or internal to the processor. For example, a printer is an
external device to the computer that you connect using a cable, while an optical disc drive typically
located inside the computer case but not the processor chip set is also an external peripheral.
Internal peripheral devices can be in-built or integrated with the CPU core of the microcontroller, and
are preferred for optimistic design.
The chapter begins by discussing how peripherals are mapped in the memory space of the MSP430
and peripherals with the registers associated them explains how to use those peripherals by
programming example. Next, various internal peripherals found in MSP430 such as GPIO, timer,
ADC, PWM and other peripherals with low power operation are described. The chapter also covers the
usage of peripherals in an embedded system with relevant examples.
It uses the same available memory It uses separate address space for
address for addressing & accessing IO. addressing IO
Same CPU instruction set are used for CPU instructions are different for accessing
accessing both IO and memory memory and IO.
In memory mapped peripherals, the IO devices are treated as a part of memory. So, the same
instructions which are used for memory based operations can be used for controlling the peripheral
devices. The memory section needs to be divided for IO mapping and that space cannot be used for
physical addressing. Peripheral devices need to monitor the address bus of the system to get
instructions and perform accordingly.
In MSP430, memory mapped peripheral techniques are used to address and access IO devices. For
the 16 bit peripheral module, the address range available is from 0100h to 01FFh. This memory range
is used for accessing word instructions. If byte instructions are used with this section, only even
addresses are permissible and the high byte of the provided result is zero. For the 8 bit peripheral
module, the address range available is from 010h to 0FFh. This memory range is used with byte
instructions. If read access of word instruction is provided in byte module, then we get an
unpredictable data in the high byte as a result. If word data is written to byte module, only low byte is
written into peripheral register ignoring the higher byte.
Therefore, it is frequently more practical to take advantage of the benefits of memory-mapped I/O. The
advantage of this method is that every instruction which can access memory can be used to
manipulate an I/O device.
In this chapter, we provide a detailed description of the registers accessible in memory space.
MSP430 has Von-Neumann architecture, which means that one address space is shared with all
memory, including special function registers (SFRs), peripheral module registers, Random Access
memory (RAM), Flash/ROM and information memory. They are mapped into a single, contiguous
address space as shown in Figure below.
The address range and data size of the each memory is shown in the figure. Data size of the some of
the memory is word, byte or both.
The memory map is slightly different for each device in the MSP430 series.
GPIO
There are up to 9 digital I/O ports (P1 to P9) in MSP430X5xx and up to 11 digital I/O ports (P1 to P11)
in MSP430x6xx series. Different MSP430 series contain a different number of ports. Some contain
eight I/O lines and some may contain fewer lines. This I/O line is individually used for input or output,
and each can be individually read or written. Each I/O line is individually configurable for pullup or
pulldown resistors. The Ports can be accessed as a byte wide or can be combined into another Port
as word wide.
P1 and P2 referred in the programming to access byte wide and P1 and P2 are paired and referred to
as PA in programming to access as word wide. Similarly, P3 and P4, P5 and P6, and so on, are
referred as PB, PC, and so on, respectively
P1 and P2 ports have interrupt capability and each pin of the P1 and P2 I/O lines can be
individually enabled and configured for rising or falling edge triggering type. Each pin of the P1 has a
single interrupt vector address (P1IV) and similarly P2 also has a single vector address (P2IV) but P1
and P2 has different vector addresses.
Timer Peripherals:
MSP430 microcontroller can be used with a wide variety of timer peripherals such as Watch dog timer,
Timer basic, Timer A, B and D, and Real Time Clock (RTC). Timer peripherals gets clock from various
clock sources available in the controller itself.
A watchdog timer is used to detect programming stuck in a continuous loop of execution and to reset
the processor. This is one of the powerful peripherals for protecting programming hang. The watchdog
timer is a 32-bit timer that can be used as a watchdog or as an interval timer. The WDT can be used in
an application and once it is used, it needs to be cleared so as to not expire the timer value.
MSP430x5xxx has three individual 16 bit timer peripherals namely Timers A, B and D. Each timer
supports 4 different modes of operations such as interval timing generation, capture, comparison and
pulse width modulation output generation. Additionally, there are multiple capture/compare modules in
each timer peripheral. Interrupt may be generated from the counter on overflow conditions or from
each of the capture/compare registers. Timer D operates in high resolution mode with a fine clock
frequency input, which is up to 16 times the timer input clock frequency.
Real Time Clock (RTC)
Real Time Clock is also a timer based peripheral and it provides a real-time clock and calendar
function that can also be configured as a general-purpose counter. It gets the clock from ACLK or
SMCLK sources. It provides seconds, minutes, hours, day of week, day of month, month, and year in
real-time clock with calendar function. It can be accessed along interrupt feature.
ADC
MSP430 microcontroller is facilitated with three different analog to digital converting (ADC) peripherals
-ADC10, ADC12 and SD24. ADC10 and ADC12 have successive approximation type ADCs with the
resolution of 10 bits and 12 bits respectively. Each ADC is facilitated with the 16 channel input and the
conversion rate maximum of 200-ksps.The clock signal for A to D conversion and for sample and hold
operation is given by clock source or by timer. Since an A to D Conversion is done with respect to
reference voltage, the reference voltage for ADC10 and ADC12 can be given by internal reference
generator module or through external pin and each of the ADC is having internal temperature sensor.
Both ADCs are functioning with 4 different conversion modes of operations such as Single channel,
repeat single channel, sequence (auto scan), and repeat sequence (repeated auto scan). The ADC10
and ADC12 are designed for low-power applications. When they are not actively converting, the
peripheral core are automatically disabled and enabled individually when needed.
ADC10 stores the converted data into an ADC memory register (ADC10MEM) and sets the interrupt
flag to generate interrupt. It stores the converted data of each channel among 16 channels into the
same memory register for all the conversion modes of operation. So the converted data should be
read by programming on each conversion complete. ADC10 comes with a window comparator circuit,
which compares the ADC data with predefined low and high value stored in separate registers and
sets the corresponding interrupt flags.
ADC12 stores the converted data of each channel into the separate memory register allocated for
each channel. The overflow condition occurs when a conversion result is written to any one of the
memory registers before its previous conversion result was read and it sets an overflow flag to
generate interrupt.
The SD24 peripheral consists of up to eight independent sigma-delta analog-to-digital converters. The
converters are based on second-order oversampling sigma-delta modulators and digital decimation
filters. The decimation filters are comb type filters with selectable oversampling ratios of up to 1024.
Additional filtering can be done in software.
DAC12
This peripheral is a 12-bit DAC and it can be configured in 8-bit or 12-bit mode and may be used in
conjunction with the DMA controller. When multiple DAC12 modules are present, they may be grouped
together for synchronous operation. Since, D to A conversion is done with respect to reference voltage
and this can be given to the DAC internally or externally to the peripheral. It supports unsigned binary
(uni polar) or twos-complement (Bipolar) data format with right or left justified.
Comparator
The comparator peripheral compares analog input voltages at the + and – input pins itself. If the
voltage at + pin is more than the – pin, the comparator output (CBOUT) is high. The comparator can
be switched on or off when not in use to reduce power consumption. It supports selectable reference
voltage generator, voltage hysteresis generator and reference voltage input from shared reference.
USCI (UART, SPI and I2C)
The USCI module in MSP430x5xxx supports multiple serial synchronous and asynchronous
communication modes supported peripherals such as UART, SPI, and I2C.
In asynchronous mode, the USCI module connects the device to an external system or device to
device by two external pins TXD and RXD called universal asynchronous receiver transmitter (UART).
In MSP430 series these pins are referred as UCAxRXD and UCAxTXD. It supports for programmable
Baud rate (bits per second (bps)), 7 or 8 bit data with odd, even, or non-parity, LSB-first or MSB-first
data transmit and receive configuration and multiprocessor communication. It has an independent
interrupt capability on receive and transmit complete.
In synchronous mode, the USCI connects the device to an external system by three or four pins such
as MOSI (master out slave in), MISO (master in slave out), SCK (serial clock) and SS (slave select)
called SPI (serial peripheral interface). In MSP430 series, these pins are referred as UCxSIMO,
UCxSOMI, UCxCLK, and UCxSTE. It supports for 7-bit or 8-bit data length, LSB-first or MSB-first data
transmit and receive, and 3-pin and 4-pin SPI operation. Independent interrupts capability for receive
and transmit complete.
The I2C architecture is in compliance to the Philips semiconductor I2C protocol. It supports for 7-bit
and 10-bit device addressing modes, multi-master transmitter/receiver mode, and slave
receiver/transmitter mode, standard mode up to 100 kbps and fast mode up to 400 kbps.
DMA
The direct memory access (DMA) controller peripheral transfers data from one memory space to
another without CPU intervention across the entire address range. For DMA, MSP430 microcontroller
has many features in transferring data. For example, it transfers data from the ADC conversion
P9 08h,0Ah,0Ch,0Eh, 16h
T
60h to 67h, 5Dh to 5Fh, 1h and 3h
T
D0h to D7h, CDh to CFh, 6h,7h
a UART MSP430x2xx
b 68h to 6Fh, 118h to 11Bh
2
Fla.sh Memory Flash Memory 128h to 12Dh
1
m 80h to 8Fh
e SDADC16 100h to 103h, 110h to 113h, B0h, B7h MSP430X2XX
m
o SDADC24 100h to 11Fh, B0h BEh MSP430X2XX
r
y 1C0h to 1C3
DAC
1C8h, 1CBh
m
122h to 127h
a
T 1D0h to 1D7h
DMaA 1DAh to 1DFh MSP430X2XX
b 1E2h, 1E3h, 1E6h to 1Ebh
l 1EEh, 1EFh, 1F0h to 1F7h
e
2.1: Peripheral and memory map
In the above Table 2.1, it is shown that some of the registers are common for many peripherals.
All of the listed peripherals in the table are not present in all the devices of MSP430. As an example,
MSP430C1101 device in MSP430X1XX family is having P1, P2, Comparator_A, and Timer_A.
Similarly, each device in a family has its own list of peripherals. The other capabilities like interrupt,
Watchdog timers, clock circuit, and reset circuits are common for all families of the MSP430 devices.
When you develop a system with the MSP430 controller using certain peripherals, ensure that the
device you have chosen has the required peripherals in the device by referring the data sheet from TI
web site.
Also, users need to ensure that the registers associated with each peripheral are handled for
configuration properly.
CPU Registers in MSP430:
The CPU incorporates sixteen 16-bit registers from R0 to R15. The registers R0, R1, R2 and R3 have
dedicated functions. R4 to R15 are working registers for general use.
As shown in the figure below, four of the registers, R0 to R3, are dedicated as program counter, stack
pointer, status register, and constant generator respectively. The remaining registers are general-
purpose registers.
locations of the memory space by the user, and is aligned to even addresses with LSB hardwired to
zero.
Status Register (SR)
The register R2 is the status register (SR) and it is used as a source or a destination register. It can be
used in the register mode only and addressed by word instructions. The remaining combinations of
addressing modes are used to support the constant generator. Figure below shows the individual bit
description of SR register.
The advantage of having this structure is that there are no special instructions required, no additional
code word for the six constants, no code memory access required to retrieve the constant.
The assembler uses the constant generator automatically if one of the six constants is used as an
immediate source operand. Registers R2 and R3, used in the constant mode, cannot be used explicitly
they act as constant registers.
Peripheral registers
In MSp430, the in-built peripherals such as GPIO, serial interface and timer etc. are mapped to the
memory space of the CPU as memory mapped IO. The registers associated with the corresponding
peripherals are discussed as follows.
P1IN Input
P1OUT Output
P1DIR Direction
GPIO registers P1IFG Interrupt Flag
P1IES Interrupt Edge Select
P1IE Interrupt Enable
P1SEL Port Select
P1IN Input
P1OUT Output
P1DIR Direction
GPIO registers P1IFG Interrupt Flag
P1IES Interrupt Edge Select
P1IE Interrupt Enable
P1SEL Port Select
configure the port pin as an input. PxREN used to enable the Pull up/Pull down, but choosing Pull up
or Pull down resistor to the port pin is done by the PxOUT register.
P1-P2
PA ( PA_Low byte = P1 and PA_High byte = P2 )
P3-P4
PB ( PB_Low byte = P3 and PB_High byte = P4 )
P5-P6
PC ( PC_Low byte = P5 and PC_High byte = P6 )
P7-P8
PA ( PD_Low byte = P7 and PD_High byte = P8 )
P9
No pair
#include"msp430x5xxx.h"
void main (void)
{
unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watch dog timer
P1DIR = 0x01; // Set P1.0 to output direction
While(1)
{
P1OUT = 0x01; // Set P1.0 Pin to Logic High
for ( i=0; i<20000; i++); //delay
P1OUT = 0x00; // Set P1.0 Pin to Logic Low
for ( i=0; i<20000; i++); //delay
}
}
#include"msp430x5xxx.h"
#include"msp430x5xxx.h"
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watch dog timer
P1DIR |= 0x41; // Set P1.0 and P1.6 are to output
P1REN = 0x04; // P1.3 is enabled for pull up/down circuit
P1OUT |= 0x04; // P1.3 is chosen for pull up resistor
P1OUT |=0x40; // P1.0 = 0 and P1.6 =1
while(1)
{ if (!(P1IN & 0x04)) // It is true when P1.3 is zero and other bits are
masked
P1OUT ^= 0x41; } // Toggle P1.0 and P1. 6 by EXOR operation
// Other bits are not disturbed
}
#pragma vector=PORT1_VECTOR
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; //Stop Watchdog Timer
P1DIR |= 0x41; // Set P1.0 and P1.6 are to output
P1REN = 0x04; // P1.3 is enabled for pull up/down circuit
P1OUT |= 0x04; // P1.3 is chosen for pull up resistor
P1OUT |=0x40; // P1.0 = 0 and P1.6 =1
P1IE |= 0x04; //Interrupt Enable in P1.3
P1IES |= 0x04; //P1.3 Interrupt flag high-to-low transition
2.7.1. Introduction:
An interrupt is an event generated by hardware or software. When an event that is asynchronous to
the current program execution occurs, then it automatically transfers CPU execution to a defined sub
program called interrupt sub program.
The following Figure 2.6.1 shows an example of how a microcontroller responds to an input signal. The
system is made for controlling the speed of the motor with proper feedback mechanism. The program
is written for sensing the speed and controlling the motor for the required speed and this program is
running forever. When the operator wants to stop the motor immediately and he presses the Panic
OFF switch then the motor should be OFF immediately.
consumes all its processing time for only monitoring the pin. This problem is overcome by using
interrupts.
The P1.3 (connected with Push button) is configured as an input port pin with internal pull up
by the following three statements.
A mask setting determines which devices (e.g. push button) can generate an interrupt. In P1
Interrupt enable register, bit 3 (0x08) of P1.3 is connected with the push button is configured
by 1 to enable (0 to disables or mask) device to trigger an interrupt and globally enable the
interrupt. This is done with the following statements.
The interrupt handler mechanism in the C level program for MSP430 is done as follows. The
push button is part of port 1, a PORT1_VECTOR interrupt handler is executed when a port 1
interrupt handler occurs.
#pragma vector=PORT1_VECTOR
interrupt void Port_1(void)
When the interrupt in P1.3 occurs, the corresponding flag P1IFG bit is set to 1 by hardware.
The interrupt handler should normally disable the interrupt by setting the same flag to 0,
allowing another interrupt to occur. This is done by the following statement in the interrupt
service routing.
#include <msp430.h>
#define LED 0x40 // BIT6
long i=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= LED; // Set P1.6 to output
P1OUT &= ~LED; // Set LED to off
P1SEL &= ~0x08; // Select Port 1 P1.3
P1DIR &= ~0x08; // Port 1 P1.3 as input
P1REN |= 0x08;
P1IE |= 0x08;
P1IFG &= ~0x08; // Clear interrupt flag
_BIS_SR(GIE); // Enable interrupts
_BIS_SR(LPM4_bits + GIE); // Enter LPM4
}
Exercise:
Develop the c program for the following.
1) Three push buttons are connected in P1.0, P1.1 and P1.2 respectively and Three LEDs are
connected in P2.0, P2.1 and P2.3 respectively. Each push button input is configured as
interrupt input and assumed to be debounced. When any one of the push button is pressed,
its corresponding LED is toggled.
2) Measure the bouncing frequency of switch button. A push button is connected in P1.0 with
interrupt pin configured. Four LEDs are connected in P2.0,P2.1, P2.2 and P2.3. When the
push button is pressed the bounce rate is computed and stored as no of 1000s, no of 100s, no
of 10s and ones. The stored value is seen in the LED by blinks for no of 1000s, 100s,10s and
1s by its LED connected in P2.0, P2., P2.2 and P2.3 respectively.
Questions:
1) What does this statement P1IFG &= ~0x08” do?
2) What statement is executed after: P1OUT ^= LED;
3) Suppose the LED is OFF. What results if the ISR is executed 2 times?
4) State the execution of the above program when the button is not debounced
5) What are the steps that occur when an interrupt is processed?
WDTPW (15-8): Watchdog timer password. Always read as 069h. Must be written as 05Ah, or a PUC
will be generated.
WDTHOLD (7): Watchdog timer hold. This bit stops the watchdog timer.
0 -- Watchdog timer is not stopped
1 -- Watchdog timer is stopped (WDT is not in use conserves power)
WDTNMIES (6): Watchdog timer NMI edge select. Selects the triggering edge for the NMI interrupt
0 -- NMI on rising edge
1 -- NMI on falling edge --- Modifying this bit can trigger an NMI
WDTNMI (5): Watchdog timer NMI select. Selects the function for the RST/NMI pin
0 -- Reset function
1-- NMI function
WDTTMSEL (4): Mode select.
0 -- Watchdog mode
1 -- Interval timer mode
WDTCNTCL (3): Watchdog timer counter clear. Setting WDTCNTCL = 1 clears the count value to
0000h. WDTCNTCL is automatically reset.
0 -- No action
1 -- WDTCNT = 0000h
WDTSSEL (2): Watchdog timer clock source select 0 – SMCLK.1 – ACLK
WDTISx (1-0): Watchdog timer interval select. Select the watchdog timer interval to set the WDTIFG
flag and/or generate a PUC.
00 -- Watchdog clock source /32768
01 -- Watchdog clock source /8192
10 -- Watchdog clock source /512
11 -- Watchdog clock source /64
NMIIE (4): NMI interrupt enable. Enables the NMI interrupt. Set or clear this bit done by using BIS.B or
BIC.B
0 -- Interrupt not enabled
1 -- Interrupt enabled
WDTIE (0): Watchdog timer interrupt enable. Enables the WDTIFG interrupt for interval timer mode
It is not necessary to set this bit for watchdog mode.
0 -- Interrupt not enabled
1 -- Interrupt enabled
Bits 3-1 and 7-5 may be used by other MSP430 series.
3) IFG1
main( )
{
while(1)
{
WDTCNT =0; // reset watchdog count to 0
....
....
....
}
}
If the program is working perfectly, the watchdog count will never become a full scale value (32768)
because one iteration of the loop will take only a maximum of 10 milli seconds, and there is a
statement to reset the count to zero at the beginning of each iteration. If the system stuck( hangs)
because of any reason, the reset watchdog-count-to-zero statement will not get executed within the
next 10 milli seconds - the watchdog count will becomes 32768 (in 32 milli seconds) and this will result
in a system reset. This ensures that the system will stay in the frozen state for only a time period well
below the danger level.
Disabling WDT
When the watchdog functionality is not used in any of the application programs, it is essential that the
watchdog timer is disabled otherwise, the processor will reset every 32 milliseconds and the program
will seem to behave in mysterious ways. One way to disable the WDT is to write the below statement
as the first line of main program.
WDTCTL = 0x5A00 | (1 << 7)
(OR)
WDTCTL = WDTPW | WDTHOLD
Interval Timer Mode
This mode is available in MSP430x2xxx series onwards. This mode can be used to provide periodic
interrupts like conventional timer. The WDTIFG flag is set at the expiration of the selected time interval.
A power on clear (PUC) is not generated in interval timer mode at expiration of the selected timer
interval and the WDTIFG enable bit WDTIE remains unchanged. When the WDTIE bit and the GIE bit
are set, the WDTIFG flag requests an interrupt. The WDTIFG interrupt flag is automatically reset when
its interrupt request is serviced, or may be reset by software. The interrupt vector address in interval
timer mode is different from that in watchdog mode
#include "msp430g2553.h"
unsigned int i=0;
void main(void)
{
WDTCTL = WDT_MDLY_0_5; // WDT as interval timer (period 0,5 ms)
// WDTPW + WDTTMSEL + WDTCNTCL + WDTIS1
IE1 |= WDTIE; // Enable WDT interrupt
P1DIR |= BIT0+BIT6; // Set P1.0 & P1.6 as output
P1OUT |= BIT0+BIT6; // P1.0 & P1.6 are ON at start
_bis_SR_register(GIE); // Enable global interrupt
while(1); // looping and doing nothing
}
#pragma vector=WDT_VECTOR
interrupt void watchdog_timer(void)
sets up the interrupt service routine for WDT. The definition of the function is to simply toggle the LED
in P1.0. And the observations of the above program, The watchdog function manipulates two registers
WDTCTL and IE1.
The digital control of the oscillator allows frequency stabilization despite its RC-type characteristics
using FLL hardware as shown in Figure 2.8.2. The XT1CLK can be used as a clock reference into the
FLL which stabilizes the clock reference and generates DCOCLK. The DCOCLK signal is further
divided by 1,2,4,8, 6 or 32 using clock divider and generates the DCOCLKDIV signal.
When power is switched on, DCO is configured with internal resistor and is start with mid-range
frequency as reset default. Also MCLK and SMCLK are generated from DCOCLK in power up
because of the CPU executes code from MCLK. The code execution begins from PUC in less than 6
us with MCLK.
The internal or external resistor can be selected with DCOR bit in BCSCT2 register by user program.
The three DOCX bits in DCOCTL register select one of eight nominal frequency ranges. RSELx bits in
BCSCTL1 into 8 frequency steps, separated by approximately 10% within the frequency range
selected by DOCX bits in DCOCTL registers. These frequency ranges are defined for an individual
device in the device-specific data sheet.
The five modulators selection MODx bits switch between the frequency selected by the DCOx bits and
the next higher frequency set by DCOx+1. When DCOx = 07h, the MODx bits have no effect because
the DCO is already at the highest setting for the selected RSELx range. The typical DCOx and RSELx
ranges and steps are shown in Figure below and DCO frequency is different from MSP430 device to
device.
DCOx: Bits DCO frequency select. These bits select which of the eight discrete
7-5 DCO frequency select. These bits select which of the eight discrete DCO frequencies
of the RSELx setting is selected.
MODx: Bits Modulator selection. These bits define how often the fDCO+1
4-0 Frequency is Modulator selection. These bits define how often the fDCO+1 frequency
is Modulator selection. These bits define how often the fDCO+1 frequency is used
within a period of 32 DCOCLK cycles. During the remaining clock cycles (32−MOD)
the fDCO frequency is used. Not useable when DCOx=7
Basic Clock System Control Register 1 (BCSCTL1)
XT2OFF Bit 7 XT2 off. This bit turns off the XT2 oscillator
0 XT2 is on
1 XT2 is off if it is not used for MCLK or SMCLK.
XTS Bit 6 LFXT1 mode select.
0 Low frequency mode
1 High frequency mode
DIVAx Bits Divider for ACLK
5-4 00 /1
01 /2
SELMx Bits Select MCLK. These bits select the MCLK source.
7-6 00 DCOCLK
01 DCOCLK
10 XT2CLK when XT2 oscillator presents on-chip. LFXT1CLK when XT2
oscillator not presents on-chip.
11 LFXT1CLK
DIVMx BitS Divider for MCLK
5-4 00 /1
01 /2
10 /4
11 /8
SELS Bit 3 Select SMCLK. This bit selects the SMCLK source.
0 DCOCLK
1 XT2CLK when XT2 oscillator presents on-chip. LFXT1CLK when XT2
oscillator not presents on-chip.
DIVSx BitS Divider for SMCLK
2-1 00 /1
01 /2
10 /4
11 /8
DCOR Bit 0 DCO resistor select
0 Internal resistors
1 External resistor
IE1, Interrupt Enable Register 1
In this device, heart rate monitor is used to provide the reading for heart rate and blood pressure. For
the speed and motion reading we have an accelerometer, gyroscope and magnetometer. There is a
provision of LCD displays, which displays real time measured parameter values. Here the USB
peripheral allows the device to download the data and update the device software. As this device is
operated by battery, it requires an ultralow power MCU to keep it running for longer hours.
Broadly, there are different kinds of methods to minimize the power consumption of microcontroller by
its operating modes. Basically MSP430 works on two types of mode:
1) Active Mode
2) Low Power Mode
Low power modes are classified into different categories depending upon the different clock condition
that is explained in next section of this chapter.
The operating modes take into account three different needs:
Ultralow-power
Speed and data throughput
Minimization of individual peripheral current consumption
MSP430 microcontroller is a mixed signal processor having power efficient digital and analog signal
processing capability by having various digital and analog signal supported peripherals with different
kind of low power modes of operation supported.
Status Register (SR) of MSP430 has some of the control bits used for selecting a particular low power
operating modes and the description of the bits are shown in Table 2.9.1.
0 0 1 LPM1
CPU, MCLK are disabled.
1
DCO and DC generator are disabled if the
- DCO is not used for SMCLK or ACLK.
FLL is disabled if DCO is disabled
1 0 1 LPM2
SMCLK and ACLK are active.
1 disabled.
ACLK is active.
1
CPU and all clocks disabled
Figure 2.9.1 Flow chart of transition Active mode to LPM and vice versa
MSP430x5xxx and higher order series have LPM3.5 and LPM 4.5. When the controller is entered into
any one of those modes, the voltage regulator of the Power Management Module (PMM) is disabled.
All the RAM, register and IO contents are lost, the I/O pin states are locked upon LPMx.5 entry.
Wakeup from LPM4.5 is possible by the power sequence, a RST event, RTC or from specific I/O. The
more description about LPM3.5 and 4.5 are discussed in its user manual and datasheet.
The following statements are used in the CCS compiler to configure the low power modes in MSP430.
By invoking the first statement in a program, the bits CPUOFF, SCG1, SCG0 and OSCOFF in SR
register are set to logic 1 and the microcontroller is getting into low power mode 4. The corresponding
configuration is discussed in Table 2.9.2.
_BIS_SR(LPM4_bits);
_BIC_SR(LPM4_bits);
By invoking the second statement, all the bits CPUOFF, SCG1, SCG0 and OSCOFF in SR register are
cleared and the microcontroller is exiting from low power mode 4. The following program illustrates that
how the microcontroller is entering into the LPM as shown in Figure 2.9.3.
Use low power inbuilt peripheral modules and configure it to run autonomously. As an example
Timer_A and Timer_B automatically generate PWM output and capture timing without CPU
resources.
Polling the pins and flags has to be avoided strictly. Prefer interrupt driven method for all
peripherals function like TIMER, ADC, UART, SPI and I2C as well as other modules as much
as possible. Build the application to operate asynchronously as much as possible.
Polling the flag can be avoided by invoking calculated branching.
Instead of doing long software calculations by CPU, the faster look-up table can be used.
Avoid frequent subroutine and function calls.
For longer software routines, single-cycle CPU registers should be used.
2.12.4. Summary and conclusion
The chapter is discussed with various battery operated systems and the static and dynamic power
consumption of the system. The flow chart for operation of MSP430 in active mode to LPM and vice
versa is shown. How the power is reduced by means of various low power modes present in MSP430
with sample programs is illustrated. Also it discussed for methods to follow in programming to design
the system for power reduction.
Low power modes are predominantly used in MSP430 to support us to conserve energy in a battery
operated application. In some critical application, upon interrupt in LPM, the delay in getting into active
mode to handle the interrupt is too long. Slower clock such as 32.768 kHz oscillator takes much longer
to stabilize approximately in milliseconds but the faster clock from crystal oscillator takes very few
microseconds. For this reason, the programmer prefers to wake up the CPU from LPM the faster clock
source is used in active mode and we do pay a penalty for this. This penalty is not only the time it
takes to go from a low power mode to Active Mode but it is that how long stays in active mode. The
deeper the time we go into the low power modes, the longer it takes to go to Active Mode makes the
system in power optimistic.
In another aspect, understanding the variants of peripherals with various modes of its operation
towards low power and the methods of handling those peripherals with interrupt driven for an
application will make us to develop the program for power optimized application.
enters and remains in an ultra-low power standby mode as long as possible, and is awakened only to
service interrupts as fast as possible. Multiple oscillators are utilized to provide both an ultra-low power
standby mode and high-performance processing.
The clock system is very flexible and allows the MSP430 to operate optimally from a single 32 KHz
crystal to the internal digitally controlled oscillator (DCO) used for the CPU and high-speed peripherals.
A low-frequency Auxiliary Clock (ACLK) is driven directly from a common 32KHz watch crystal with no
additional external components. The ACLK enables the MSP430‟s ultra-low power standby mode
(LPM3) and an internal real-time clock function. In LPM3, the MSP430 typically consumes current in
the 1µA range. The integrated high-speed DCO can source the master clock (MCLK) used by the CPU
and high-speed peripherals. In design, the DCO is active and fully stable in less than 6µs with no
intermediate steps. This enables the CPU to conduct instant high-performance processing without
waiting for a long start-up for a second crystal or second speed start-up. Because the DCO is digitally
adjustable with software and hardware, stability over time and temperature is assured.
The operating modes of MSP430 series microcontrollers are for three different needs such as
Ultra-low power
Speed and data throughput
Minimization of individual peripheral current consumption
As in the data sheet of MSP430G2553, in Active mode the current consumption varies form 225µA to
340µA against the operating voltage that varies from 2.2V to 3V. Similarly current consumption by
other low power modes are given in the Figure 10.1
Active mode
225 - 250
2.2V
fDCO=fMCL = fSMCLK = 1MHz
fACLK=0 340 - 420
3V
Figure 10.2 Active mode current against to operating voltage and Frequency.
Ferroelectric Random Access Memory (FRAM) is an ultra-low power nonvolatile memory technology
with write speeds akin to static RAM (SRAM). The technology has been in the industry for over a
decade, implemented as stand-alone memory. FRAM's first introduction as an embedded memory in a
general purpose ultra-low-power MCU was on Texas Instruments 16-bit MSP430™ product line, the
MSP430FR57xx family.
Some of the important attributes of FRAM are:
1) FRAM is non-volatile; that is, it retains its contents on loss of power.
2) FRAM is a true random-access memory. The memory is not segmented; addressing of data
for read or write at word or byte level happens directly in the same way as SRAM.
3) The embedded FRAM on MSP430 devices can be accessed (read or write) at a maximum
speed of 8 MHz. Above 8 MHz, wait states are used when accessing FRAM. Typical write
speeds can exceed 2 MBps with FRAM compared to approximately 14 kBps on flash devices
4) Writing to FRAM and reading from FRAM require no setup or preparation such as pre-erase
before write or unlocking of control registers.
5) FRAM write accesses are extremely low power, because writing to FRAM does not require a
charge pump.
6) FRAM writes can be performed across the full voltage range of the device.
7) FRAM meets and exceeds reliability requirements on data integrity. It provides practically
unlimited endurance for read and write operations on the order of 1015 write or erase cycles.
FRAM Characteristics:
Data Retention:
The basic goal of performing data retention tests is to ensure that FRAM can meet the retention
specification for nonvolatile memory characterized by a ten-year lifetime at 85°C.
FRAM Data Retention Test Flow
To clarify the test procedure for data retention, the following two terms are defined:
Same-state refers to the logic state of FRAM; that is, the state of polarization of the
ferroelectric crystal prior to the high-temperature bake when testing for imprint.
Opposite-state refers to the polarization of the crystal in a direction opposite to that in which it
was imprinted.
Figure 1.shows the test procedure for data retention. To test for imprint, a data pattern with a set logic
state is written onto FRAM, and then the device is exposed to a high-temperature bake at 125°C. This
bakes the bit-cells in one logic state referred to as same-state. This bake is followed by a read-restore
to further strengthen the same-state data. Following this, opposite-state data is written to FRAM. This
is followed by a thermal depolarization bake to weaken/stress the opposite-state data. This bake is
performed at the maximum operating temperature for the device (85°C for the MSP430). After the de-
polarization bake is completed, the data is read out to ensure the integrity of the opposite-state data.
The test is then repeated until the testing time is reached.
Energy trace technology is provided to calculate the power and energy of the device. Energy Trace
technology is included in Code Composer Studio version 6.0 and newer. It requires specialized
debugger circuitry, which is supported with the second-generation on-board eZ-FET flash emulation
tool and second-generation standalone MSP-FET JTAG emulator. Target power must be supplied
through the emulator when Energy Trace is in use.
2.15. Summary
2.17. Exercises
The previous chapter provided a deep understanding of peripherals and the programming concepts of
the MSP430 microcontroller. It also covered topics such as memory mapped peripherals followed by
the system registers used to control GPIOs, interrupts and watchdog timer as well as system clocks
present in the device.
In this chapter, readers will learn about some more advanced features of the MSP430 microcontroller.
At the end of the chapter, the reader will be able to have an understanding of timers and Real time
Clock; pulse width modulation control and its applications; ADC and comparator as well as data
transfer using the DMA module. Additionally, the chapter will also cover the programming methodology
of peripherals for optimal power management.
Topic Page
3.1. Introduction ................................................................................................................................ 91
3.2. Timer and RTC .......................................................................................................................... 91
3.3. Timer_A ..................................................................................................................................... 95
3.4. Real Time Clock (RTC) ........................................................................................................... 106
3.5. Pulse Width Modulation ........................................................................................................... 113
3.6. Timing generation and measurement...................................................................................... 117
3.7. Analog interfacing and acquisition ........................................................................................... 118
3.8. Direct Memory Access (DMA) ................................................................................................. 147
3.1. Introduction
In today‟s world, the increased use of real time systems requires a large number of high accuracy
peripherals. For example, in building automation applications such as smoke detectors or occupancy &
motion detectors, analog sensors such as optic, smoke need to be used. The received signal requires
some external peripherals such as ADC to convert the data to the digital form to be processed by the
processor as shown in the figure below.
In other applications such as audio playback modules and multi string LED drivers, timers are used to
produce PWM signals which are required to control the intensity of light and sound as shown below.
Microcontrollers, being a digital device, need peripherals like ADC, comparators and timers (to
produce PWM control) to communicate with the sensor data. The data needs to be understood by the
device and to supply variable outputs. These external peripherals incur heavy cost when used
separately, which results in an inefficient system being developed in terms of cost and size. With the
decreasing chip size, microcontrollers in the current market are being loaded with a large number of
advanced peripherals in addition to regular attributes such as GPIOs, system clocks and memory.
Microcontrollers now comprise most of the necessary peripherals, which have made the development
of an embedded system more effective and area & cost efficient.
The main focus of this chapter is to understand the technical intricacies of the on-chip peripherals
present in TI‟s MSP430 low power microcontrollers and the programming methodologies for low power
consumption.
register gets roll over (reaching to zero value and starts new counting), it sets a flag called timer
overflow flag (T1OFG) and there by the processor is interrupted from its current program to execute
the service program (ISR) associated with timer.
BTCNT2 Clock
BTSSEL BTDIV
Source
0 0 ACLK
0 1 ACLK/256
1 0 SMCLK
1 1 ACLK/256
BTFRFQx 4-3 fLCD frequency. These bits control the LCD update frequency.
00 -fACLK/32, 01 -fACLK/64, 10 -fACLK/128, 11 -fACLK/256
BTIPx 2-0 Basic Timer1 interrupt interval
000 -fCLK2/2 001 -fCLK2/4 010 -fCLK2/8 011 -fCLK2/16
BTCN1X Bits 7-0 BTCNT1 register. The BTCNT1 register is the count of BTCNT1.
BTCN2X Bits 7-0 BTCNT2 register. The BTCNT2 register is the count of BTCNT2.
3.3. Timer_A
Timer_A exists with a 16-bit timer/counter and three capture/compare registers. Timer_A can support
multiple capture/compares, PWM outputs, and interval timing. Timer_A also has extensive interrupt
capabilities. Interrupts may be generated from the timer on overflow and from each of the
capture/compare registers conditions.
Timer_A features include:
Asynchronous 16-bit timer/counter with four operating modes
Selectable and configurable clock source
Three configurable capture/compare registers
Configurable outputs with PWM capability
Asynchronous input and output latching
Interrupt mechanism for fast decoding of all Timer_A interrupts
The block diagram of Timer A is shown in Figure 3.3.
The timer register, TAR is incremented or decremented with each rising edge of the clock signal. TAR
can be read or written with software. TAR may be cleared by setting the TACLR bit. Setting TACLR
also clears the clock divider and count direction for up/down mode. The Timer should be in OFF
condition before modifying its configuration and its operation.
11 Up/down The timer repeatedly counts from zero up to the value of TACCR0 and back down to
zero.
The output signal OUTx is defined by the OUTx bit. The OUTx signal
000 Output
updates immediately when OUTx is updated.
The output is set when the timer counts to the TACCRx value. It
001 Set remains set until a reset of the timer, or until another output mode is
selected and affects the output.
The output is toggled when the timer counts to the TACCRx value. It is
010 Toggle/Reset
reset when the timer counts to the TACCR0 value.
The output is set when the timer counts to the TACCRx value. It is
011 Set/Reset
reset when the timer counts to the TACCR0 value.
The output is toggled when the timer counts to the TACCRx value. The
100 Toggle
output period is double the timer period.
The output is reset when the timer counts to the TACCRx value. It
101 Reset remains reset until another output mode is selected and affects the
output.
The output is toggled when the timer counts to the TACCRx value. It is
110 Toggle/Set
set when the timer counts to the TACCR0 value.
111 Reset/Set The output is reset when the timer counts to the TACCRx value. It is
set when the timer counts to the TACCR0 value.
7-6 Input divider. These bits select the divider for the input clock
IDx
00 - /1, 01 - /2, 10 - /4,11 - /8
Mode control
0- Stop mode: the timer is halted
MCx 5-4 1- Upmode: the timer counts up to TACCR0
10-Continuous mode: the timer counts upto 0FFFFh
11-Up/down mode: the timer counts up to TACCR0 then down to 0000h
Unused 3 Unused
7-6 Input divider. These bits select the divider for the input clock
IDx
00 - /1, 01 - /2, 10 - /4,11 - /8
Mode control
0- Stop mode: the timer is halted
MCx 5-4 1- Upmode: the timer counts up to TACCR0
10-Continuous mode: the timer counts upto 0FFFFh
11-Up/down mode: the timer counts up to TACCR0 then down to 0000h
Unused 3 Unused
Timer_A clear.
TACLR 2 Setting this bit resets TAR, the clock divider, and the count direction.
The TACLR bit is automatically reset and is always read as zero
Timer A interrupt enable. It enables the TAIFG interrupt request
TAIE 1 0-interrupt disabled, 1-interrupt enabled
Switching from counter to calendar mode clears the seconds, minutes, hours, day-of-week, and year
counts and sets day-of-month and month counts to 1.
When RTCBCD = 1, BCD format is selected for the calendar registers. The format must be selected
before the time is set. Changing the state of RTCBCD clears the seconds, minutes, hours, day-of-
week, and year counts and sets day-of-month and month counts to 1. The calendar includes a leap
year algorithm that considers all years evenly divisible by 4 as leap years. This algorithm is accurate
from the year 1901 through 2099.
Note: Any write to any counting register takes effect immediately. However the clock is stopped during
the write. This could result in losing up to one second during a write.
00 8-bit overflow
01 16-bit overflow
Counter Mode
10 24-bit overflow
11 32-bit overflow
00 Minute changed
01 Hour changed
Calendar Mode Every day at midnight (00:00)
10
11 Every day at noon (12:00)
reset
None, not
RTCMON
Real-Time Clock month Read/write 04Dh reset
None, not
Real-Time Clock year (low RTCYEARL
Read/write 04Eh reset
byte)
None, not
Real-Time Clock year (high reset
RTCYEARH Read/write 04Fh
byte)
Reset with
SFR interrupt enable register 2 IE2 Read/write 001h PUC
BCD format select. This bit selects BCD format for the calendar registers when
RTCBCD 7 RTCMODEx = 11.
0 -Hexadecimal format,1 -BCD format
Real-Time Clock hold
0 -Real-Time Clock is operational
RTCHOLD 6
1 -RTCMODEx < 11: The RTC module is stopped
RTCMODEx = 11: The RTC and the Basic Timer1 are stopped
Real-Time Clock interrupt event. These bits select the event for
Setting RTCFG.
RTCMODEx RTCTEVx Interrupt Interval
Counter Mode 00 8-bit overflow
01 16-bit overflow
RTCTEVX 3-2 10 24-bit overflow
11 32-bit overflow
Calendar Mode 00 Minute changed
01 Hour changed
10 Every day at midnight (00:00)
11 Every day at noon (12:00)
RTCNT1x Bits 7−0 RTCNT1 register. The RTCNT1 register is the count of RTCNT1
RTCNT2x Bits 7−0 RTCNT2 register. The RTCNT2 register is the count of RTCNT2
RTCNT3x Bits 7−0 RTCNT3 register. The RTCNT2 register is the count of RTCNT3
RTCNT4x Bits 7−0 RTCNT4 register. The RTCNT2 register is the count of RTCNT4
RTCYEARL, RTC Year Low-Byte Register, Calendar Mode with Hexadecimal Format
RTCYEARL, RTC Year Low-Byte Register, Calendar Mode with BCD Format
RTCYEARH, RTC Year High-Byte Register, Calendar Mode with Hexadecimal Format
RTCYEARH, RTC Year High-Byte Register, Calendar Mode with BCD Format
BTIE 7 Basic Timer1 interrupt enable. This bit enables the BTIFG interrupt. Because other
bits in IE2 may be used for other modules, it is recommended to set or clear this bit
using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions.
0 -Interrupt not enabled
1 -Interrupt enabled
- 6-1 These bits may be used by other modules. See device-specific data sheet
BTIFG 7 Basic Timer1 interrupt flag. Because other bits in IFG2 may be used for other
modules, it is recommended to clear BTIFG automatically by servicing the interrupt,
or by using BIS.B or BIC.B instructions, rather than MOV.B or CLR.B instructions.
0-No interrupt pending
1 -Interrupt pending
- 6-1 These bits may be used by other modules. See device-specific data sheet
Example 1:
The following program is used for realizing PWM signal by connecting an LED in P1.2 and this LED‟s
intensity can be adjusted by changing ON and Total time. The PWM can be realized by changing
Period and duty cycle in TARCC0 and TARCC1 respectively. The output mode can be changed to
set/rest mode and output can be realized by changing the TACCR0 and 1.
#include msp430g2553.h
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= BIT2; // Initialize port for Output signal OUT1
P1SEL |= BIT2;
TACCR0 = 0xFF;
TACCR1 = 0x20; // initial duty cycle
TACCTL1 = OUTMOD_7; // Reset/set output mode
// Start timer from ACLK /2, Up mode , clear , no interrupts
TACTL |= TASSEL_1|ID_1|MC_1;
low_power_mode_3 ();
for(;;);
}
Example 2:
The following program is used for realizing PWM signal by connecting a LED in P1.2 and this LED‟s
intensity is slowly brightened and reaches full intensity. Again the LED comes to OFF and starts
brightening continuously. The PWM can be realized by changing Period and duty cycle in TARCC0
and TARCC1 respectively. The output mode can be changed to set/rest mode for creating dimming
effect using PWM.
#include msp430g2553.h
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= BIT2; // Initialize port for Output signal OUT1
P1SEL |= BIT2;
TACCTL0 = CCIE;
TACCR0 = 0x00FF;
TACCR1 = 0x0; // initial duty cycle
TACCTL1 = OUTMOD_7; // Reset/set output mode
// Start timer from ACLK /2, Up mode , clear , no interrupts
TACTL |= TASSEL_1|ID_1|MC_1;
while(1);
}
The controller takes input from input buttons and can be used to either put the device in measuring
mode or view the stored readings. The air pump is controlled and operated by the PWM module in the
controller after the device is set to measuring mode to inflate the arm cuff for measuring systolic
pressure. The average voltage applied to the pump can also be varied by only changing the duty cycle
to ensure correct readings. The air valve is also controlled by PWM module to deflate the arm cuff
automatically to measure the diastolic pressure. The pressure sensor senses the pressure of the cuff
and displays it on the LCD. The final readings are displayed on the LCD and stored in the EEPROM.
A flowchart is illustrated to understand the application of PWM in blood pressure monitor.
3.6.4. Software
When all the timers in the MSP430 device are busy, then software loop is used. It is best to avoid
these whenever possible, except for trivial cases such as delays while a clock stabilizes.
#include <msp430g2253.h>
int main(void) {
/*** Watchdog timer and clock Set-Up ***/
3.7.1. ADC
Many of the practical real time signals around us are analog in nature. In order to feed this signal
quantity into the digital world (such as to a microcontroller), it needs to be converted into digital by
means of a special hardware called Analog to Digital Converter (ADC). The ADC gets the signal from
an analog source like pressure, temperature, lights intensity and then converts it into a proportional
equivalent electric signal. That means a physical parameter is converted into an electrical signal.
MSP430 microcontroller has two separate ADCs such as 10 bit and 12 bit namely ADC10 and ADC12
respectively.
3.7.2. ADC 10
The ADC10 module is a high-performance 10-bit analog-to-digital converter. This chapter describes
the ADC10.
Sample Timing calculation is discussed in the datasheet of the corresponding series of MSP430.
Conversion results Bits The 10-bit conversion results are right justified,
15-0
Straight-binary format. Bit 9 is the MSB. Bits 15-10 are
always 0.
DTC transfers 7-0 DTC transfers. These bits define the number of transfers
in each block.
0 DTC is disabled, 01h-0FFh Number of transfers per
block
ADC10Sax 15-1 ADC10 start address. These bits are the start address for
the DTC. A Write to register ADC10SA is required to
initiate DTC transfers
3.7.3. ADC 12
The ADC12 module is a high-performance 12-bit analog-to-digital converter. This chapter describes
the ADC12. The ADC12 is implemented in the MSP430x13x, MSP430x14x, MSP430x15x, and
MSP430x16x devices. The module supports fast (greater than 250ksps), 12-bit analog-to-digital
conversions, SAR core, sample select control, reference generator and a 16 word conversion-and-
control buffer. The conversion-and-control buffer allows up to 16 independent ADC samples to be
converted and stored without any CPU intervention.
A sequence of channels is
01 Sequence-of channels
converted once
A single channel is converted
10 Repeat single channel
Repeatedly
A sequence of channels is
11 Repeat sequence of-channels
Converted repeatedly
Single-Channel Single-Conversion Mode
A single channel is sampled and converted once. The ADC result is written to the ADC12MEMx
defined by the CSTARTADDx bits. When any other trigger source is used, ENC must be toggled
between each conversion.
Sequence-of-Channels Mode
A sequence of channels is sampled and converted once. The ADC results are written to the
conversion memories starting with the ADCMEMx defined by the CSTARTADDx bits. The sequence
stops after the measurement of the channel with a set EOS bit. When ADC12SC triggers a sequence,
successive sequences can be triggered by the ADC12SC bit. When any other trigger source is used,
ENC must be toggled between each sequence.
Repeat-Single-Channel Mode
A single channel is sampled and converted continuously. The ADC results are written to the
ADC12MEMx defined by the CSTARTADDx bits. It is necessary to read the result after the completed
conversion because only one ADC12MEMx memory is used and is overwritten by the next conversion.
SHT1x Sample-and-hold time. These bits define the number of ADC12CLK cycles in the
15-12
sampling period for registers ADC12MEM8 to ADC12MEM15.
Sample-and-hold time. These bits define the number of ADC12CLK cycles in the
sampling period for registers ADC12MEM0 to ADC12MEM7.
Interrupt enable.
These bits enable or disable the interrupt request
ADC12IEx 15-0
For the ADC12IFGx bits.
0-Interrupt disabled,1-Interrupt enabled
Now consider the various configuration parameters related to the various registers that we use in
setting up the ADC12:
Comparator_A Registers
Comparator_A exchange
CAEX 7 This bit exchanges the comparator inputs and
inverts the comparator output.
P2CA1 3 Pin to CA1. This bit selects the CA1 pin function.
0-The pin is not connected to CA1, 1-The pin is connected to CA1
P2CA0 2 Pin to CA0. Pin to CA0. This bit selects the CA0 pin function.
0-The pin is not connected to CA0,1-The pin is connected to CA0
CAOUT 0 Comparator_A output. This bit reflects the value of the Comparator output. Writing this bit
has no effect.
Comparator_A port disable. These bits individually disable the Input buffer for the pins of
the port associated with Comparator_A. For example, if CA0 is on pin P2.3, the CAPDx
CAPDx 7-0 bits can be used to individually enable or disable each P2.x pin buffer. CAPD0 disables
P2.0, CAPD1 disables P2.1, etc.
0-The input buffer is enabled, 1- The input buffer is disabled.
DMA2 TSELx 11-8 DMA trigger select. These bits select the DMA transfer trigger
0000 DMAREQ bit (software trigger)
0001 TACCR2 CCIFG bit
0010 TBCCR2 CCIFG bit
0011 URXIFG0 (UART/SPI mode), USART0 data received
0100 UTXIFG0 (UART/SPI mode), USART0 transmit ready (I2Cmode)
0101 DAC12_0CTL DAC12IFG bit
0110 ADC12 ADC12IFGx bit
0111 TACCR0 CCIFG bit
1000 TBCCR0 CCIFG bit
A 1001 URXIFG1 bit
n
a 1010 UTXIFG1 bit
l 1011 Multiplier ready
y
1100 No action
s
1101 No action
1110 DMA0IFG bit triggers DMA channel 1
DMA1IFG bit triggers DMA channel 2
DMA2IFG bit triggers DMA channel 0
1111 External trigger DMAE0
MMA0TSEL
D 3-0 DMA2TSELx
o
dern air conditioning systems available in the current market are automated systems. These air
conditioners have a remote control system available for user to control various operations in the AC
like turning on and off, sleep mode, setting a timer, shutting off the compressor, setting the
temperature, controlling the panel light and entering the energy saving mode. The remote controller
uses pulse width modulation to generate infrared signals for communication with the air condition
system.
A generic remote controller requires the necessary components:
Keypad: Generally 4x4 matrix keypad is used to provide 15 different inputs.
Microcontroller (MSP430): A microcontroller to control the complete operation
Infrared Transmitter: An infrared LED to transmit the signal
LCD Screen: To display the set values
3.9. Summary:
The chapter began with listing the importance of the presence of on chip peripherals in
microcontrollers.
Important peripherals like timers, comparators, ADC were discussed in context of n MSP430 controller.
Associated system registers along with configuration and application were also explained. PWM
control, an important technique used to produce varying analog voltages was also described and its
configuration using timers was explained with a simple application. The chapter was closed with a
case study of an air conditioner remote controller developed using MSP430 microcontroller.
3.11. Exercises
The previous chapter covered the process of configuring various interfaces such as PWM, ADC and
comparator with theMSP430 microcontroller.
Most OEMs today design sensors that come with digital data output capability, thereby making it easier
and more efficient (fewer I/O pins)to interface various sensors with the microcontroller. However, a
microcontroller must have the capability to process digital data from sensors. It must provide set of
interfaces to gather sensor data in order to process digital data.
With this in mind, this chapter will help readers understand Serial Communication protocols and their
significance. It will cover various Serial interfaces and protocols as well as the operation of various
serial protocols. Finally, it will cover the process of configuring various serial interfaces of MSP430
microcontroller and discuss digital Sensor interfacing techniques for real world applications.
Topic Page
4.1. Introduction .............................................................................................................................. 160
4.2. Basics of embedded serial communication ............................................................................. 160
4.3. Various serial communication interfaces and their comparison .............................................. 163
4.4 Universal Asynchronous Receiver-Transmitter ........................................................................ 164
4.5. I2C Serial Interface .................................................................................................................. 167
4.6. SPI Interface ............................................................................................................................ 169
4.7. Overview of MSP430x5xx Serial communication Interfaces ................................................... 170
4.8. Programming MSP430 for SPI protocol .................................................................................. 176
4.9. Programming MSP430 for I2C protocol .................................................................................. 182
4.10 Case Study: MSP430 ............................................................................................................ 192
4.11. Summary ............................................................................................................................... 195
4.12. Review Questions ................................................................................................................. 196
4.13. Exercises ............................................................................................................................... 197
4.1. Introduction
In today‟s world of digital devices, there are several instances where data communication is required
between various digital modules of the larger system. For example, in an automated gardening
system, the various sensors deployed in the gardening area sense parameters such as temperature,
pressure, moisture content, and precipitation level. These sensor parameters are converted into
analog signals and thereafter digitized by all digital sensors.
Physical
environment Set of
protocols transfer
Humidity data serially
ADC converts from
Moisture
analog signals digital sensors
Temperature
into digital to microcontroller
Pressure
signals for
CO/CO2
Accelerometer further processing
A microcontroller provides the mechanism to process digital data received from digital sensors by
means of a set of protocols and interfaces. A solid understanding of serial communication helps
engineers to understand mechanisms by which data from digital sensors can be processed by
microcontroller.
Digital data communication between various modules of embedded systems needs standards,
interfaces and protocols that facilitate easy interconnection microcontrollers and other digital sensors.
In a typical embedded system or device, microcontrollers need to communicate with external sensors
and modules like humidity sensors, pressure sensors, GPS modules, GSM/GPRS modules etc. To
support data communication between a microcontroller and digital sensor, microcontrollers support
GPIOs as well as other communication interfaces and protocols like UART, SPI, I2C and CAN. There
are two types of data communication techniques - serial communication and parallel communication.
This chapter helps readers understand the intricacies of embedded serial communication protocols
and its related concepts. The main aim is to introduce audiences to embedded communication
concepts, real time interfacing of digital modules with microcontroller MSP430 using serial interfaces
and to know the supporting communication protocols and its programming. This chapter will cover
basic protocols, terminologies and help readers understand how digital devices transmit and receive
data. Additionally, various digital interfaces available and factors affecting the right choice of interface;
specific protocols and their operation are also covered. Finally, readers will also learn about
configuring and programming various interfaces of MSP430 series microcontroller.
synchronize their access to data line with the help of shared clock for data transfer to become
successful. SPI, I2C are examples of Synchronous Serial Interfaces. Both these protocols are
explained in forthcoming sections.
One frame
d7 d0
Figure 4.1: Frame for ASCII ‗A‘ (01000001)
Figure shows the ASCII character "A", binary 0100 0001, is framed between the start bit and two stop
bits. LSB will go out first. When there is no data transfer, the logic „1‟ is transmitted. This is known as a
„mark.‟ The logic „0‟ is referred to as space. Peripheral chips can be programmed to receive or transmit
5, 6, 7 or 8 bits of data. In the initial days, twostop bits were used to give sufficient time to organize the
received data or to make suitable arrangements to transmit the next chunk of data. The modern day
microcontrollers and personal computers use 1 stop bit. In modern UARTs, a total of 10-bits are used.
8-bits are for ASCII code, one for start bit and one for stop bit.
Pin Description
1 Data Carrier Detect (DCD)
2 Received data (RxD)
3 Transmitted data (TxD)
4 Data terminal ready (DTR)
5 Signal Ground (GND)
6 Data set ready (DSR)
7 Request to Send (RTS)
8 Clear to send (CTS)
9 Ring Indicator (RI)
The handshaking mechanism is important to ensure fast and reliable data transfer between the two
devices. Few signals of RS-232 are used for handshaking.
DCD (Data carrier Detect)
This signal is also known as CD (Carrier Detect). The microcontroller asserts DCD to inform PC that a
valid carrier has been detected and connection is successfully established. DCD is an output from
microcontroller and input to PC.
DTR (Data Terminal Ready)
After self-test operation, DTR signal will inform microcontroller that it is ready for communication. DTR
is output of PC COM port. The DTR is an active low signal and won‟t get activated when there is an
error in COM port.
DSR (Data Set Ready)
When microcontroller is turned on, it will undergo self-test for UART and asserts DSR to signal PC
COM port, that it is ready. This is an active low signal.
RTS (Request To Send)
When a PC COM port wants to transmit the byte of data to microcontroller, it will signal the
microcontroller by asserting the RTS signal. RTS is an active low signal.
CTS (Clear To Send)
Microcontroller will respond to RTS signal by asserting the CTS line, indicating that it is ready to
receive data. This signal is an output of the microcontroller and an input to the PC COM port. PC will
start transmission once it receives CTS.
RI (Ring Indicator)
This signal is a handshaking signal, which is not often used. Microcontroller can send RI to PC, so that
thetelephone will ring and PC will receive it.
I2C interface supports three data transfer modes: standard mode, fast mode and high speed mode
with data rates of 100kbps, 400kbps and 3.4Mbps respectively.
the SPI device when it is configured as slave and to receive data when configured as master. Both
master and slave devices are connected together by means of shift registers as shown in Fig 4.10
The MSP430x5xx series device USCI_Ax module consists of two control registers for UART
configuration as shown below:
UCAxCTL0Register abbreviated as USCI_AxControlRegister0
UCAxCTL1Register abbreviated as USCI_AxControlRegister1
Table 4.1UCAxCTL0Register
The UART mode of the USCI_Ax module can be enabled by setting the UCSYNC bit of the
UCAxCTL0Register. Prior to the setting, we need to enable the UCSWRST bitof UCAxCTL1Register.
UCA0CTL1 |= UCSWRST;
Step 2: Write ISR related to UART interrupt. The role is to monitor the interrupt flag IFG2 and
transmit buffer flag UCA0TXIFG and put the data into buffer UCA0TXBUF for transmission, if
buffer is empty.
Table 4.5 Pin mapping between SPI and USCI module of MSP430
In MSP430x55xx series devices, P3.4 (UCA0SOMI) and P3.3 (UCA0SIMO) are multiplexed and can be
configured to be used in SPI communication using UCSI_A0 module; whereas P3.0 (UCB0SIMO) and
P3.1 (UCB0SOMI) can be configured to be used for SPI communication using USCI_B0 module. For
USCI_A0 module P2.7 port pin represents UCA0CLK pin and for USCI_B0 module P3.2 represents
UCB0CLK pin.
The master on the SPI bus provides UCA0CLK. When UCMST=1 ,the bit clock is provided by the USCI
bit clock generator on the UCA0CLK pin. The clock used to generate the bit clock is selected with the
UCSSELx bits. In order to generate bit clock using system clock (SMCLK) for USCI module:
UCA0CTL0= UCSSEL_2;
The bit clock frequency is given by
fbitclock= fBRCLK/ UCBRx, where BRCLK is equal to SMCLK.
UCBRx register can be configured for even and odd decimal values depending upon the required
bitclock frequency. The modulation field of modulation register UCA0MCTL remains empty. This can be
achieved as:
UCA0MCLT = 0;
The polarity and phase of UCxCLK are independently configured via the UCCKPL and UCCKPH control
bits of the USCI.
The UCRXIFG interrupt flag is set each time a character is received and loaded into UCxRXBUF. An
interrupt request is generated if UCRXIE and GIE are also set. UCRXIFG and UCRXIE are reset by a
system reset PUC signal or when UCSWRST=1. UCRXIFG is automatically reset when UCxRXBUF is
read. In order to receive data from slave device the procedure is:
Step 1: configure ports and initialize USCI module.
Step 2: continuously monitor receive flag UCA0RXIFG and IFG2.
Step 3: If data is available in receive buffer UCA0RXBUF, remove the data from the buffer by
storing it in a user-defined buffer.
Clear UCSWRST
Enable interrupts (optional)
In most of the applications, the MSP430 is configured as a master and external sensor module acts as a
slave device. In order for MSP430 to work as master, USCI_Bx module need to be configured as a
master and provide clock to the slave device. The USCI_Bx module is configured as an I 2C master by
selecting the I2C mode with UCMODEx = 11 and UCSYNC = 1 and setting the UCMST bit. By setting
UCSNYC=1 we ensure that USCI_Bx module is in synchronous mode. The role of the UCMST bit is to
select whether USCI module will act as a slave or master. When UCMST bit is clear, the USCI module
will act as slave, whereas when UCMST bit is set, it acts as a master. This can be done in programming
as:
UCB1CTL1 = UCSWRST;
UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC;
Prior to this we need to set UCSWRST bit to enable configuration of registers. Next we need to assign
SDA and SCL pins to UCSI_Bx (in this example USCI_B1 module).
P4SEL |= BIT2 + BIT1;
P4SEL2 | = BIT2 + BIT1;
Before clearing the UCSWRST pin, we need to select clock source and pre-scale divider register value.
This can be done in coding using the following lines:
UCB1CTL1 = USSEL_2; // Selecting SMCLK for BRCLK
UCB1BR0= 0x02; // pre-scaler divider value
UCB1BR1= 0;
After initialization is done, master transmitter mode is initiated by writing the desired slave address to
the UCB1I2CSA register, selecting the size of the slave address with the UCSLA10 bit, setting UCTR
for transmitter mode, and setting UCTXSTT to generate a START condition. Before sending START
condition, we need to make sure the module has done with previous transmission by checking STOP
condition. The various bit fields are part of Control registers:
USCI_Bx Control Register 0 (UCBxCTL0)
USCI_Bx control Register 1 (UCBxCTL1)
Main program:
Step 1: Configure USCI_B1 module as a master;
Step 2: Put slave address 0x32H into UCB1I2CSA;
Step 3: Enable receive interrupt;
Step 4: Check for the STOP condition, whether it is sent or not by monitoring UCTXSTP flag bit;
Step 5: Generate START condition;
Step 6: Wait until START condition sent by monitoring UCXSTT flag bit;
Step 7: Send STOP condition;
Step 8: Enter Low power mode with interrupt enable and repeat step 4 upto step 8 repeatedly.
ISR_routine:
Copy data from UCB1RXBUF to user defined buffer, if data is available
Exit Low Power mode;
Main program:
Step 1: Configure USCI_B1 module as a master;
Step 2: Put slave address 0x32H into UCB1I2CSA;
Step 3: Enable transmit interrupt;
Step 4: Check for the STOP condition, whether it is sent or not by monitoring UCTXSTP flag bit ;
Step 5: Generate START condition;
Step 6: Enter Low power mode with interrupt enable and remains there.
ISR_routine:
Load data into transmit buffer UCB1TXBUF;
Generate stop condition;
Clear transmit flag UCB1TXIFG;
Exit from low power mode;
VDD 3.3 V
GND GND
INT PIN 2
SYNC X
VIO 3.3 V
CLK X
ASCL X
ASDA X
In order to process data, MSP430 must be configured as master. In order to explain the complete
algorithm to process sensor data, the overall software application must be divided into smaller modules.
There is a need of functions or modules that configures USCI module for I2C communication. We can
categorize these as:
USCI initialization module
Set slave address or data register address into the buffer UCBxI2CSA.
Read single byte operation on I2C bus
Write operation on I2C bus
Once the USCI module is configured as a master then the various operations can be performed.
As per I2C protocol specifications, I2C protocol specifies the method of transaction as per read or writes
operation. Read/write sequence follows the following order:
Start sequence; send start bit
Send slave address of the device, in our case the address is 68H
Send R/W bit; 0 for read from the bus and 1 for write to the bus
Wait for acknowledgement ACK bit or send ACK to slave
Read or Write the data.
Wait or send acknowledgement
Send the stop bit
Set slave address or data register address into the buffer UCBxI2CSA.
The address of slave device or data register can be written with following settings:
Set UCSWRST bit
Place address into buffer UCBxI2CSA
Clear UCSWRST bit
Read single byte operation on I2C bus
It is a good programming practice to check USCI module for stop condition before beginning read or
write operation transaction on I2C bus. This can be achieved by checking UCTxSTP flag; while
(UCBxCLT1 & UCTxSTP);
If it is the first read operation, then with START bit, UCTR bit is set.
UCBxCLT1 | = UCTR + UCTxSTT;
Check that buffer UCBxTxBUF is empty by monitoring IFG2 and UCB0TXIFG flag simultaneously,
then place slave address for transmission. UCBxTXIFG interrupt flag is set by the transmitter to indicate
that UCBxTXBUF is ready to accept another character. UCBxTXIFG is automatically reset if a character
is written to UCxTXBUF or a NACK is received. Whereas UCxRXIFG interrupt flag is set each time a
character is received and loaded into UCBxRXBUF. UCxRXIFG flag is automatically reset if a character
is written to UCBxRXBUF or a NACK is received.
while (!(IFG2&UCB1TXIFG)); // character is transmitted means transmit flag is set,then put SA to
transmit buffer
UCB1TXBUF =SA; // SA is slave address of the device whose data need to be read.
The read operation is always followed by write operation. Therefore, once slave address is transmitted
by setting UCTR bit, we need to wait for the transmission and then perform write operation. For write
operation, UCTR bit must be clear. This can be achieved as:
while (!(IFG2&UCB1TXIFG));
UCB1CTL1 &= ~UCTR; // clear UCTR bit for recieve operation
UCB1CTL1 |= UCTXSTT; // generate repeated start
Before putting slave address or data, one must check the Transmit buffer and then copy the data into
UCBXTxBUF.
while (!(IFG2&UCB0TXIFG));
UCB1TXBUF = slave address or data register address;
After putting data, wait for the transmission and acknowledgement from slave and then place data into
transmit buffer.
while (!(IFG2&UCB1TXIFG));
if(UCB1STAT & UCNACKIFG) return UCB1STAT;
UCB1TXBUF = data;
The UCB1STAT needs to be known to know whether or not the acknowledgement received is from
slave.
If the slave does not acknowledge the transmitted data, the not-acknowledge interrupt flag UCNACKIFG
is set. The master must react with either a STOP condition or a repeated START condition. If this data
should be transmitted after a repeated START, it must be written into UCBxTXBUF again and to trigger
a repeated START, UCTXSTT must be set again.
After this, we need to wait for the transmission to be completed, generate STOP bit and clear the
transmit flag.
while (! (IFG2&UCB0TXIFG));
UCB0CTL1 |= UCTXSTP;
IFG2 &= ~UCB0TXIFG;
Till now, we have discussed the various operations that need to be included in the complete I2C
program. Let us discuss about the internal register details of MPU6050 that need to be configured.
WHO_AM_I register
This register is used to verify the identity of the device. The contents of WHO_AM_I are the upper 6 bits
of the MPU-60X0‟s 7-bit I2C address. The default value of the register is 0x68.
PWR_MGMT_1 Register
With the help of above algorithm, we can get the digitized acceleration values of various sensor modules
for further processing depending upon application requirement.
4.10. Case Study: MSP430 based embedded system application using the interface
protocols for communication with external devices: ―A Low-Power Battery less
Wireless Temperature and Humidity Sensor with Passive Low Frequency RFID‖
The smart weather monitoring systems today are quite sophisticated. They require wireless
measurement of several environmental parameters such as humidity, pressure, temperature etc. For
this wireless measurement system, we need battery-less operations. In this type of applications we
require wireless data and power transfer. We need a set of modules (shown in fig) combined together to
perform this application. Blocks of this system are as follows:
Low frequency RF Interface Device(TMS37157):To establish communication link
Microcontroller(MSP430): To control the whole system
Humidity & Temperature Sensor(SHT21):To sense the environmental parameter
DC/DC Converter(TPS71433):To stabilize the power level
Work Flow:
The operation of whole system starts with the initialization of SPI and I2C. This is because
communication protocols are the backbone of this system either wired or wireless. After getting
instruction from base station, the measurement starts. The power capacitor should be charged before
measurement of each parameter. As the name suggests, the whole system is low power because the
power capacitor is the only source. The overall flow of system can be understood by the flow chart
below:
4.11. Summary
(Inputs required)
4.13. Exercises
The previous chapter covered the process of interfacing the MSP430 with other devices using various
2
serial communication protocols such as UART, I C, SPI for sensor based and data logging
applications. This learning is essential to integrate the MSP430 as part of a larger system of
interconnected devices, which have the ability to communicate to each other over standard protocols .
With this background, the current chapter covers the study of IoT architecture and various wireless
communication protocols to build the IoT applications with MSP430. Readers will also learn about the
building blocks of IoT applications using MSP430 such as smart electric meter created by integrating it
with a Wi-Fi module.
By the end of this chapter, readers can expect to understand wireless communication protocols and its
integration with controllers; acquire knowledge about CC3100 SimpleLink Wi-Fi module and its
architecture and know how to interface CC3100 module with MSP430.
Topic Page
5.1. Introduction ...............................................................................................................................199
5.2. Applications of IOT ...................................................................................................................201
5.3. Architecture of IOT ...................................................................................................................202
5.4. Challenges of IOT.....................................................................................................................203
5.5. Overview of Wireless Sensor Networks and Design Examples ...............................................204
5.6. Relation between WSN & IOT ..................................................................................................205
5.7. Various Wireless Protocols and its Applications ......................................................................208
5.8. Adding Wi-Fi to a Microcontroller-based system using CC3100 Simplelink Wi-Fi module ......222
5.9. Building IoT Applications using CC3100 user API ...................................................................226
5.10. Implementing Wi-Fi Connectivity in a Smart Electric Meter ...................................................228
5.11. Summary ................................................................................................................................229
5.1. Introduction
In this chapter, readers will be introduced to embedded networking technologies such as ZigBee, NFC,
Bluetooth, Wi-Fi etc. These are key elements in designing internet enabled applications such as smart
homes, low power wireless sensor networks, commercial building automation, industrial automation and in
location tracking like asset tracking.
Let‟s take the example of a Wireless Sensor Network, which utilizes the harvested energy that comes
from the energy sources such as wind, heat, light as the main power source. TI MSP430 series devices
are ultra low power MCUs and are a better choice for designing various WSN networks.
This chapter covers wireless sensor network and different wireless protocols that provide connectivity
between smart devices and gateway solutions and related case studies .
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. It is expected that the number of „things‟ connected to IoT will
grow from 20 billion in 2015 to an estimated 200 billion by 2020. The Internet has spread across various
technological platforms and to billions of people in the world. With this spread getting wider, new
technologies and devices have evolved. Examples include smart phones, smart watches and smart
homes equipped with sensing technologies for smart energy, water management etc. The internet lies as
the backbone for all of these devices and technologies. IoT refers to a scenario in which all the real-life
things (including objects, people and animals) are connected to the Internet, and can transfer data over it,
preferably to a cloud. This data can then be used by businesses and people to create a world of new
possibilities and subsequently benefit from it. Fig. 1 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 then sent by the smart
refrigerator on the cloud, where the best deals are offered for online purchase.
IoT can be generically thought of as connecting things to the Internet and using that connection to provide
some kind of useful remote monitoring or control of these things. It is about harmonizing the way humans
interact with devices and the environment using some common public services.
IoT in its culmination can be defined as the one that creates an intelligent, invisible network environment
that can be sensed, controlled and programmed. IoT-enabled products employ embedded technology that
allows them to communicate, directly or indirectly, with each other or the Internet.
Figure 1 IOT Enabled Home with Connected Devices and Appliances working invisibly for
Consumers
Source: www.ti.com/lit/ml/slyb214/slyb214.pdf
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 restricted 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 .
The IoT paradigm discussed may be encountered in a wide variety of venues that span across various
activity circles throughout the day utilizing different kinds of devices . In the personal area network we
encounter wearable devices for entertainment and location tracking . As an example, it can be a Blue*tooth
headset or GPS tracker. These devices enable users to enhance their health and wellness and gather
information around the user. At home, we are surrounded with an ever-growing number of appliances,
multimedia devices and other consumer gadgets. 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.
Users are human participants that use services and their own end equipments . 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, they can be used to carry out actions requested by clients, either users or things.
The different devices and environments needed in IoT can be layered as shown in the Figure 3. 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 dicussed 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.
Connectivity: There is not one connectivity standard that ‗ wins‘ over the others. There is a wide
variety of wired and wireless standards as well as proprietary implementations used to connect
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 require battery power, or need to use energy
harvesting to be more portable and self -sustaining. Line-powered equipment needs 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 have
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 consumers need to be able to set-up and use their devices without a
technical knowledge.
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 around
unknown devices, unknown applications and unknown use cases . Given this, there needs to be
4
flexibility in all facets of development. For example, it requires processors and microcontrollers
that range from 16–1500 MHz to address the full spectrum of applications; right from a
microcontroller (MCU) in a small, energy-harvested wireless sensor node to a 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. Lastly, 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 cause
considerable waste. When it comes to power, the challenge is to ensure that adding Internet connectivity
does not increase power requirement. It should ideally fit within the existing power budget headroom . The
MSP430, being an ultra-low power MCU ensures that the IoT application takes minimal power .
Security: Security is always a challenge in data networks . This challenge intensifies in the case of IoT
simply because there are more entry points, thereby increasing vulnerability. The magnitude of the threat
is also higher since it is not just data that is at risk . With IoT, the damage potential is much higher (e.g.
opening a door remotely by taking a burglar-alarm system offline). Therefore, the fight towards better
security can seem unending. The MSP430 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 quantity of data generated creates 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 MSP430 to provide connectivity that suits the need of the IoT
application.
enable dynamic control that reduces costs and extends capabilities. The main components of WSN
include nodes, gateway and software (refer figure below) . The spatially distributed nodes interface with
sensors to monitor assets or their environment. The acquired data wirelessly transmits to the gateway,
which can operate independently or connect to a host system where you can collect, process, analyze,
and present your measurement data using software. Routers are a special type of node that can be used
to extend WSN distance and reliability.
Figure 4 Energy Harvesting requires ultra-low-power components for all stages of the signal chain
and power management
the heart of any measurement system is the microcontroller unit (MCU) that performs calculations and
controls the system . Wireless sensor nodes require ULP microcontrollers that sleep for long periods —
usually for more than 99 percent of the time—in order to conserve power. An active cycle refers to the
process of waking quickly, performing measurement, running communication and control functions
efficiently and returning to sleep. Because of the large number of potential applications for sensors, the
MCU must include enough peripheral functions to make it flexible. But there needs to be a provision to
turned off the ones that are not in use, to save power.
Smart World
As the Smart Grid is joined by intelligent communication among powered equipments everywhere: in
homes, offices, factories, even outdoors (Figure 6). Such equipment and their networks are themselves
extended by wireless sensor networks that monitor conditions and report to central systems, thus enabling
control over extremely wide areas.
Figure 5 The Smart Grid complemented by many power and sensing networks
Source: http://www.ti.com/lit/ml/sszy008/sszy008.pdf
The design of the power supply subsystem is extremely important in wireless sensor nodes . The energy
source, whether a solar panel, thermal or piezoelectric transducer, or other device, must be supported by
circuitry designed to maximize energy harvesting despite the irregularities of ambient conditions . Energy
storage in a rechargeable battery or super-capacitor, or both, requires careful management in order to
optimize power so that it can be available whenever required. Elements that sense heat, current,
chemicals or other environmental conditions must be sufficiently sensitive for accurate readings, yet not
power-hungry. When all these components are selected to meet the right tradeoffs of functionality and low
power consumption, the sensor node should be capable of functioning autonomously for years .
The WSNs depend on the availability of inexpensive, ultra-low-power components that can harvest
ambient energy, sense local conditions, perform necessary measurement functions, and periodically
communicate information via wireless transmissions. Based on its work with wireless utility meters and
other applications, Texas Instruments has already developed this technology and today offers products
that enable the development of ‗ stick-on‘ sensor nodes for a variety of applications.
NFC is a short-range high frequency wireless communication technology that enables the
exchange of data between devices within a 10 cm distance from each other . NFC is an upgrade to
the existing proximity card standard (RFID) that combines the interface of a smartcard and a
reader into a single device.
It allows users to seamlessly share content between digital devices, pay bills wirelessly or even
use their cell phone as an electronic travelling ticket using existing contactless infrastructure
already in use for public transportation.
The significant advantage of NFC over Bluetooth is the shorter set-up time. Instead of performing
manual configurations to identify Bluetooth devices, the connection between two NFC devices is
th
established at once (under 1/10 of a second).
Due to its shorter range, NFC provides a higher degree of security than Bluetooth and makes
NFC suitable for crowded areas where correlating a signal with its transmitting physical device
(and by extension, its user) might otherwise prove impossible. NFC can also work when one of the
devices is not powered by a battery (e.g. on a phone that may be turned off, a contactless smart
credit card, etc.).
Different types of modes: The different modes of NFC devices are as shown in the Figure 7.
An NFC device can operate in two modes: active, which is battery powered, and passive, which is radio -
energy powered. NFC always involves both an initiator and a target. The initiator generates an RF field
that can power a passive target. This enables NFC targets to take on non-battery operated, simple-form
factors such as tags, stickers, key fobs and cards.
Active communication mode: Both initiator and target device communicate by alternately
generating their own fields . A device deactivates its RF field while it is waiting for data. In this
mode, both devices typically have power supplies.
Passive communication mode: The initiator device provides a carrier field and the target device
answers by modulating the existing field. In this mode, the target device may draw its operating
power from the initiator-provided electromagnetic field, thus making the target device a
transponder.
Limitations of NFC -
Equipment Required – NFC enabled equipment is required, NFC enabled cards and scanners
Cost – Like any advance in technology, there are costs attributed to the development and
implementation of NFC.
Understanding – NFC (at the time of writing) is still a relatively unknown technology even -though it
has been around for a long time. Many people do not know what NFC is, hence do not understand
how to use it.
Technical Limitations – NFC has limitations related to speed, volume of data it can transfer etc.
Security - NFC has built-in security ready applications; but there is still a high risk of fraud;
whereby people who fail to protect their passwords with any encryption or security setting could
easily be targeted by hackers and criminals.
Source: http://www.ti.com/lit/ds/symlink/rf430cl330h.pdf
Source: http://www.ti.com/lit/ds/symlink/rf430cl330h.pdf
Embedded Networking and Internet of Things 211
Key advantages of RF430CL330H Transponder
It is a combination of both wireless NFC interface and wired SPI/I2C interface
Dynamic update of data content supports update of pairing parameters
The NFC uses alternative carriers like BT, BLE, Wi-Fi and RF4CE for pairing process.
Wake up on RF – measurement of current consumption only when the device is in active state.
The firmware requirements for microcontroller are very minimal
NFC also acts as a service interface for firmware update and for data diagnostics
The application support sublayer (APS) is the other main standard component of the layer, and it offers a
well-defined interface and control services. It works as a bridge between the network layer and the other
components of the application layer: it keeps up-to-date binding tables in the form of a database, which
can be used to find appropriate devices depending on the services that are needed and those the
different devices offer. As the union between both specified layers, it also routes messages across the
layers of the protocol stack.
Antenna/RF: The antenna and RF design portion is interesting in that it requires a unique solution for
each device. When purchasing a Bluetooth module for Ericsson, for instance, the antenna is not provided .
Bluetooth silicon manufacturers cannot effectively provide an antenna with the hardware . Even single chip
solutions require specialized antenna design, depending on the device . Antenna design requires
specialized skills to ensure that the Bluetooth radio will operate within its specification.
Bluetooth Radio and Baseband: The Bluetooth radio is the hardware transceiver unit that implements
the Bluetooth radio specification. The purpose of the specification is to provide compatibility between
Bluetooth devices that operate in the 2.4 GHz ISM band, and to define the quality of the system . Further
information on the Bluetooth radio specifications may be found in the Bluetooth core specification
document.
The Bluetooth baseband consists mainly of a Link Controller (LC) that carries out baseband protocols and
low-layer link routines. Protocols defined within the scope of the baseband specification include physical
channels and links, data packet definitions, error correction and detection, logical channels, channel
control, and hop selection among others . For more information about the Bluetooth baseband
specification, see the Bluetooth core specification document.
An example implementation of the Bluetooth radio and baseband is the Ericsson Bluetooth Module . In
addition to the hardware, this module contains the firmware that implements the baseband specifications .
As one would expect, there are a number of other manufacturers developing Bluetooth modules too.
Bluetooth Software Protocol Stack: The Bluetooth software protocol stack can be thought of as driver
code. This code allows the application software to send and receive information from the Bluetooth
module. Several implementations of this currently exist, and vary from GNU licensed code to commercial
products targeted at various operating systems.
Data and voice access points: Bluetooth facilitates real-time voice and data transmissions by
providing effortless wireless connection of portable and stationary communications devices.
Cable replacement: Bluetooth eliminates the need for numerous, often proprietary cable
attachments for connection of practically any kind of communications device . Connections are
instant and are maintained even when devices are not within line of sight . The range of each radio
is approximately 10 m, but can be extended to 100 m with an optional amplifier .
Ad hoc networking: A device equipped with a Bluetooth radio can establish instant connection to
another Bluetooth radio as soon as it comes into range.
Limitations
Data Transfer Rate
Range
Security
Battery Use
Bluetooth Low Energy
Bluetooth low energy (Bluetooth LE, BLE, marketed as Bluetooth Smart) is a wireless personal area
network technology designed and marketed by the Bluetooth Special Interest Group aimed at novel
applications in healthcare, fitness, beacons, security and home entertainment industries . Compared to
Classic, Bluetooth Smart is intended to provide considerably reduced power consumption and cost while
maintaining a similar communication range.
While many wireless options exist, Wi-Fi has quickly become the de facto standard for wireless embedded
systems because of its global acceptance and interoperability. Additionally, with the availability of low-
power, self-contained, industry-certified solutions, Wi-Fi fits into many markets; including those with mobile
and battery-powered requirements.
Components:
Embedded systems for a large variety of applications--including appliances, automation systems, medical
devices, entertainment systems, and energy management--today already use or can potentially use a
wireless interface.
Limitations
Security
Range
Reliability
Speed
5.8. Adding Wi-Fi to a Microcontroller-based system using cc3100 Simplelink Wi-Fi module
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 users
and embedded systems. For example, a user can interact with utility systems (such as AC, Garage door,
Coffee machine etc.) in a smart-home using a smartphone, provided both (smart-home and smartphone)
are connected to the internet.
Texas Instruments 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 . Texas Instruments‟ SimpleLink 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 Fig. 9.
Dedicated ARM MCU – It executes the Wi-Fi and Internet protocols required to communicate over
the Internet using Wi-Fi connectivity.
ROM – stores pre-programmed Wi-Fi driver and multiple Internet protocols
TCP/IP Stack – supports communication with computer systems on the Internet
Crypto Engine – provides fast, and secure Wi-Fi as well as Internet connectivity
802.11 b/g/n Radio, Baseband and Medium Access Control - for wireless transmission and
reception of data
SPI/ UART Interface – connects the CC3100
module to the host MCU.
The Wi-Fi network processor sub-system in the 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 in
Table-1 below.
Table-1 Wi-Fi Features supported by SimpleLink CC3100 module
5.8.2. CC3100 SimpleLink Driver and its Application Programming Interface (API)
In order to simplify development using the SimpleLink Wi-Fi devices, TI provides a simple and user
friendly host driver software. This driver software allows any MCU (like TIVA platform ) to interact with a
SimpleLink device and performs the following functions:
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,
acquiringthe 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
ofnetworking or user proprietary data.
WLAN connection – The physical interface needs to be established. There are numerous ways to
do so, all of which will be explained in this document. The simplest way is to manually connect to
an AP as a wireless station.
DHCP – Although not an integral part of the WLAN connection, you need to wait for the receiving
IP address before continuing to the next step of working with TCP\UDP sockets.
Socket connection – At this point, it is up to the application to set up its TCP\IP layer. This phase
can be broken down into the following parts:
o Creating the socket – Choosing to use TCP, UDP or RAW sockets, whether to use a
client or a server socket, defining socket characteristics such as blocking\non-blocking,
socket timeouts, and so forth.
o Querying for the server IP address – On most occasions, when implementing a client
side communication, you will not know the remote server side IP address, which is
required for establishing the socket connection. This can be done by using DNS protocol
to query the server IPaddress by using the server name.
o Creating socket connection – When using the TCP socket, it is required to establish a
proper socket connection before continuing to perform data transaction .
Data transactions – Once the socket connection is established, it is possible to transmit data
both ways between the client and the server; basically implementing the application logic.
Socket disconnection – Upon finishing the required data transactions, it is recommended to
perform a graceful closure of the socket communication channel.
Wi-Fi subsystem hibernate – When not working with the Wi-Fi subsystem for a long period of
time, it is recommended to put it into hibernate mode.
Case Study IV: Configuration of CC3100 as a WLAN station by interfacing with MSP430F5529.
This case study demonstrates interfacing the MSP430 with CC3100 WiFi module. The following code
attempts to configure CC3100 Booster Pack as a Wireless Local Area Network (WLAN) Station and
connect to a Wi-Fi access-point. The application connects to an Access-Point and pings the gateway. It
also checks for internet connectivity by pinging the website www.ti.com.
This case study demonstrates a three-phase energy meter with Wi-Fi connectivity. The three-phase
energy meter is used to perform all metrology functions like RMS current, RMS voltage, power factor,
frequency, active and reactive power and energies and to control the SimpleLink ™ Wi-Fi transceiver. The
smart meter data can then be displayed on any Wi-Fi connected device via a standard web browser.
In this case study TI‟s EVM430-F6779 3-phase current meter is used to measure all metrology functions.
The measured energy consumption is displayed on the LCD every two seconds. For every parameter or
metrology function, the metering is displayed on the LCD. In addition to displaying the metrology results
on the LCD, the LCD is also used to display the Wi-Fi status.
5.11. Summary
In this chapter we covered the concept of Internet of Things and how the MSP430 microcontroller helps in
realizing IoT applications. The concept of IoT is synonymous to connectivity. TI offers a wide-range of
connectivity modules based on different wireless technologies to interface with the MSP430. The vast
array of modules compatible with the MSP430 ensures that every IoT application makes use of the
wireless technology that best suits the particular IoT application.
The potential that IoT offers is limitless, and the MSP430 and TI‖ s portfolio of wireless modules are ideal
candidates for diverse IoT applications.
5.13. Exercises