Serial Peripheral Interface Module MTT48 8-1
Serial Peripheral Interface Module MTT48 8-1
PERIPHERAL
INTERFACE
(SPI)
Module exercise:
Master mode
• Only a master SPI initiates a transmission
• Data is shifted out via Master Out Slave In (MOSI) line
• Data is shifted in via Master In Slave Out (MISO) line
• Transmission ends after 8 cycles of serial clock (SPSCK)
Slave Mode
• Transfer synchronized to serial clock (SPSCK) from Master
• Data is shifted in via the Master Out Slave In (MOSI) line
• Data is shifted out via the Master In Slave Out (MISO) line
SPSCK
Baud Rate Gen. SS +5v
SS
Slave Select (SS)
• Master mode
– SS held high during transmission
– Acts as error detection input
– Can be general purpose output
• Slave mode
– SS must remain low until transmission completes
0 = Enables slave
1 = Disables slave
RESET: 0 0 0 0 1 0 0 0
phase settings
• Clock Polarity (CPOL)
– Determines clock state when idle
• Clock Phase (CPHA)
1 = Begin capturing data on second clock cycle edge
0 = Begin capturing data on first clock cycle edge*
– When CPHA = 0, the SS must be deasserted and reasserted
between each transmitted byte
M Serial Peripheral Interface Module MTT48 8-7
Clock Polarity and Phase
SS
CPHA CPOL
0 0 SPSCK
1 0 SPSCK
0 1 SPSCK
1 1 SPSCK
Capture Strobe
RESET: 0 0 0 0 1 0 0 0
READ:
SPDR Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
WRITE:
RESET: 0 0 0 0 1 0 0 0
RESET: 0 0 0 0 1 0 0 0
Part 1:
Initialize a SPI to the following:
Master mode
1 MHz baud rate ( 8 MHz system clock )
Clock phase = 1 and clock polarity = 0
Polled operation
Part 2:
Write a procedure to transmit the character in the
Accumulator to the Slave device. Then wait for the
received character and place it into the Accumulator.
(The Master SS is tied to VDD and the Slave SS is tied to
ground)
M
12. Stay here until transmission is complete.
13. Make PB3 output high (deselect shift register).
14. Done, stay here.
HC08-SPIExer
Additional Information
Wired-Or Mode
READ:
SPCR SPRIE DMAS SPMSTR CPOL CPHA SPWOM SPE SPTIE
WRITE:
RESET: 0 0 0 0 1 0 0 0
RESET: 0 0 0 0 1 0 0 0
READ:
SPCR SPRIE DMAS SPMSTR CPOL CPHA SPWOM SPE SPTIE
WRITE:
READ:
SPDR Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
WRITE:
M
WAIT BRCLR #7,SPSCR,WAIT 12. Stay here until transmission is complete.
BSET #3,PORTB 13. Make PB3 output high (deselect shift register).
DONE BRA DONE 14. Done, stay here.
HC08-SPISol