?? f411_vr_sstflash.c
字號:
NSSMD0 = 0; // enable the flash
// send the read instruction
SPI0DAT = READ; // load the XMIT register
while (TXBMT != 1) // wait until the command is moved into
{ // the XMIT buffer
}
SPI0DAT = temp_addr.UByte[1]; // load the high byte of the address
while (TXBMT != 1) // wait until the data is moved into
{ // the XMIT buffer
}
SPI0DAT = temp_addr.UByte[2]; // load the middle byte of the address
while (TXBMT != 1) // wait until the data is moved into
{ // the XMIT buffer
}
SPI0DAT = temp_addr.UByte[3]; // load the low byte of the address
while (TXBMT != 1) // wait until the data is moved into
{ // the XMIT buffer
}
SPI0DAT = 0xFF; // load junk data in order to receive
// data from the flash
while (TXBMT != 1) // wait until the junk data is moved
{ // into the XMIT buffer
}
SPIF = 0;
while (SPIF != 1) // wait until the read data is received
{
}
SPIF = 0;
NSSMD0 = 1; // disable the flash
return SPI0DAT;
}
//-----------------------------------------------------------------------------
// Erase_MEM
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// Erase all data from the SST flash memory.
//
void Erase_MEM (void)
{
unsigned char mem_status = 0x01;
NSSMD0 = 0; // enable the flash
// send the write enable command
SPI0DAT = WREN; // load the XMIT register
while (TXBMT != 1) // wait until the command is moved into
{ // the XMIT buffer
}
SPIF = 0;
while (SPIF != 1) // wait until the command reaches the
{ // flash
}
SPIF = 0;
NSSMD0 = 1; // allow the WREN to execute
NSSMD0 = 0; // enable the flash
// send the chip erase instruction
SPI0DAT = CERASE; // load the XMIT register
while (TXBMT != 1) // wait until the command is moved into
{ // the XMIT buffer
}
SPIF = 0;
while (SPIF != 1) // wait until the command reaches the
{ // flash
}
SPIF = 0;
NSSMD0 = 1; // allow the erase to execute
// poll on the busy bit in the flash until the erase operation is complete
NSSMD0 = 0; // enable the flash
SPI0DAT = RDSR; // send the read status register command
while (TXBMT != 1) // wait until the SPI can accept more
{ // data
}
while (mem_status == 0x01)
{
SPI0DAT = 0xFF; // send junk in order to receive data
while (TXBMT != 1) // wait until the junk data is moved
{ // into the XMIT buffer
}
SPIF = 0;
while (SPIF != 1) // wait until the read data is received
{
}
SPIF = 0;
mem_status = SPI0DAT & 0x01; // check the BUSY bit
}
NSSMD0 = 1; // disable the flash
}
//-----------------------------------------------------------------------------
// Read_MEM_Init
//-----------------------------------------------------------------------------
//
// Return Value :
// 1) char data_byte - the data byte read from memory
// range is positive range of character: 0 to 255
// Parameters :
// 1) long address - address in the 512 kB external SST Flash
// range is postive values up to 2^19: 0 to 524287,
// or, 0 to 0x7FFFF
//
// Read one byte of data from a 24-bit address in the SST Flash Memory using
// the SPI. This function is called by Recording_Search in F411_VR.c
// and is a duplicate of Read_MEM to avoid a warning by the compiler.
//
unsigned char Read_MEM_Init (unsigned long address)
{
ADDRESS temp_addr;
temp_addr.ULong = address;
NSSMD0 = 0; // enable the flash
// send the read instruction
SPI0DAT = READ; // load the XMIT register
while (TXBMT != 1) // wait until the command is moved into
{ // the XMIT buffer
}
SPI0DAT = temp_addr.UByte[1]; // load the high byte of the address
while (TXBMT != 1) // wait until the data is moved into
{ // the XMIT buffer
}
SPI0DAT = temp_addr.UByte[2]; // load the middle byte of the address
while (TXBMT != 1) // wait until the data is moved into
{ // the XMIT buffer
}
SPI0DAT = temp_addr.UByte[3]; // load the low byte of the address
while (TXBMT != 1) // wait until the data is moved into
{ // the XMIT buffer
}
SPI0DAT = 0xFF; // load junk data in order to receive
// data from the flash
while (TXBMT != 1) // wait until the junk data is moved
{ // into the XMIT buffer
}
SPIF = 0;
while (SPIF != 1) // wait until the read data is received
{
}
SPIF = 0;
NSSMD0 = 1; // disable the flash
return SPI0DAT;
}
//-----------------------------------------------------------------------------
// ReadID_MEM
//-----------------------------------------------------------------------------
//
// Return Value :
// 1) char data_byte - the device ID read from memory at address 0x000001
// (this address is specified in the SST Flash datasheet)
// range is positive range of character: 0 to 255
// Parameters : None
//
// Read the part ID from the flash memory (used for debugging).
//
/*
char ReadID_MEM (void)
{
NSSMD0 = 0; // enable the flash
SPI0DAT = READID; // send the read ID instruction
while (TXBMT != 1) // wait until the SPI can accept more
{ // data
}
SPI0DAT = 0x00; // send the device ID address
while (TXBMT != 1) // wait until the SPI can accept more
{ // data
}
SPI0DAT = 0x00; // send the device ID address
while (TXBMT != 1) // wait until the SPI can accept more
{ // data
}
SPI0DAT = 0x01; // send the device ID address
while (TXBMT != 1) // wait until the SPI can accept more
{ // data
}
SPI0DAT = 0xA5; // send dummy data for shift register
while (TXBMT != 1) // wait until the SPI can accept more
{ // data
}
SPIF = 0;
while (SPIF != 1) // wait until the read data is received
{
}
SPIF = 0;
NSSMD0 = 1; // disable the flash
return SPI0DAT;
}
*/
//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -