SlideShare a Scribd company logo
SPI INTERFACE
Joseph
2016/08/08
1
SPI 線路
2
SPI 為一個Ring 結構:要讀資料,必送資料
{dummy byte}
CPOL: rest state of clock (high or low)
CPHA: First or second SCLK transition
CPOL,CPHA 用來決定latch 資料的時間點
SPI 模式
3
Serial Flash (SPI interface)
Flash size: 4Mbit
1) 64K Block size (Block Erase)
2) 4K Sector size (Sector Erase, Block_Erase_4K)
3) 256 Byte Page size (Page Program)
Single Power Supply Operation
• 2.7 to 3.6 volt for read, erase, and program operations
SPI Modes : Mode 0 & Mode 1
注意:
1) Flash 要寫入page之前,要先Erase
2) Page Program->"0", Erase -->"1"
3) 傳送順序為 MSB First
MX25L4005A 規格
4
MX25L4005A Addressing (3 byte)
Flash Memory Organization
Page #Sector #Block #
11 01523 18 12 8 7
Offset #
AD1 AD2 AD3
16
Sector Address A[18:12]
MSB LSB
Page Program (0x02)Page Address A[18:8] + Offset A[7:0]
. . .
256 byte
1 page=256 bytes
Sector Erase (0x20)
5
16 pages
Read Status Register (RDSR)
6
Command Table
7
對於 PP, SE, BE, CE, and WRSR 會改變Flash內容的Command, 都
要先設定WEL bit=1 (in RDSR bit 1), 一旦操作完成後, 它會自動reset
(將WEL bit設回0)
操作方法:
MX25L4005A 操作方法
CS# goes low
sending WREN (0x6); // set WEL=1
CS# goes high
CS# goes low
sending <CMD>+{Flash Address}+{Data}; //see command table
CS# goes high
CS# goes low
deadline = jiffies + MAX_READY_WAIT_JIFFIES;
do {
status=sending RDSR(0x5) ;
if (!(status & WIP) ) return 0; //判斷是否操作完成
cond_resched(); // 再排程
} while (!time_after_eq(jiffies, deadline));
CS# goes high
8
Read ID command
MX25L4005A FlashID:C22013
C2 20 13
9
Page Program
送出24 bit Address 決定了寫入位址(page+offset)後, 接著就是在這個page內偱序寫入資料。
因為page size為256 byte, 所以最多只能寫256 Byte, 超過會覆蓋到同page的開頭
10
write_flash(addr, buf, len) ;
在位址 0x2085, 寫入長度是786 byte時, 該進行何種程序? 假設
Page 為256 bytes
Answer:要執行4次Page Program cycle (每次不同的Page address)
Quiz
11
addr
len
page
PP(0x2100,256)
PP(0x2200,256)
PP(0x2300,151)
PP(0x2085,123)
page offset 0x85
SPI 操作-big-banging
void SendByte( uint8 byte_value )
{
uint16 i;
uint8 cycle_cnt;
cycle_cnt = 8;
for( i= 0; i < cycle_cnt; i++ )
{
if ( (byte_value & IO_MASK) == 0x80 ){
SI = 1;
}
else{
SI = 0;
}
SCLK = 0;
byte_value = byte_value << 1;
SCLK = 1;
}
}
uint8 GetByte( )
{
uint16 i;
uint8 cycle_cnt;
uint8 data_buf;
data_buf = 0;
cycle_cnt = 8;
for( i= 0; i < cycle_cnt; i++ )
{
SCLK = 0;
if ( SO == 1 ){
data_buf = (data_buf | (0x80 >> i));
}
SCLK = 1;
}
return data_buf;
}
SCLK = 1; // init Flash input clock
12
SPI Mode : 3
SPI 操作 - big-banging
ReturnMsg CMD_RDID( uint32 *Identification )
{
uint32 temp;
uint8 gDataBuffer[3];
// Chip select go low to start a flash command
CS_Low();
// Send command
#define FLASH_CMD_RDID 0x9F //RDID (Read Identification)
SendByte( FLASH_CMD_RDID);
// Get manufacturer identification, device identification
gDataBuffer[0] = GetByte( );
gDataBuffer[1] = GetByte( );
gDataBuffer[2] = GetByte( );
// Chip select go high to end a command
CS_High();
// Store identification
temp = gDataBuffer[0];
temp = (temp << 8) | gDataBuffer[1];
*Identification = (temp << 8) | gDataBuffer[2];
// Flash ID:C22013
return FlashOperationSuccess;
}
13
ADC (MCP3008)
2.7V 4-Channel/8-Channel 10-Bit A/D Converters with SPI Serial Interface
4 pseudo-differential input pairs or 8 single-ended inputs
SPI Interface
LSB: 最小刻度
VREF determines the
analog input voltage range
SPI COMMUNICATION
SPI Interface

More Related Content

PPT
PPT
Spi master core verification
PDF
SPI Protocol
PPTX
Spi in arm7(lpc2148)
PPTX
Raspberry Pi tutorial
PPTX
Serial peripheral Interface - Embedded System Protocol
PPTX
PPTX
Лекц 15
Spi master core verification
SPI Protocol
Spi in arm7(lpc2148)
Raspberry Pi tutorial
Serial peripheral Interface - Embedded System Protocol
Лекц 15

What's hot (20)

PPTX
Serial peripheral interface
PPTX
Linkmeup v23-compass-eos
PPT
PDF
Llpc2148 sci
PPTX
COMPLETE DETAIL OF ARM PART 3
PPTX
OSPF Internal Route Summarization
PPT
Spi (1)
PPTX
Redistribution into OSPF
PPTX
Serial Peripheral Interface
PPTX
Serial connectors, Protocols , USB (universal serial bus)
PPTX
I2 c communication protocol
PPTX
arm complete detail part 2
PPTX
CCNA ppt Day 7
PPTX
Лекц 8
PPTX
FAR/MARS Avionics CDR
PPT
Switch configuration
PPTX
I2c protocol - Inter–Integrated Circuit Communication Protocol
PPTX
PPT
SPI Bus Protocol
PPTX
I2c buses
Serial peripheral interface
Linkmeup v23-compass-eos
Llpc2148 sci
COMPLETE DETAIL OF ARM PART 3
OSPF Internal Route Summarization
Spi (1)
Redistribution into OSPF
Serial Peripheral Interface
Serial connectors, Protocols , USB (universal serial bus)
I2 c communication protocol
arm complete detail part 2
CCNA ppt Day 7
Лекц 8
FAR/MARS Avionics CDR
Switch configuration
I2c protocol - Inter–Integrated Circuit Communication Protocol
SPI Bus Protocol
I2c buses
Ad

Similar to SPI Interface (20)

PDF
[KOR] ODI no.004 analysis of oracle performance degradation caused by ineffic...
PPTX
Blake2.pptxRWAAEFETGWRAEGTRWGRWERGEWGEREWFREW
PDF
POWER10 innovations for HPC
PDF
The Quantum Physics of Java
PDF
DOAG Security Day 2016 Enterprise Security Reloaded
PPTX
Super scaling singleton inserts
PPT
Machine Architecture of Intel 8088 and addressing modes
PPTX
Cisco EuroMPI'13 vendor session presentation
PPTX
MaPU-HPCA2016
PDF
Computer Organization and Design 4th Edition Patterson Test Bank
PDF
助教が吼える! 各界の若手研究者大集合「ハードウェアはやわらかい」
PPTX
了解Cpu
PDF
Design and Implementation of 64 Bit RISC Processor Using System.pdf
PDF
Oracle Deep Internal 4 (ver.2)
PPTX
Proving out flash storage array performance using swingbench and slob
PDF
SPI Design Report used in serial communication
PPTX
Microprocessor Week1: Introduction
PDF
lecture16-recap-questions-and-answers.pdf
PPTX
IPv6 Static Routes
[KOR] ODI no.004 analysis of oracle performance degradation caused by ineffic...
Blake2.pptxRWAAEFETGWRAEGTRWGRWERGEWGEREWFREW
POWER10 innovations for HPC
The Quantum Physics of Java
DOAG Security Day 2016 Enterprise Security Reloaded
Super scaling singleton inserts
Machine Architecture of Intel 8088 and addressing modes
Cisco EuroMPI'13 vendor session presentation
MaPU-HPCA2016
Computer Organization and Design 4th Edition Patterson Test Bank
助教が吼える! 各界の若手研究者大集合「ハードウェアはやわらかい」
了解Cpu
Design and Implementation of 64 Bit RISC Processor Using System.pdf
Oracle Deep Internal 4 (ver.2)
Proving out flash storage array performance using swingbench and slob
SPI Design Report used in serial communication
Microprocessor Week1: Introduction
lecture16-recap-questions-and-answers.pdf
IPv6 Static Routes
Ad

More from 艾鍗科技 (20)

PPTX
AI 技術浪潮, 什麼是機器學習? 什麼是深度學習, 什麼是生成式AI, AI 能力認證
PDF
TinyML - 4 speech recognition
PPTX
Appendix 1 Goolge colab
PPTX
Project-IOT於餐館系統的應用
PPTX
02 IoT implementation
PPTX
Tiny ML for spark Fun Edge
PDF
Openvino ncs2
PDF
Step motor
PDF
2. 機器學習簡介
PDF
5.MLP(Multi-Layer Perceptron)
PDF
3. data features
PPTX
心率血氧檢測與運動促進
PPTX
利用音樂&情境燈幫助放鬆
PPTX
IoT感測器驅動程式 在樹莓派上實作
PPTX
無線聲控遙控車
PPT
最佳光源的研究和實作
PPTX
無線監控網路攝影機與控制自走車
PPTX
Reinforcement Learning
PPTX
Linux Device Tree
PPTX
人臉辨識考勤系統
AI 技術浪潮, 什麼是機器學習? 什麼是深度學習, 什麼是生成式AI, AI 能力認證
TinyML - 4 speech recognition
Appendix 1 Goolge colab
Project-IOT於餐館系統的應用
02 IoT implementation
Tiny ML for spark Fun Edge
Openvino ncs2
Step motor
2. 機器學習簡介
5.MLP(Multi-Layer Perceptron)
3. data features
心率血氧檢測與運動促進
利用音樂&情境燈幫助放鬆
IoT感測器驅動程式 在樹莓派上實作
無線聲控遙控車
最佳光源的研究和實作
無線監控網路攝影機與控制自走車
Reinforcement Learning
Linux Device Tree
人臉辨識考勤系統

Recently uploaded (20)

PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
additive manufacturing of ss316l using mig welding
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
DOCX
573137875-Attendance-Management-System-original
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Digital Logic Computer Design lecture notes
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
additive manufacturing of ss316l using mig welding
Automation-in-Manufacturing-Chapter-Introduction.pdf
Foundation to blockchain - A guide to Blockchain Tech
573137875-Attendance-Management-System-original
CH1 Production IntroductoryConcepts.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Geodesy 1.pptx...............................................
Lecture Notes Electrical Wiring System Components
CYBER-CRIMES AND SECURITY A guide to understanding
Digital Logic Computer Design lecture notes
UNIT 4 Total Quality Management .pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Model Code of Practice - Construction Work - 21102022 .pdf
R24 SURVEYING LAB MANUAL for civil enggi
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx

SPI Interface

  • 2. SPI 線路 2 SPI 為一個Ring 結構:要讀資料,必送資料 {dummy byte}
  • 3. CPOL: rest state of clock (high or low) CPHA: First or second SCLK transition CPOL,CPHA 用來決定latch 資料的時間點 SPI 模式 3
  • 4. Serial Flash (SPI interface) Flash size: 4Mbit 1) 64K Block size (Block Erase) 2) 4K Sector size (Sector Erase, Block_Erase_4K) 3) 256 Byte Page size (Page Program) Single Power Supply Operation • 2.7 to 3.6 volt for read, erase, and program operations SPI Modes : Mode 0 & Mode 1 注意: 1) Flash 要寫入page之前,要先Erase 2) Page Program->"0", Erase -->"1" 3) 傳送順序為 MSB First MX25L4005A 規格 4
  • 5. MX25L4005A Addressing (3 byte) Flash Memory Organization Page #Sector #Block # 11 01523 18 12 8 7 Offset # AD1 AD2 AD3 16 Sector Address A[18:12] MSB LSB Page Program (0x02)Page Address A[18:8] + Offset A[7:0] . . . 256 byte 1 page=256 bytes Sector Erase (0x20) 5 16 pages
  • 8. 對於 PP, SE, BE, CE, and WRSR 會改變Flash內容的Command, 都 要先設定WEL bit=1 (in RDSR bit 1), 一旦操作完成後, 它會自動reset (將WEL bit設回0) 操作方法: MX25L4005A 操作方法 CS# goes low sending WREN (0x6); // set WEL=1 CS# goes high CS# goes low sending <CMD>+{Flash Address}+{Data}; //see command table CS# goes high CS# goes low deadline = jiffies + MAX_READY_WAIT_JIFFIES; do { status=sending RDSR(0x5) ; if (!(status & WIP) ) return 0; //判斷是否操作完成 cond_resched(); // 再排程 } while (!time_after_eq(jiffies, deadline)); CS# goes high 8
  • 9. Read ID command MX25L4005A FlashID:C22013 C2 20 13 9
  • 10. Page Program 送出24 bit Address 決定了寫入位址(page+offset)後, 接著就是在這個page內偱序寫入資料。 因為page size為256 byte, 所以最多只能寫256 Byte, 超過會覆蓋到同page的開頭 10
  • 11. write_flash(addr, buf, len) ; 在位址 0x2085, 寫入長度是786 byte時, 該進行何種程序? 假設 Page 為256 bytes Answer:要執行4次Page Program cycle (每次不同的Page address) Quiz 11 addr len page PP(0x2100,256) PP(0x2200,256) PP(0x2300,151) PP(0x2085,123) page offset 0x85
  • 12. SPI 操作-big-banging void SendByte( uint8 byte_value ) { uint16 i; uint8 cycle_cnt; cycle_cnt = 8; for( i= 0; i < cycle_cnt; i++ ) { if ( (byte_value & IO_MASK) == 0x80 ){ SI = 1; } else{ SI = 0; } SCLK = 0; byte_value = byte_value << 1; SCLK = 1; } } uint8 GetByte( ) { uint16 i; uint8 cycle_cnt; uint8 data_buf; data_buf = 0; cycle_cnt = 8; for( i= 0; i < cycle_cnt; i++ ) { SCLK = 0; if ( SO == 1 ){ data_buf = (data_buf | (0x80 >> i)); } SCLK = 1; } return data_buf; } SCLK = 1; // init Flash input clock 12 SPI Mode : 3
  • 13. SPI 操作 - big-banging ReturnMsg CMD_RDID( uint32 *Identification ) { uint32 temp; uint8 gDataBuffer[3]; // Chip select go low to start a flash command CS_Low(); // Send command #define FLASH_CMD_RDID 0x9F //RDID (Read Identification) SendByte( FLASH_CMD_RDID); // Get manufacturer identification, device identification gDataBuffer[0] = GetByte( ); gDataBuffer[1] = GetByte( ); gDataBuffer[2] = GetByte( ); // Chip select go high to end a command CS_High(); // Store identification temp = gDataBuffer[0]; temp = (temp << 8) | gDataBuffer[1]; *Identification = (temp << 8) | gDataBuffer[2]; // Flash ID:C22013 return FlashOperationSuccess; } 13
  • 14. ADC (MCP3008) 2.7V 4-Channel/8-Channel 10-Bit A/D Converters with SPI Serial Interface 4 pseudo-differential input pairs or 8 single-ended inputs
  • 16. LSB: 最小刻度 VREF determines the analog input voltage range