|
- // sst25vfxxx部分
- #ifndef _US_SST25_
- #define _US_SST25_
- #define SST25_READ 0x03
- #define SST25_WRITE 0x02
- #define SST25_AUTO_INCR 0xAF
- #define SST25_SECTOR_EREASE 0x20
- #define SST25_BLOCK_EREASE 0x52
- #define SST25_CHIP_EREASE 0x60
- #define SST25_READ_ID 0x90
- #include "uS_Spi.h"
- #define YES 1
- #define NO 0
- void Chip_Erease(SpiDriverStr Operator);
- U8 readFlash(SpiDriverStr Operator,U32 star_addr);
- void FlashRead(SpiDriverStr Operator,U32 star_addr,U16 len,U8 *buffer);
- void writeFlash(SpiDriverStr Operator,U32 start_addr,U8 date);
- void FlashWrite_Auto_BYTE(SpiDriverStr Operator,U32 start_addr,U16 len,U8 *buffer);
- void FlashWrite_AutoIncrement_BYTE(SpiDriverStr Operator,U32 start_addr,U16 len,U8 *buffer);
- U8 Read_State_Register(SpiDriverStr Operator);
- void StateRegister_Write(SpiDriverStr Operator,U8 NewStatus);
- void Wait_Busy(SpiDriverStr Operator);
- void WREN_Check(SpiDriverStr Operator);
- void Write_EN(SpiDriverStr Operator);
- void Write_DISABLE(SpiDriverStr Operator);
- void State_Register_WR_EN(SpiDriverStr Operator);
- void State_Register_WR(SpiDriverStr Operator) ;
- void Sector_Erease(SpiDriverStr Operator,U32 start_addr);
- void Block_Erease(SpiDriverStr Operator,U32 start_addr);
- U16 Read_ID(SpiDriverStr Operator);
- U32 Flash_Read_ID(SpiDriverStr Operator);
- U32 Test_Read_ID(SpiDriverStr Operator);
- void WREN_Check(SpiDriverStr Operator);
- #endif
- //
- #include "uS_sst25vfxxx.h"
- static void ChipSelect(SpiDriverStr Operator,int NewState)
- {
- if(NewState == YES)
- (*(Operator.SpiCeLow))();
- else
- (*(Operator.SpiCeHigh))();
- }
- //==============================================================================
- U8 Read_State_Register(SpiDriverStr Operator)
- {
- U8 Read_date;
-
- ChipSelect(Operator,YES);
- SpiWrite(Operator,0x05);
- Read_date = SpiRead(Operator);
- ChipSelect(Operator,NO);
- return Read_date;
- }
- void StateRegister_Write(SpiDriverStr Operator,U8 NewStatus)
- {
- ChipSelect(Operator,YES);
- SpiWrite(Operator,0x50);
- ChipSelect(Operator,NO);
-
- ChipSelect(Operator,YES);
- SpiWrite(Operator,0x01);
- SpiWrite(Operator,NewStatus);
- ChipSelect(Operator,NO);
- }
- void State_Register_WR_EN(SpiDriverStr Operator)
- {
- ChipSelect(Operator,YES);
- SpiWrite(Operator,0x50);
- }
- void State_Register_WR(SpiDriverStr Operator)
- {
- ChipSelect(Operator,YES);
- SpiWrite(Operator,0x01);
- ChipSelect(Operator,NO);
- }
- void Wait_Busy(SpiDriverStr Operator)
- {
- while( ( Read_State_Register(Operator) & 0x01) == 0x01);
- }
- void WREN_Check(SpiDriverStr Operator)
- {
- U8 byte;
-
- byte = Read_State_Register(Operator);
- if ((byte&0x02) != 0x02) Write_EN(Operator);
- }
- void Write_EN(SpiDriverStr Operator)
- {
- ChipSelect(Operator,YES);
- SpiWrite(Operator,0x06);
- ChipSelect(Operator,NO);
- }
- void Write_DISABLE(SpiDriverStr Operator)
- {
- ChipSelect(Operator,YES);
- SpiWrite(Operator,0x04);
- ChipSelect(Operator,NO);
- }
- //==============================================================================
- void Chip_Erease(SpiDriverStr Operator)
- {
- ChipSelect(Operator,YES);
- Write_EN(Operator);
- ChipSelect(Operator,YES);
- SpiWrite(Operator,SST25_CHIP_EREASE);
- ChipSelect(Operator,NO);
- }
- U8 readFlash(SpiDriverStr Operator,U32 star_addr)
- {
- U8 byte;
-
- ChipSelect(Operator,YES);
- SpiWrite(Operator,SST25_READ);
- SpiWrite(Operator,(U8)(star_addr>>16));
- SpiWrite(Operator,(U8)(star_addr>>8));
- SpiWrite(Operator,(U8)star_addr);
-
- byte = SpiRead(Operator);
-
- ChipSelect(Operator,NO);
- return byte;
- }
- void writeFlash(SpiDriverStr Operator,U32 start_addr,U8 date)
- {
- Write_EN(Operator);
-
- ChipSelect(Operator,YES);
-
- SpiWrite(Operator,SST25_WRITE);
- SpiWrite(Operator,(U8)(start_addr>>16));
- SpiWrite(Operator,(U8)(start_addr>>8));
- SpiWrite(Operator,(U8)start_addr);
-
- SpiWrite(Operator,date);
- ChipSelect(Operator,NO);
- }
- void Sector_Erease(SpiDriverStr Operator,U32 start_addr)
- {
- Write_EN(Operator);
- ChipSelect(Operator,YES);
- SpiWrite(Operator,SST25_SECTOR_EREASE);
- SpiWrite(Operator,(U8)(start_addr>>8));
- SpiWrite(Operator,(U8)start_addr);
-
- ChipSelect(Operator,NO);
- }
- void Block_Erease(SpiDriverStr Operator,U32 start_addr)
- {
- Write_EN(Operator);
- ChipSelect(Operator,YES);
- SpiWrite(Operator,SST25_BLOCK_EREASE);
- SpiWrite(Operator,(U8)(start_addr>>8));
- SpiWrite(Operator,(U8)start_addr);
- ChipSelect(Operator,NO);
- }
复制代码 |
|