Serial versus Parallel Data Transfers 1 SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA
Serial communications Most communications is carried out over serial links Fewer wires needed Less electronics needed Must run faster Examples Ethernet USB Universal Serial Bus USART Universal Synchronous and Asynchronous serial All available in Receiver and Transmitter (RS232/COM ports) ATmega128 as onchip peripherals I 2 C Inter Integrated Circuit SPI Serial Peripheral Interface 2
Parallel or serial? Convert numbers expressed in terms of several bits (many signal lines) into a stream of 0s, 1s on a single line (and a Clock). Advantage: A convenient way to reduce the number of Electrical signal lines by factors of 8, 16, 32, 64. 3 Disadvantage: For the same transfer rate the electronics must be faster by factors of 8, 16, 32, 64.
A shift register converts 4-bit parallel to serial 4 When Parallel load is set, the S/R bits on the Flip Flops are arranged to latch in the bits on the data bus (1 bit on each Flip Flop) On each rising edge of the clock, The Data on the Flip Flops is put on the Q (Output Line), which appears at the input of the next flip flop. The input data is latched, and the bits move from one FF to the next It takes 4 clock cycles to move the 4 bits out to the serial ouput line A Four Bit Shift Register Composed of 4 D-Flip-Flops Parallel to Serial Conversion
Data is placed on the parallel data bus PL: Data Loaded into Flip Flops On Clock edge Data is shifted from output of each FF to the Input of the next NEILNEIL - Microprocessor Course 5
8 Bit Parallel to Serial Shift Register 6
Parallel to Serial Conversion: Parallel load a number then clock it out 7 clock D0 D1 D2 D3 D4 D5 D6 D7 Output 0 1 1 0 1 1 0 1 1 1 Tick 1 1 0 1 1 0 1 1 2 Ticks 1 1 0 1 1 0 1 3 Ticks 1 1 0 1 1 0 4 Ticks 1 1 0 1 1 5 Ticks 1 1 0 1 6 Ticks 1 1 0 7 Ticks 1 1 8 Ticks 1
Serial to Parallel shift register At each clock transition, the data is shifted to the next flip-flop in the chain We need to keep track of how many clock pulses we have sent to know when the full byte is on the outputs 8
Suppose you feed a 1 : 9 D0 D1 D2 D3 D4 D5 D6 D7 0 0 0 0 0 0 0 0 0 1T 1 0 0 0 0 0 0 0 2T 1 1 0 0 0 0 0 0 3T 1 1 1 0 0 0 0 0 4T 1 1 1 1 0 0 0 0 5T 1 1 1 1 1 0 0 0 6T 1 1 1 1 1 1 0 0 7T 1 1 1 1 1 1 1 0 8T 1 1 1 1 1 1 1 1
10 Serial/parallel peripheral module on AVR There are several different peripheral functional units on the AVR which you can use. The Serial Peripheral Interface (SPI) unit allows the AVR to communicate to external devices using a simple serial protocol. M. Neil - Microprocessor Course
11 SPI module on AVR At the heart of the SPI module is a shift register. You can write parallel 8- bit data to the SPI module which is then automatically clocked out through the shift register to external pins. The SPI unit can also read in serial data from external pins and present it as parallel 8-bit data to your program. M. Neil - Microprocessor Course
SPI timing diagram 12 Note that as well as selecting clock polarity, you can also select whether the MSB or the LSB is output first!
The 74HC164 Shift Register: Serial to Parallel Serial Data In 13 Clock *Reset Parallel out
74HC164 Function Table 14
SPI code example SPI_MasterInit: ; Set MOSI and SCK output, SS* also as output, all others input ldi r17,(1<<ddb2) (1<<DDB1) (1<<DDB0) out DDRB,r17 ; Enable SPI, Master, set clock rate fck/16 ldi r17,(1<<spe) (1<<MSTR) (1<<SPR0) out SPCR,r17 ret SPI_MasterTransmit: ; Start transmission of data (held in r16) out SPDR,r16 Wait_Transmit: ; Wait for transmission to complete sbis SPSR,SPIF rjmp Wait_Transmit ret 15
High Level Design 16 The Project: Parallel To Serial 8-Bits of data (Parallel) ATmega128 SPI 8-Bits of data (Serial) PORTB Data Clock Serial to Parallel 8-bit Serial Data Shift Register 74HC164 8-Bits of data (Parallel) LEDs
17 Low Level Design Wire up LEDs so that you can see the data arrive on the output Wire up a switch to the MR* line to allow you to clear the Shift Register outputs (make sure you understand how this works) Data: PORTB2 (MOSI) 2 1 8 Q7 DSB Q6 Q5 DSA Q4 Q3 Q2 Q1 Q0 CP MR 74HC164 13 12 11 10 6 5 4 3 9 LEDs to read output VCC The clock and data bits should come from the SPI outputs that can be found on PORTB Clock: PORTB1 (SCK) 1.0k VCC
The Serial Link Test Program 18 Start Send new pattern to SPI Delay several seconds SPI Clocks the data 8 times into 164 using PORTB Look at the LEDs
Task Plan: Construct a device that will turn 8-bit parallel data into serial data + clock using the on-chip SPI peripheral. 19 Construct a device that will receive serial data, convert them to parallel data and display them using LEDs. Write a program that will send several patterns down your serial link and demonstrate that it works.