Presentation is loading. Please wait.

Presentation is loading. Please wait.

SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA Mark Neil - Microprocessor Course 1 Serial versus Parallel Data Transfers.

Similar presentations


Presentation on theme: "SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA Mark Neil - Microprocessor Course 1 Serial versus Parallel Data Transfers."— Presentation transcript:

1 SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA Mark Neil - Microprocessor Course 1 Serial versus Parallel Data Transfers

2 Serial communications Mark Neil - Microprocessor Course 2 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 Receiver and Transmitter (RS232/COM ports)  I 2 C – Inter Integrated Circuit  SPI – Serial Peripheral Interface All available in ATmega128 as “on- chip peripherals”

3 Shift Registers Mark Neil - Microprocessor Course 3 Shift Registers convert numbers expressed in terms of several bits (many signal lines) into a stream of 0s, 1s and a Clock.  Advantage: A convenient way to reduce the number of Electrical signal lines by factors of 8, 16, 32, 64.  Disadvantage: For the same transfer rate the electronics must be faster by factors of 8, 16, 32, 64.

4 A Four Bit Shift Register Composed of 4 D-Flip-Flops Parallel to Serial Conversion This Shift Register converts data on a 4 bit parallel data bus into a serial bit stream 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 Mark Neil - Microprocessor Course 4

5 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

6 8 Bit Parallel to Serial Shift Register Mark Neil - Microprocessor Course 6

7 Parallel to Serial Conversion: Parallel load a number then clock it out Mark Neil - Microprocessor Course 7

8 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 Mark Neil - Microprocessor Course 8

9 Suppose you feed a ‘1’: Mark Neil - Microprocessor Course 9

10 The 74HC164 Shift Register: Serial to Parallel Mark Neil - Microprocessor Course 10 Serial Data In Serial Data In *Reset Parallel out Parallel out Clock

11 74HC164 Function Table Mark Neil - Microprocessor Course 11

12 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 12

13 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 13

14 SPI timing diagram Mark Neil - Microprocessor Course 14 Note that as well as selecting clock polarity, you can also select whether the MSB or the LSB is output first!

15 SPI code example Mark Neil - Microprocessor Course 15 SPI_MasterInit: ; Set MOSI and SCK output, SS* also as output, all others input ldi r17,(1<

16 High Level Design Mark Neil - Microprocessor Course 16 The Project: 8-bit Serial Data ATmega128 Parallel To Serial PORTB Data Clock SPI Shift Register 74HC164 Shift Register 74HC164 8-Bits of data (Parallel) Serial to Parallel Serial to Parallel 8-Bits of data (Serial) 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) The clock and data bits should come from PORTB 17 Mark Neil - Microprocessor Course Data: PORTB2 (MOSI) Clock: PORTB1 (SCK)

18 The Serial Link Test Program Mark Neil - Microprocessor Course 18 Start Delay several seconds Delay several seconds Send new pattern to SPI SPI Clocks the data 8 times into 164 using PORTB SPI Clocks the data 8 times into 164 using PORTB Look at the LEDs Look at the LEDs

19 Task Plan: Mark Neil - Microprocessor Course 19 Construct a device that will turn 8-bit parallel data into serial data + clock using the on-chip SPI peripheral. 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.


Download ppt "SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA Mark Neil - Microprocessor Course 1 Serial versus Parallel Data Transfers."

Similar presentations


Ads by Google