Lab7-Spi 2023
Lab7-Spi 2023
LAB 7 — SPI
SPI – Serial Peripheral Interface
• Synchronous serial data communication(can operate in full
duplex)
• 4 wire communication(SS,CLK,MOSI,MISO)
• M0 has four set SPI
https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi
SPI register
• SPI->SSR: SPI slave select register
• SS_LVL
• AUTOSS
• SSR
• SPI->CNTRL: SPI control and status register
• SLAVE
• CLKP
• TX_NUM, TX_BIT_LEN
• TX_NEG, RX_NEG
• GO_BUSY
ADXL SPI configuration
• SPI->DIVIDER: Set SPI clock(DIVIDER)
• SPI->SSR
• SS line is active at low-level edge(SSR.SS_LVL)
• Disable auto ss(SSR.AUTOSS)
• SPI->CNTRL
• Set SPI as master mode(CNTRL.SLAVE)
• CLK is idle at high(CNTRL.CLKP)
• CPOL=1, CPHA=1(CNTRL.TX_NEG, RX_NEG)
• 8 bit data length for each word transmit(CNTRL.TX_BIT_LEN)
• One word in one transfer(CNTRL.TX_NUM)
SPI Write operation
Set Tx data(address)
Set Tx data(address)
GO_BUSY bit
become 0
Read Rx data
Tips: You can see NuMicro_SPI.ppt p.17
for the example code
GO_BUSY bit = 1
Set CS line high
ADXL SPI Read/Write
R/W MB A5 A4 A3 A2 A1 A0
• Data format
• Read/Write bit + Multiple-byte bit + 6 bits address
• Configure 0x2D(0x0010_1101) as address, single-byte Read
• Read + MB + address ➔ 0x1010_1101
ADXL pin configuration
• CS ----------->SPI2 CS(GPD0)
• SCL ----------->SPI2 CLK(GPD1)
• SDO ---------->SPI2 MISO(GPD2)
Bad design for using SPI, we
• SDA(SDI) ---->SPI2 MOSI(GPD3) need to remove this resistor
then let SPI work
• Easy test: you can read the adxl register 0x00 to test SPI communication is
correct or not, it will return 0xE5 if your SPI is right
• Demo必須在Report deadline前完成
• Demo前須先上傳程式碼(上傳main所在的.c檔即可)
Graded
• Basic : 80%
• Report & Code : 20%