SPI Serial Port (in AVR Microcontrollers)
Microprocessors , Lecture 7:
SPI Serial Port (in AVR Microcontrollers) Contents Serial - - PowerPoint PPT Presentation
Microprocessors , Lecture 7: SPI Serial Port (in AVR Microcontrollers) Contents Serial communication with SPI Serial communication programming in C Reference: Chapter 17 of the Mazidis book University of Tehran 2 Serial ports
Microprocessors , Lecture 7:
University of Tehran 2
University of Tehran 3
University of Tehran 4
University of Tehran 5
University of Tehran 6
University of Tehran 7
– SCLK and CE, and only a single pin for data transfer
and SDO data pins are tied together
University of Tehran 8
slave side
– generates the clock for the shift registers
University of Tehran 9
slave shift register by MOSI (Master Out Slave In)
slave shift register by MISO (Master In Slave Out)
interchanged
University of Tehran 10
– SS=0: enable slave – SS=1: disable slave – Active low!
University of Tehran 11
– CPOL (clock polarity) – CPHA (clock phase)
University of Tehran 12
– CPOL (clock polarity) – CPHA (clock phase)
University of Tehran 13
University of Tehran 14
University of Tehran 15
University of Tehran 16
University of Tehran 17
University of Tehran 18
University of Tehran 19
– Just write data to SPDR – 8 clocks are generated automatically to transfer data – Slave can never start sending data
– First send address (and also tell if the transfer is read or write), then send/receive data
University of Tehran 20
– Make CE = 0 to begin writing – The 8-bit address is shifted in, one bit at a time, with each edge of SCLK » A7 = 1 for the write operation – After all 8 bits of the address are sent in, the SPI device expects to receive the data belonging to that address location immediately – The 8-bit data is shifted in one bit at a time, with each edge of the SCLK – Make CE = 1 to indicate the end of the write cycle
University of Tehran 21
– The SPI device internally increments the address location as long as CE is LOW
University of Tehran 22
– Make CE = 0 to begin reading – The 8-bit address is shifted in one bit at a time, with each edge of SCLK
» A7 = 0 for the read operation
– After all 8 bits of the address are sent in, the SPI device sends out data belonging to that location – The 8-bit data is shifted out one bit at a time, with each edge
– Make CE = 1 to indicate the end of the read cycle
University of Tehran 23
University of Tehran 24
University of Tehran 25
CLCK frequency = Fosc/l6, and then transmit 'G' via SPI
University of Tehran 26
CLCK frequency = Fosc/4, and then show the received data on Port D
DDRB=0001,0000 // MISO as output other pins input DDRD=0xFF; //port D as output SPCR= 1100,0000 // enable interrupt, enable SPI, clk=f/4 SPSR=0; #asm (“sei”) while (1) { } interrupt [SPI] void spi_isr() { PORTD=SPDR; }
University of Tehran 27
University of Tehran 28
University of Tehran 29
University of Tehran 30