0% found this document useful (0 votes)
7 views12 pages

Lab7-Spi 2023

The document provides an overview of the Serial Peripheral Interface (SPI) used in microprocessor systems, detailing its configuration, operation, and specific registers. It includes instructions for SPI read/write operations, pin configurations for the ADXL accelerometer, and tips for successful implementation. Additionally, it outlines the demo requirements and grading criteria for a lab assignment.

Uploaded by

angus880826
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views12 pages

Lab7-Spi 2023

The document provides an overview of the Serial Peripheral Interface (SPI) used in microprocessor systems, detailing its configuration, operation, and specific registers. It includes instructions for SPI read/write operations, pin configurations for the ADXL accelerometer, and tips for successful implementation. Additionally, it outlines the demo requirements and grading criteria for a lab assignment.

Uploaded by

angus880826
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

微處理機系統與介面技術

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 CS line low Set Tx data(data)

GO_BUSY bit = 1 GO_BUSY bit


become 0

GO_BUSY bit Tips: You can see NuMicro_SPI.ppt p.17


Set CS line high for the example code
become 0
SPI Read operation

Set Tx data(address)

Set CS line low

GO_BUSY bit = 1 GO_BUSY bit


become 0

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

• Mark: Don’t use SPI0


Basic
• Read 3 axis accelerometer and print on putty
• Need to do calibration
• Result = (Raw data ± offset)/(256 ± offset)
Tips
• 範例程式: SPI_Loopback

• 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

• Remember to change configuration in the SYS_init


• Ex. CLK_SEL1(ModuleClock), GPx_MFP, ALT_MFP ➔ change SPI to SPI2

• Do not use AutoSS, SPI.c SPI.h are useful.

• Be careful for the SPI configuration !!!

• You can write the code as the example.c


Demo
• Place: 創新大樓515 找助教 徐睿桐
• Demo Time: (二)(四)下午三點~五點
• Report deadline: 1/05(五)
• Report title format: LABx_ID_Name.pdf

• Demo必須在Report deadline前完成
• Demo前須先上傳程式碼(上傳main所在的.c檔即可)
Graded
• Basic : 80%
• Report & Code : 20%

• Last LAB, and No Bonus. \(^o^)/

You might also like