📄 tr220flash.c
字号:
/* It is up to the user to give the last byte ID_addr to determine */
/* whether the device outputs manufacturer's ID first, or device ID */
/* first. Please see the product datasheet for details. Returns ID in */
/* variable byte. */
/* */
/* Input: */
/* ID_addr */
/* */
/* Returns: */
/* byte: ID1 */
/* */
/************************************************************************/
/************************************************************************/
/* PROCEDURE: Read */
/* */
/* This procedure reads one address of the device. It will return the */
/* byte read in variable byte. */
/* */
/* */
/* */
/* Input: */
/* Dst: Destination Address 000000H - 07FFFFH */
/* */
/* */
/* Returns: */
/* byte */
/* */
/************************************************************************/
unsigned char Read(unsigned long Dst)
{
unsigned char byte = 0;
vSST25_CE_Low(); /* enable device */
vSST25_Send_Byte(0x03); /* read command */
vSST25_Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
vSST25_Send_Byte(((Dst & 0xFFFF) >> 8));
vSST25_Send_Byte(Dst & 0xFF);
byte = ucSST25_Get_Byte();
vSST25_CE_High(); /* disable device */
return byte; /* return one byte read */
}
/************************************************************************/
/* PROCEDURE: Read_Cont */
/* */
/* This procedure reads multiple addresses of the device and stores */
/* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*/
/* */
/* Input: */
/* Dst: Destination Address 000000H - 07FFFFH */
/* no_bytes Number of bytes to read (max = 128) */
/* */
/* Returns: */
/* Nothing */
/* */
/************************************************************************/
/************************************************************************/
/* PROCEDURE: Byte_Program */
/* */
/* This procedure programs one address of the device. */
/* Assumption: Address being programmed is already erased and is NOT */
/* block protected. */
/* */
/* */
/* */
/* Input: */
/* Dst: Destination Address 000000H - 07FFFFH */
/* byte: byte to be programmed */
/* */
/* */
/* Returns: */
/* Nothing */
/* */
/************************************************************************/
void Byte_Program(unsigned long Dst, unsigned char byte)
{
Wait_Busy();
vSST25_CE_Low(); /* enable device */
vSST25_Send_Byte(0x02); /* send Byte Program command */
vSST25_Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
vSST25_Send_Byte(((Dst & 0xFFFF) >> 8));
vSST25_Send_Byte((Dst & 0xFF));
vSST25_Send_Byte(byte); /* send byte to be programmed */
vSST25_CE_High(); /* disable device */
Wait_Busy();
}
/************************************************************************/
/* PROCEDURE: Auto_Add_IncA */
/* */
/* This procedure programs consecutive addresses of the device. This */
/* is used to to start the AAI process. It should be followed by */
/* Auto_Add_IncB. */
/* Assumption: Address being programmed is already erased and is NOT */
/* block protected. */
/* */
/* */
/* Note: Only RDSR command can be executed once in AAI mode. */
/* Use WRDI to exit AAI mode unless AAI is programming the last */
/* address or last address of unprotected block, which */
/* automatically exits AAI mode. */
/* */
/* Input: */
/* Dst: Destination Address 000000H - 07FFFFH */
/* byte: byte to be programmed */
/* */
/* */
/* Returns: */
/* Nothing */
/* */
/************************************************************************/
/************************************************************************/
/* PROCEDURE: Auto_Add_IncB */
/* */
/* This procedure programs consecutive addresses of the device. This */
/* is used after Auto_Address_IncA. */
/* Assumption: Address being programmed is already erased and is NOT */
/* block protected. */
/* */
/* Note: Only RDSR command can be executed once in AAI mode. */
/* Use WRDI to exit AAI mode unless AAI is programming the last */
/* address or last address of unprotected block, which */
/* automatically exits AAI mode. */
/* */
/* Input: */
/* */
/* byte: byte to be programmed */
/* */
/* */
/* Returns: */
/* Nothing */
/* */
/************************************************************************/
/************************************************************************/
/* PROCEDURE: Chip_Erase */
/* */
/* This procedure erases the entire Chip. */
/* */
/* Input: */
/* None */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
void Chip_Erase(void)
{
Wait_Busy();
vSST25_CE_Low(); /* enable device */
vSST25_Send_Byte(0x60); /* send Chip Erase command */
vSST25_CE_High(); /* disable device */
Wait_Busy();
}
/************************************************************************/
/* PROCEDURE: Sector_Erase */
/* */
/* This procedure Sector Erases the Chip. */
/* */
/* Input: */
/* Dst: Destination Address 000000H - 07FFFFH */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
void Sector_Erase(unsigned long Dst)
{
Wait_Busy();
vSST25_CE_Low(); /* enable device */
vSST25_Send_Byte(0x20); /* send Sector Erase command */
vSST25_Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
vSST25_Send_Byte(((Dst & 0xFFFF) >> 8));
vSST25_Send_Byte(Dst & 0xFF);
vSST25_CE_High(); /* disable device */
Wait_Busy();
}
/************************************************************************/
/* PROCEDURE: Block_Erase */
/* */
/* This procedure Block Erases the Chip. */
/* */
/* Input: */
/* Dst: Destination Address 000000H - 07FFFFH */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
void Block_Erase(unsigned long Dst)
{
Wait_Busy();
vSST25_CE_Low(); /* enable device */
vSST25_Send_Byte(0x52); /* send Block Erase command */
vSST25_Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
vSST25_Send_Byte(((Dst & 0xFFFF) >> 8));
vSST25_Send_Byte(Dst & 0xFF);
vSST25_CE_High(); /* disable device */
Wait_Busy();
}
/************************************************************************/
/* PROCEDURE: Wait_Busy */
/* */
/* This procedure waits until device is no longer busy (can be used by */
/* Byte-Program, Sector-Erase, Block-Erase, Chip-Erase). */
/* */
/* Input: */
/* None */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
void Wait_Busy(void)
{
do
{
WREN();
ucFlash_Status=Read_Status_Register();
}
while(((ucFlash_Status &0x01)==0x01)||((ucFlash_Status &0x02)==0x00)); /* waste time until not busy */
}
/************************************************************************/
/* PROCEDURE: Wait_Busy_AAI */
/* */
/* This procedure waits until device is no longer busy for AAI mode. */
/* */
/* Input: */
/* None */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
/************************************************************************/
/* PROCEDURE: WREN_Check */
/* */
/* This procedure checks to see if WEL bit set before program/erase. */
/* */
/* Input: */
/* None */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
/************************************************************************/
/* PROCEDURE: WREN_AAI_Check */
/* */
/* This procedure checks for AAI and WEL bit once in AAI mode. */
/* */
/* Input: */
/* None */
/* */
/* Returns: */
/* Nothing */
/************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -