Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Configure the SPI to transmit and receive characters to/from another device in Master mode at a 1 MHz rate
LVI
IRQ
RESET
68HC08 CPU
COP
BREAK
Monitor ROM
Features of the SPI module include the following: Full-Duplex Operation Master and Slave Modes Separate Transmit and Receive Registers Four Master Mode Frequencies (Maximum = Bus Frequency 2) Maximum Slave Mode Frequency = Bus Frequency Separate Clock Ground for Reduced Radio Frequency (RF) Interference Serial Clock with Programmable Polarity and Phase Bus Contention Error Flag Overrun Error Flag Two Separately Enabled Interrupts with DMA or CPU Service: SPRF (SPI Receiver Full) SPTE (SPI Transmitter Empty) Programmable Wired-OR Mode I2C (Inter-Integrated Circuit) Compatibility
SPI Control Register (SPCR) SPI Status and Control Register (SPSCR) SPI Data Register (SPDR)
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)
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
Slave Mode
MASTER
MOSI
Shift Register MISO SPSCK Baud Rate Gen. SS +5v
SLAVE
Shift Register
SS
Master mode
Slave mode
completes
SS held high during transmission Acts as error detection input Can be general purpose output SS must remain low until transmission 0 = Enables slave 1 = Disables slave
SPRIE
CPHA
SPWOM
SPE
SPTIE
Selects master mode or slave mode operation 1 = Master mode 0 = Slave mode
Recommend disabling SPI before initializing or SPI Master and Slave need identical clock polarity and changing clock phase, clock polarity, or baud phase settings rate 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
CPHA
CPOL
SS SPSCK SPSCK SPSCK SPSCK MSB Bit 6 Bit 4 Bit 3 Bit 2 LSB
0 1 0 1
0 0 1 1
Bit 5
Bit 1
SPRF
OVRF
MODF
SPTE
0
SPR1 SPR0
Sets the Master SPSCK clock frequency No effect in the Slave devices Baud Rate = CGMOUT / Baud Rate Divisor
SPR1:SPR0 00 01 10 11
Baud Rate (System Clock Freq. = 8 MHz) 4 MHz 1 MHz 250 KHz 62.5 KHz
READ: SPDR WRITE: RESET: UNAFFECTED BY RESET Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Read operation
Reads data in receive data register
SPRF
OVRF
MODF
SPTE
0 SPR1 SPR0
Set when a byte is shifted from shift register to the receive data register Cleared by reading SPSCR then reading SPDR
Set when a byte is transferred from SPDR to the shift register Cleared by reading SPDR register
READ:
SPCR
WRITE: RESET:
SPRIE
CPHA
SPWOM
SPE
SPTIE
Selects either DMA or CPU interrupt request SPRIE/SPTIE bits still enable or disable
SPI Initialization sequence 1) Initialize SPI clock frequency ( SPR1 and SPR0 in SPSCR ) 2) Set clock configuration ( CPOL and CPHA bits in SPSCR ) 3) Select Master/Slave operation ( SPMSTR in SPCR ) 4) Enable interrupts if desired ( SPTIE, SPRIE in SPCR ) 5) Enable the SPI system ( SPE in SPCR )
Simple Polled operation 1) Initialize the SPI 2) Select SS to Slave device (hardware dependent 3) Write byte to SPDR 4) Wait for SPI Transmitter Empty Flag (SPTE) 5) Read the SPDR 6) Release SS to Slave (hardware dependent)
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 1:
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)
Part 2:
READ:
SPCR WRITE: RESET: 0 0 0 0 1 0 0 0 SPRIE DMAS SPMSTR CPOL CPHA SPWOM SPE SPTIE
open-drain drivers Allows multiple-master systems Provides some protection against CMOS latchup
SPRF
OVRF
MODF
SPTE
0 SPR1 SPR0
Failure to read data register before it is over written Incoming data bytes are lost
Data register contents unaffected
Master mode only Indicates another master tried to access this device Set when another device pulls SS pin low Cleared by a write to the SPSCR
WAIT
STOP
SPI mode remains active SPI registers are not accessible Except by DMA Enabled SPI interrupts will exit wait mode SPI module becomes inactive No affect on register conditions Operation continues after an external
interrupt
READ: SPCR WRITE: SPRIE DMAS SPMSTR CPOL CPHA SPWOM SPE SPTIE
SPRF
OVRF
MODF
SPTE
0 SPR1 SPR0
READ: SPDR WRITE: Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
BSET BSET LDA STA LDA STA LDA #$22 SPSCR #$02 DDRF #$06 #3,DDRB
#3,PTB
10. Load accumulator with $55. 11. Store accumulator to SPDR register.
#3,PORTB DONE
13. Make PB3 output high (deselect shift register). 14. Done, stay here.
HC08-SPISol