Unit - 4: 4.1. Serial Data Communication - Basics
Unit - 4: 4.1. Serial Data Communication - Basics
UNIT – 4
Within a micro-computer system, the data transfer is in parallel because it is the fastest
method. But transferring the data over long distances, the parallel data transmission requires too
many wires and it is complicated and expensive. Therefore, the data to be sent for long distances is
converted into serial form so that it can be sent on a single wire. At the destination, the received
serial data is converted into parallel form so that it can be easily transferred on the micro-
computer buses.
(i) Simplex :
(ii) Half-dupplex :
(iii) Full-dupplex :
Transmitter and Receiver are operated with Transmitter and Receiver can operated with
same CLK frequency. different CLK frequency.
SYNC pulses are required START and STOP bits are required
A group of characters can be transmitted For each character, the START & STOP bits
after sending the SYNC pulses are required.
It is used in high speed data transmission It is used in low speed data transmission
Generally used between CPU and other It is used to exchange data with other
devices on the same PCB, as the same power equipment such as PC.
supply and CLK are used.
The universal serial communication interface (USCI) module of MSP430 support multiple serial
communication modes. The THREE common types of serial communication are
The asynchronous systems must conform fully to established standards so that they work
reliably and must be protected against electromagnetic interference and other hazards. This
requires special interface circuits. On the other hand, simple wires are usually sufficient for SPI
and I²C provided that all devices work at the same voltage.
SPI and I²C are synchronous, which means that a clock signal is sent along with the data. The
device that generates the clock is called the master and other devices are slaves. An extra wire
carries the clock.
Transmission and reception are essentially separate processes and can take place together,
giving full-duplex communication.
The major practical difference is that SPI and I²C are typically used between a microcontroller
and other devices on the same PCB, while asynchronous communication is used to exchange
data with other equipment such as a PC.
The major difference between them is that I²C is a true bus, which is designed to accommodate
a large number of devices. Transactions follow a protocol that starts with an address to select a
particular slave and includes acknowledgment bits to confirm successful delivery. There is
only one wire for data, giving a total of two with the clock. Data can travel in either direction
but only in one way at a time, which is called half-duplex transmission.
In contrast, SPI uses two lines for data so that information can be sent simultaneously in both
directions. In fact both processes must occur together because of the concept that underlies SPI.
The full version of SPI includes a further line that is used to select a particular slave and gives
a total of four wires for the interface. The SPI needs more wires than I²C and offers less
sophistication but is simpler and faster. This makes SPI more suitable when large amounts of
data have to be transferred.
SPI and I²C have similar applications. SPI and I²C are often used to communicate with
Port expanders to increase the effective no. of pins for digital input and output.
ADCs and DACs.
Sensors with digital outputs, such as thermometers.
External memory (dataflash, EEPROM).
Real-time clocks.
Other processors.
The universal asynchronous receiver/transmitter (UART) takes bytes of data and transmits
the individual bits in a sequential fashion. At the destination, a second UART re-assembles the bits
into complete bytes. Each UART contains a shift register, which is the fundamental method of
conversion between serial and parallel forms.
The UART character format, shown in below Figure , consists of a start bit, seven or eight data
bits, an even/odd/no parity bit, an address bit (address-bit mode), and one or two stop bits. The
UCMSB bit controls the direction of the transfer and selects LSB or MSB first. In most applications
the least significant data bit (LSB) is transmitted first.
The start bit signals the receiver that a new character is coming. The next bits represent the
character. If a parity bit is used, it would be placed after all of the data bits. The next one or two
bits are always in the mark (logic high, i.e., '1') condition and called the stop bit(s). They signal the
receiver that the character is completed. Since the start bit is logic low (0) and the stop bit is logic
high (1) there are always at least two guaranteed signal changes between characters.
All operations of the UART hardware are controlled by a clock signal which runs at a
multiple of the data rate, typically 8 times the bit rate. The receiver tests the state of the incoming
signal on each clock pulse, looking for the beginning of the start bit.
The baud rate gives the frequency at which bits are transmitted on the line. It is the inverse
of the bit period and the name is used to distinguish it from the rate at which useful data
are communicated. If the baud rate is „x‟ bits per second, the time slot available for one bit
is 1/x seconds.
Each 8 bits of data are accompanied by a start and stop bit so the maximum data rate is
only 8/10 of the baud rate.
The division factor N is often a non-integer value, thus, at least one divider and one
modulator stage is used to meet the factor as closely as possible.
The USCI module automatically detects framing errors, parity errors, overrun errors, and
break conditions when receiving characters. The bits UCFE, UCPE, UCOE, and UCBRK are
set when their respective condition is detected. When the error flags UCFE, UCPE, or
UCOE are set, UCRXERR is also set.
Framing error UCFE Framing error occurs when a low stop bit is detected
Parity error is mismatch between the no.of 1‟s in a
Parity error UCPE
character and the value of parity bit.
Overrun error occurs when a character is loaded into
Over run error UCOE
UCARxBUF before the prior character has be read.
When not using automatic baud-rate detection, a break is
Break condition UCBRK
detected when all data, parity and stop bits are LOW.
This register controls the settings for Parity selection, direction of data transmission (LSB or
MSB first),character length, no of stop bits, modes of serial transmission.
7 6 5 4 3 2 1 0
0 Disables Parity
Bit 7 UCPEN Parity enable
1 Enables Parity
0 Odd parity
Bit 6 UCPAR Parity select
1 Even parity
0 LSB first
Bit 5 UCMSB MSB first select.
1 MSB first
0 8-bit data
Bit 4 UC7BIT Character length
1 7-bit data
If UCSYNC = 0 then
00 UART mode
Bit 2-1 UCMODEx USCI mode.
01 Idle-line multiprocessor mode
10 Address-bit multiprocessor mode
11 UART mode with automatic baud-rate detection
The serial peripheral interface (SPI) was introduced by Motorola and is the simplest
synchronous full duplex communication protocol.
SPI is a single master multi-slave system.
SPI requires 4- signal lines for communication. They are :
MOSI : Master out slave in signal line carries the data from Master to Slave device
It is also called as Slave data in (SDI) / Slave input (SI) /Data in (DI)
MISO : Master in slave out signal line carries the data from Slave to Master device
It is also called as Slave data out (SDO) /Slave output (SO) / Data out (DO)
SS : Slave Select signal is used for slave device select. Usually it is active LOW signal
The SPI requires four wires (plus ground, which is essential but never counted) and transmits data
simultaneously in both directions (full duplex) between two devices. One device is the master and
the other the slave. The master provides the clock for both devices and a signal to select (enable)
the slave, but the path followed by the data is identical in each.
SPI works on the principle of „Shift Registers‟. The master and slave devices contain a special shift
register for the data transmit and receive. During transmission from master to slave, the data in
the master‟s shift register is shifted out to the MOSI pin and it enters the slave‟s shift register
through MOSI pin. At the same time, the shifted out data bit from the slave‟s shift register enters
the master‟s shift register. In summary, the shift registers of master and slave devices form a
circular buffer (loop).
The concept of SPI is based on two shift registers, one in each device, which are connected to form
a loop. The registers usually hold 8 bits. Each device places a new bit on its output from the most
significant bit (MSB) of the shift register when the clock has a negative edge and reads its input
into the LSB of the shift register on a positive edge of the clock.
Thus a bit is transferred in each direction during each clock cycle. After eight cycles the contents of
the shift registers have been exchanged and the transfer is complete. Transmission and reception
are clearly inseparable: we can‟t do one without the other, at least in principle. Thus a byte must
be transmitted in order to receive a byte.
Thus CPHA controls whether writing and reading take place on the leading and trailing edges of
the clock pulses or vice versa. This is the first of many options that control the configuration of
SPI. A related option is the clock polarity, selected with the CPOL bit:
There is no fundamental difference between these two polarities: One is just the complement of
the other. Combinations of the two bits CPOL and CPHA give four standard modes for the clock
in SPI, which are listed in the following Table.
The following figures illustrate complete waveforms for a 4-bit transfer in modes 0 and 3.
There are two ways of connecting multiple slaves to a single master. In both cases the master
provides the clock to all the slaves. Slaves can be addressed individually.
In the first configuration, all the MOSI pins are connected together, but each slave‟s SS pin is
connected to a separate pin on the master. Slaves must ignore data on MOSI when their SS pin is
idle, despite the activity on the clock, and must leave their MISO pins in a high-impedance state.
In other words, the MISO pins must have three-state outputs.
The alternative is to connect all the devices in a “daisy chain,” as shown in Figure(b). In this
configuration, the MISO pin of a slave is connected to the MOSI pin of the next slave in the chain.
The MOSI pin of the final slave is connected to MOSI on the master. Effectively all the shift
registers inside each device are connected into a single, long loop. The slaves must allow data to
be clocked through them transparently while SS is held active and react to the new data only
when SS is released.
In SPI mode, serial data is transmitted and received by multiple devices using a shared clock
provided by the master. An additional pin, UCxSTE, is provided to enable a device to receive and
transmit data and is controlled by the master. 3 (or) 4 signals are used for SPI data exchange:
Master Mode :
The above figure shows the USCI as a master in both 3-pin and 4-pin configurations. The USCI
initiates data transfer when data is moved to the transmit data buffer UCxTXBUF.
The UCxTXBUF data is moved to the TX shift register when the TX shift register is empty,
initiating data transfer on UCxSIMO starting with either the MSB bit or LSB bit depending on
the UCMSB setting.
Data on UCxSOMI is shifted into the receive shift register on the opposite clock edge.
When the character is received, the receive data is moved from the RX shift register to the
received data buffer UCxRXBUF and the receive interrupt flag (UCxRXIFG) is set, indicating
the RX/TX operation is complete.
A set transmit interrupt flag (UCxTXIFG) indicates that data has moved from UCxTXBUF to
the TX shift register and UCxTXBUF is ready for new data. It does not indicate RX/TX
completion.
Slave Mode :
The above figure shows the USCI as a slave in both 3-pin and 4-pin configurations.
UCxCLK is used as the input for the SPI clock and must be supplied by the external master.
The data-transfer rate is determined by this clock and not by the internal bit clock generator.
Data written to UCxTXBUF and moved to the TX shift register before the start of UCxCLK is
transmitted on UCxSOMI.
Data on UCxSIMO is shifted into the receive shift register on the opposite edge of UCxCLK
and moved to UCxRXBUF when the set number of bits are received. When data is moved from
the RX shift register to UCxRXBUF, the UCxRXIFG interrupt flag is set, indicating that data
has been received.
The overrun error bit, UCOE, is set when the previously received data is not read from
UCxRXBUF before new data is moved to UCxRXBUF.
7 6 5 4 3 2 1 0
0 LSB first
Bit 5 UCMSB MSB first select
1 MSB first
0 8-bit data
Bit 4 UC7BIT Character length
1 7-bit data
0 Slave mode
Bit 3 UCMST Master mode select
1 Master mode
If UNSYNC = 1 then
00 3-pin SPI
Bit 2-1 UCMODEx USCI mode.
01 4-pin SPI with UCSTE active high
10 4-pin SPI with UCSTE active high
11 I2C
The electronic interface to the I²C bus is shown in Figure 10.11 for a master and two slaves.
A full-featured slave has the same hardware as a master but most are simpler and cannot
drive the clock line SCL.
On the other hand, slaves must always be able to drive SDA.
Digital outputs are normally driven actively for both their binary values, either to VSS for
logic 0 or to VCC for logic 1.
Pull-up resistors Rp keep the lines at VCC when none of the drivers is active. The devices
must therefore have open-drain (or open-collector) outputs. This means that there is only an
n-channel MOSFET between the output and ground as in Figure 10.11.
The pull-up resistor Rp holds the line at VCC when there is no activity, so both the clock
and data idle high. If a single n-MOSFET is turned on, its line is pulled down to VSS to
give a logical 0.
In I2C mode, the USCI module provides an interface between the MSP430 and I2C-
compatible devices connected by way of the two-wire I2C serial bus. External components
attached to the I2C bus serially transmit and/or receive serial data to/from the USCI
module through the 2-wire I2C interface.
The I2C mode features include:
1. 7-bit and 10-bit device addressing modes
2. General call
3. START/RESTART/STOP
4. Multi-master transmitter/receiver mode
5. Slave receiver/transmitter mode
6. Standard mode up to 100 kbps and fast mode up to 400 kbps support
7. Programmable UCxCLK frequency in master mode
8. Designed for low power
9. Slave receiver START detection for auto-wake up from LPMx modes
10. Slave operation in LPM4
I²C Protocol
A simple example of a transfer on I²C is shown in Figure 10.12, where the master reads a
single byte from the slave.
Transfers consist of a sequence of 8-bit bytes, which are sent with the MSB first and must
be acknowledged to confirm successful reception. The recipient does this by writing a
further acknowledgment (A) bit of 0 to SDA.
1. The master sends a start condition (S) by pulling SDA low while SCL is high.
2. The master starts the clock and puts the first bit of the address on SDA after SCL has gone low.
3. The value on SDA is valid after SCL has gone high and is read by all slaves on the bus.
4. The last two steps are repeated until all 7 bits of the address have been sent.
5. The final bit of the first byte specifies the direction for the rest of the transfer. Here it is R/W= 1,
which shows that the master wishes to read data from the slave.
6. The ninth bit is the acknowledgment (A or Ack), which is low and is sent by the slave that
recognizes its address.
7. The master must check that a slave acknowledges the address and abort the transfer if the low
bit is missing.
8. The next 8 clock cycles are used to transmit 1 byte of data from the slave to the master. The
master continues to provide the clock.
9. The 9th bit would normally be an acknowledgment bit, which signals to the slave that the
master has received sufficient data.
10. There is a final cycle of the clock to set up the stop signal (P). The master sends a stop
condition (S) by pulling SDA high while SCL is high.
Thus transfers
Begin with a start condition (S), shown by a falling edge on SDA while SCL is high.
End with a stop condition (P), shown by a rising edge on SDA while SCL is high.
Both the SCL and SDA lines are high before a start condition and after a stop condition,
which is the idle state of the bus
7 6 5 4 3 2 1 0
0 Slave mode
Bit 3 UCMST Master mode select
1 Master mode
If UNSYNC = 1 then
00 3-pin SPI
Bit 2-1 UCMODEx USCI mode.
01 4-pin SPI with UCSTE active high
10 4-pin SPI with UCSTE active high
11 I2C