Professional Documents
Culture Documents
Module 5 Lavanya Notes
Module 5 Lavanya Notes
Advantages Disadvantages
Full duplex. But only one data line (slave) is More pins(4 wires) than UART & I2C
active at a time
Higher speed (25 Mbps) than UART + I2C Short distances(20 cm) Vs RS-232/ RS-485
Not limited to 8-bit words Several variants like dual SPI, quad SPI etc..
Lower power requirement No error-checking protocol is defined
Extremely simple hardware interfacing No hardware slave acknowledgment
Concept of SPI
It is the simplest synchronous serial communication protocol introduced by Motorola for
short-distance communication. It is also called four-wire bus. SPI devices communicate
in full duplex mode using master-slave architecture. The embedded controller is the master
& the other device such as the ADC or flash memory could serve as the receiver.
The SPI bus specifies four logic signals:
SCLK: Serial Clock. This is initiated by the
master device whenever data transmission
is required.
MOSI: Master Output Slave Input
MISO: Master Input Slave Output
Master configures the clock, using a
frequency supported by the slave device,
typically up to a few MHz.
Usually eight-bit words are transmitted using two shift registers connected in a ring
topology as shown in the figure. During each clock cycle master sends a bit on the MOSI line
Phase:
If CPHA =0, the next bit of
data transition takes place
during the trailing edge of
clock
If CPHA =1, the next bit of
data transition takes place
during the rising edge of
clock
Depending on the combination of polarity & phase bits, there are 4 modes of SPI operation
Mode CPOL CPHA
0 0 0
1 0 1
2 1 0
3 1 1
SPI Operation:
SPI is one master and multi slave communication interface. It can be used in Independent
slave configuration & Daisy Chain configurations as shown in Fig below.
In Daisy Chain Configuration, MISO pins of the first slave is connected the MOSI pin of the
second slave so on. Each slave copies input to output in the next clock cycle until S̅S̅ =1.
Advantage of this configuration is that it requires only a single SS line from the master,
rather than several lines for each slave.
Bit Banging:
If no hardware is available, slow communication can be achieved by driving the pins using
software. This is known as bit-banging and is helpful for asynchronous serial
communication. Here the signals has to be controlled by software & is assisted by Timer_A
For a 9600 baud rate, bit time = 1/ 9600 = 104.17 µs considering that the MSP430 is working
on ACLK = 32768 Hz, the clock bit time = 1/32768 = 30.517 µs. simply multiplying this clock
bit time by an integer factor will not give the exact bit time. (i.e 3 × 30.517 µs = 91.55 µs or 4
× 30.517 µs = 122.07 µs, but not exactly 104.17 as required). This introduces cumulative
error. Modulation minimizes this cumulative error. Asynchronous communication is usually
used between separate pieces of equipment. Therefore an interface is needed between the
UART in the microcontroller and the outside world. This is where RS-232 comes in.
R in R out
RXD
Micro
MAX232
controller T out
T in
TXD
We want fBITCLK16 =16 fbaud =16×9600 = 153.6 KHz. With fBRCLK= 220 Hz, the divider/pre-scaler
should use a factor of 220 Hz / 153, 600 = 6.83. So the value 0006h is set for UBAxBR0 &
UCAxBR1 and the modulation index of 0D is set for UCBRFx to get a closer value.
UxBR1 | UxBR0 | UxMCTL= 00h | 06h | 7D h ; where 0D is the modulation pattern. In most
cases this procedure brings fBITCLK close enough to fbaud. If it does not, it is also possible to
modulate the second division from BITCLK16 to BITCLK by using UCBRSx
The equation to find UCBRx & UCBRFx is given by:
nint (fBRCLK / fbaud) = (16 – UCBRFx) UCBRx + UCBRFx (UCBRx +1) = 16 UCBRx +UCBRFx
nint (220 / 9600) = (16-13)6 + 13 (6 +1)
nint (109) = 18 + 91 = 109
The divider UCBRx and the modulation index UCBRSx are given by:
nint(8 × fBRCLK / fbaud ) = (8−UCBRSx) UCBRx + UCBRSx (UCBRx+1) = 8UCBRx + UCBRSx.
Considering ACLK =32 KHz,
nint ((8 × 32000) / 9600 ) = 8UCBRx + UCBRSx
nint (26.66) = (8 × 3) + 4
27 = 27
Hence UCBRx = 3 & UCBRSx =4
Interrupts in USCI_A
Once configured, a character for transmission is written to UCA0TXBUF after checking that
the flag UCA0TXIFG is raised. Similarly, the flag UCA0RXIFG is raised when a new character
has been received and is available in UCA0RXBUF. There is usually no way of telling the
remote transmitter to pause so it is important to read the buffer promptly before it is
overwritten. The overrun flag UCOE is raised if this happens.
P1.7
Then when P1OUT|=0x80, high is written on P1.7
PxOUT performs 2 functions:
• If port is configured as GIPO & direction is set as o/p, then P1OUT holds logical high/low status
based on what is written to PxOUT
But in MSP430, pull up/ pull down are inbuilt and are selected based on status of P1DIR, P1REN &
P1OUT. Example: