SPI Flash Sample Driver
1. Table of Contents
1. Table of Contents.................................................................................................................... 2
2. Instruction Set ........................................................................................................................ 3
3. Customer functions ................................................................................................................ 4
3.1 oemOutByte.................................................................................................................... 4
3.2 oemInByte ...................................................................................................................... 4
3.3 oemSetCS ........................................................................................................................ 5
3.4 oemQuadOutByte ........................................................................................................... 5
3.5 oemQuadInByte .............................................................................................................. 6
4. Operations .............................................................................................................................. 7
4.1 ReadStatusRegister ......................................................................................................... 7
4.2 WriteStatusRegister ........................................................................................................ 7
4.3 ReadMIDDID1 ................................................................................................................. 8
4.4 ReadMIDDID2 ................................................................................................................. 8
4.5 ReadData ........................................................................................................................ 9
4.6 PageProgram .................................................................................................................. 9
4.7 EraseSector ................................................................................................................... 10
4.8 EraseBlock ..................................................................................................................... 11
4.9 EraseChip ...................................................................................................................... 12
4.10 FastReadDataQuadOut ................................................................................................. 13
4.11 FastReadDataQuadIO ................................................................................................... 14
4.12 QuadInputPageProgram ............................................................................................... 14
2. Instruction Set
#define WRITE_ENABLE_CMD 0x6
#define WRITE_DISABLE_CMD 0x4
#define READ_STATUS_CMD 0x5
#define WRITE_STATUS_CMD 0x1
#define READ_DATA_CMD 0x3
#define PAGE_PROGRAM_CMD 0x2
#define ERASE_SECTOR_CMD 0x20
#define ERASE_BLOCK_CMD 0xD8 // or 0x52
#define ERASE_CHIP_CMD 0xC7 // or 0x60
#define READ_MID_DID_1_CMD 0x90
#define READ_MID_DID_2_CMD 0x9F
#define FAST_READ_QUADOUT_CMD 0x6B // (1-1-4)
#define FAST_READ_QUADIO_CMD 0xEB // (1-4-4)
#define PAGE_PROGRAM_QUADIN_CMD 0x32 // or 0x38 (1-1-4)
3. Customer functions
3.1 oemOutByte
Description: This function is used to output a byte of data to the bit stream connected
to the SPI flash device through ‘SI’ pin.
Declaration:
void oemOutByte(unsigned char outByte)
Parameters:
Name
Type
Description
outByte
unsigned char
Output data byte
Return: n/a
Example Implementation:
extern SPI_SIGNAL CLK;
extern SPI_SIGNAL SI;
void oemOutByte(unsigned char outByte)
{
unsigned char i;
for(i=0; i<8; i++) {
CLK = 0;
CLK = 1;
SI = (outByte>>(7-i))&0x01;
}
}
3.2 oemInByte
Description: This function is used to get a byte of data from the bit stream connected
to the SPI flash device through ‘SO’ pin.
Declaration:
void oemInByte(unsigned char *pInByte)
Parameters:
Name
Type
Description
pInByte
unsigned char *
Pointer to the input data byte.
Return: n/a
Example Implementation:
extern SPI_SIGNAL CLK;
extern SPI_SIGNAL SO;
void oemInByte(unsigned char *pInByte)
{
unsigned char i;
*pInByte = 0;
for(i=0; i<8; i++) {
CLK = 1;
CLK = 0;
if(SO == 1) *pInByte |= (0x80>>i);
}
}
3.3 oemSetCS
Description: This function is used to assert / dessert the CS signal of the SPI flash
device.
Declaration:
void oemSetCS(unsigned char assert)
Parameters:
Name
Type
Description
assert
unsigned char
Value of the CS.
Return: n/a
Example Implementation:
#define ASSERT 0
#define DESSERT 1
extern SPI_SIGNAL CS
void oemSetCS(unsigned char assert)
{
CS = assert;
}
3.4 oemQuadOutByte
Description: This function is used to output a byte of data to the bit stream connected
to the SPI flash device through ‘Quad IO’ pins (IO0, IO1, IO2, IO3).
Declaration:
void oemQuadOutByte(unsigned char outByte)
Parameters:
Name
Type
Description
outByte
unsigned char
Output data byte
Return: n/a
Example Implementation:
extern SPI_SIGNAL CLK;
extern SPI_SIGNAL SI; // = IO0
extern SPI_SIGNAL SO; // = IO1
extern SPI_SIGNAL IO2;
extern SPI_SIGNAL IO3;
void oemQuadOutByte(unsigned char outByte)
{
unsigned char i;
for(i=0; i<8; i+=4) {
CLK = 0;
CLK = 1;
SI = (outByte>>(7-i-0))&0x01;
SO = (outByte>>(7-i-1))&0x01;
IO2 = (outByte>>(7-i-2))&0x01;
IO3 = (outByte>>(7-i-3))&0x01;
}
}