More Related Content
Similar to SPI Interface (20)
SPI Interface
- 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
- 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