⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sst25vf016b.c

📁 SPI接口的FLASH sst25VF016B的相关子程序
💻 C
📖 第 1 页 / 共 3 页
字号:
	Send_Byte(0xAD);			/* send AAI command */
	Send_Byte(byte1);			/* send 1st byte to be programmed */
	Send_Byte(byte2);			/* send 2nd byte to be programmed */
	CE_High();				/* disable device */
}

/************************************************************************/
/* PROCEDURE:	Auto_Add_IncA_EBSY					*/
/*									*/
/* This procedure is the same as procedure Auto_Add_IncA except that it */
/* uses EBSY and Poll_SO functions to check for RY/BY. It programs 	*/
/* consecutive addresses of the device.  The 1st data byte will be 	*/
/* programmed into the initial address [A23-A1] and with A0 = 0.  The 	*/
/* 2nd data byte will be programmed into initial address [A23-A1] and 	*/
/* with A0  = 1.  This is used to to start the AAI process.  It should  */
/* be followed by Auto_Add_IncB_EBSY.					*/
/* Assumption:  Address being programmed is already erased and is NOT	*/
/*		block protected.					*/
/*									*/
/*									*/
/* Note: Only WRDI and AAI command can be executed once in AAI mode 	*/
/*	 with SO enabled as RY/BY# status.  When the device is busy 	*/
/*	 asserting CE# will output the status of RY/BY# on SO.  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 - 1FFFFFH	*/
/*		byte1:		1st byte to be programmed		*/
/*      	byte1:		2nd byte to be programmed		*/
/*									*/
/* Returns:								*/
/*		Nothing							*/
/*									*/
/************************************************************************/
void Auto_Add_IncA_EBSY(unsigned long Dst, unsigned char byte1, unsigned char byte2)
{
	EBSY();					/* enable RY/BY# status for SO in AAI */	

	CE_Low();				/* enable device */
	Send_Byte(0xAD);			/* send AAI command */
	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */
	Send_Byte(((Dst & 0xFFFF) >> 8));
	Send_Byte(Dst & 0xFF);
	Send_Byte(byte1);			/* send 1st byte to be programmed */	
	Send_Byte(byte2);			/* send 2nd byte to be programmed */
	CE_High();				/* disable device */

	Poll_SO();				/* polls RY/BY# using SO line */

}

/************************************************************************/
/* PROCEDURE:	Auto_Add_IncB_EBSY					*/
/*									*/
/* This procedure is the same as Auto_Add_IncB excpet that it uses 	*/
/* Poll_SO to poll for RY/BY#.  It demonstrate on how to use DBSY after	*/
/* AAI programmming is completed.  It programs consecutive addresses of */
/* the device.  The 1st data byte will be programmed into the initial   */
/* address [A23-A1] and with A0 = 0.  The 2nd data byte will be 	*/
/* programmed into initial address [A23-A1] and with A0  = 1.  This is 	*/
/* used after Auto_Address_IncA.					*/
/* Assumption:  Address being programmed is already erased and is NOT	*/
/*		block protected.					*/
/*									*/
/* Note: Only WRDI and AAI command can be executed once in AAI mode 	*/
/*	 with SO enabled as RY/BY# status.  When the device is busy 	*/
/*	 asserting CE# will output the status of RY/BY# on SO.  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:								*/
/*									*/
/*		byte1:		1st byte to be programmed		*/
/*		byte2:		2nd byte to be programmed		*/
/*      								*/
/*									*/
/* Returns:								*/
/*		Nothing							*/
/*									*/
/************************************************************************/
void Auto_Add_IncB_EBSY(unsigned char byte1, unsigned char byte2)
{
	CE_Low();				/* enable device */
	Send_Byte(0xAD);			/* send AAI command */
	Send_Byte(byte1);			/* send 1st byte to be programmed */
	Send_Byte(byte2);			/* send 2nd byte to be programmed */
	CE_High();				/* disable device */

	Poll_SO();				/* polls RY/BY# using SO line */

	WRDI(); 				/* Exit AAI before executing DBSY */
	DBSY();					/* disable SO as RY/BY# output if in AAI */
}

/************************************************************************/
/* PROCEDURE: Chip_Erase						*/
/*									*/
/* This procedure erases the entire Chip.				*/
/*									*/
/* Input:								*/
/*		None							*/
/*									*/
/* Returns:								*/
/*		Nothing							*/
/************************************************************************/
void Chip_Erase()
{		
	Wait_Busy();
	WREN();
	CE_Low();				/* enable device */
	Send_Byte(0x60);			/* send Chip Erase command (60h or C7h) */
	CE_High();				/* disable device */
}

/************************************************************************/
/* PROCEDURE: Sector_Erase						*/
/*									*/
/* This procedure Sector Erases the Chip.				*/
/*									*/
/* Input:								*/
/*		Dst:		Destination Address 000000H - 1FFFFFH	*/
/*									*/
/* Returns:								*/
/*		Nothing							*/
/************************************************************************/
void Sector_Erase(unsigned long Dst)
{
	Wait_Busy();
	WREN();
	CE_Low();				/* enable device */
	Send_Byte(0x20);			/* send Sector Erase command */
	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */
	Send_Byte(((Dst & 0xFFFF) >> 8));
	Send_Byte(Dst & 0xFF);
	CE_High();				/* disable device */
	Wait_Busy();
}

/************************************************************************/
/* PROCEDURE: Block_Erase_32K						*/
/*									*/
/* This procedure Block Erases 32 KByte of the Chip.			*/
/*									*/
/* Input:								*/
/*		Dst:		Destination Address 000000H - 1FFFFFH	*/
/*									*/
/* Returns:								*/
/*		Nothing							*/
/************************************************************************/
void Block_Erase_32K(unsigned long Dst)
{
	CE_Low();				/* enable device */
	Send_Byte(0x52);			/* send 32 KByte Block Erase command */
	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */
	Send_Byte(((Dst & 0xFFFF) >> 8));
	Send_Byte(Dst & 0xFF);
	CE_High();				/* disable device */
}

/************************************************************************/
/* PROCEDURE: Block_Erase_64K						*/
/*									*/
/* This procedure Block Erases 64 KByte of the Chip.			*/
/*									*/
/* Input:								*/
/*		Dst:		Destination Address 000000H - 1FFFFFH	*/
/*									*/
/* Returns:								*/
/*		Nothing							*/
/************************************************************************/
void Block_Erase_64K(unsigned long Dst)
{
	CE_Low();				/* enable device */
	Send_Byte(0xD8);			/* send 64KByte Block Erase command */
	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */
	Send_Byte(((Dst & 0xFFFF) >> 8));
	Send_Byte(Dst & 0xFF);
	CE_High();				/* disable device */
}

/************************************************************************/
/* 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()
{
	RESET_WDT;
	while (Read_Status_Register() == 0x03)	/* waste time until not busy */
		Read_Status_Register();
}

/************************************************************************/
/* PROCEDURE: Wait_Busy_AAI						*/
/*									*/
/* This procedure waits until device is no longer busy for AAI mode.	*/
/*									*/
/* Input:								*/
/*		None							*/
/*									*/
/* Returns:								*/
/*		Nothing							*/
/************************************************************************/
void Wait_Busy_AAI()
{
	while (Read_Status_Register() == 0x43)	/* waste time until not busy */
		Read_Status_Register();
}

/************************************************************************/
/* PROCEDURE: WREN_Check						*/
/*									*/
/* This procedure checks to see if WEL bit set before program/erase.	*/
/*									*/
/* Input:								*/
/*		None							*/
/*									*/
/* Returns:								*/
/*		Nothing							*/
/************************************************************************/
void WREN_Check()
{
	unsigned char byte;
	byte = Read_Status_Register();	/* read the status register */
	if (byte != 0x02)		/* verify that WEL bit is set */
	{
		while(1);
		/* add source code or statements for this file */
		/* to compile   			       */
		/* i.e. option: insert a display to view error on LED? */
		/* option: insert a display to view error on LED? */
	}
}

/************************************************************************/
/* PROCEDURE: WREN_AAI_Check						*/
/*									*/
/* This procedure checks for AAI and WEL bit once in AAI mode.		*/
/*									*/
/* Input:								*/
/*		None							*/
/*									*/
/* Returns:								*/
/*		Nothing							*/
/************************************************************************/
void WREN_AAI_Check()
{
	unsigned char byte;
	byte = Read_Status_Register();	/* read the status register */
	if (byte != 0x42)		/* verify that AAI and WEL bit is set */
	{
		while(1);		
		/* add source code or statements for this file */
		/* to compile   			       */
		/* i.e. option: insert a display to view error on LED? */
		/* option: insert a display to view error on LED? */

	}
}

/************************************************************************/
/* PROCEDURE: Verify							*/
/*									*/
/* This procedure checks to see if the correct byte has be read.	*/
/*									*/
/* Input:								*/
/*		byte:		byte read				*/
/*		cor_byte:	correct_byte that should be read	*/
/*									*/
/* Returns:								*/
/*		Nothing							*/
/************************************************************************/
void Verify(unsigned char byte, unsigned char cor_byte)
{
	if (byte != cor_byte)
	{
		while(1);
		/* add source code or statement for this file */
		/* to compile   			       */
		/* i.e. option: insert a display to view error on LED? */

		/* option: insert a display to view error on LED? */
	}
}



void ssttest()
{
//	u16 i = 0;
	//	u16 j = 0;
	u8 t = 0;
//	u8 buf[128];
//	u32 addr = 0;
t = t;
	t = Read_Status_Register();
	WRSR(0x02);
	t = Read_Status_Register();
	WRSR(0x02);

#if 0
	Sector_Erase(0);

	t = Read_Status_Register();
	Byte_Program(addr, 0x55);

	t = Read_Status_Register();
	t = HighSpeed_Read(addr);

	t = Read_Status_Register();
	addr ++;

	Byte_Program(addr, 'C');
	t = Read_Status_Register();

	t = HighSpeed_Read(addr);

	t = Read_Status_Register();

	Sector_Erase(0x1000);
	for(i = 0; i < 128; i++)
	{
		Byte_Program(0x1000+i, 0x30+i);
	}
	HighSpeed_Read_Cont(0x1000,128,buf);
#endif
	saveHisData();
}

u8 sstFlashWriteStr(u16 sec, u16 offset,u16 len, u8 srcBuf[])
{
	u16 i = 0;
	u32 dst = 0;

	dst = (u32)(sec)*SECSIZE + offset;

	if(offset == 0)
	{
		//Sector_Erase(dst);
	}

	for(i = 0; i < len; i++)
	{
		Byte_Program(dst++, srcBuf[i]);
	}
 return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -