sst25驱动程序.docx

上传人:b****6 文档编号:8556344 上传时间:2023-01-31 格式:DOCX 页数:20 大小:18.76KB
下载 相关 举报
sst25驱动程序.docx_第1页
第1页 / 共20页
sst25驱动程序.docx_第2页
第2页 / 共20页
sst25驱动程序.docx_第3页
第3页 / 共20页
sst25驱动程序.docx_第4页
第4页 / 共20页
sst25驱动程序.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

sst25驱动程序.docx

《sst25驱动程序.docx》由会员分享,可在线阅读,更多相关《sst25驱动程序.docx(20页珍藏版)》请在冰豆网上搜索。

sst25驱动程序.docx

sst25驱动程序

SST25驱动程序

#defineCMD_RDSR0x05//Read-Status-Register

#defineCMD_EWSR0x50//Enable-Write-Status-Register

#defineCMD_WRSR0x01//Write-Status-Register

#defineCMD_WREN0x06//Write-Enable

#defineCMD_WRDI0x04//Write-Disable

#defineCMD_RDID0x90//ReadChipID

#defineCMD_RDID20xab//ReadChipID

#defineCMD_JEDECID0x9f//ReadJEDECID

#defineCMD_EHLD0xaa//EnableHOLDpinfunctionalityoftheRST/HOLDpin

#defineCMD_RD_SID0x88//ReadSecurityID

#defineCMD_PROG_SID0xa5//ProgramUserSecurityIDarea

#defineCMD_LOCK_SID0x85//LockoutSecurityIDProgramming

#defineCMD_RD0x03//ReadMemory

#defineCMD_FTRD_DIO0xbb//ReadMemorywithDualAddressInputandDataOutput

#defineCMD_FTRD_DO0x3b//ReadMemorywithDualOutput

#defineCMD_HSRD0x0b//ReadMemoryatHigherSpeed

#defineCMD_4K_ERASE0x20//Erase4KByteofmemoryarray

#defineCMD_32K_ERASE0x52//Erase32KByteblockofmemoryarray

#defineCMD_64K_ERASE0xd8//Erase64KByteblockofmemoryarray

#defineCMD_CHIP_ERASE0x60//Erasefullmemoryarray

#defineCMD_CHIP_ERASE20xc7//Erasefullmemoryarray

#defineCMD_PG_PROG0x02//Toprogram1to256databytes

#defineCMD_DIPG_PROG0xa2//Toprogram1to256databytes

#defineSST25_CHIPID0xBF4B

/**************DefinitionsforConstant************/

#defineSST25_CEGPIO_Pin_12//PB12

#defineSST25_WPGPIO_Pin_8//PD8

#defineSST25_HLDGPIO_Pin_9//PD9

#defineSST25_CEPORTGPIOB

#defineSST25_WPPORTGPIOD

#defineSST25_HLDPORTGPIOD

#defineRCC_APB2Periph_GPIO_SST25(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD)

staticvoidSST_FM_HLD_Level(uint8_tlevel)

{

if(level==1)

GPIO_SetBits(SST25_HLDPORT,SST25_HLD);

else

GPIO_ResetBits(SST25_HLDPORT,SST25_HLD);

}

staticvoidSST_FM_WP_Level(uint8_tlevel)

{

if(level==1)

GPIO_SetBits(SST25_WPPORT,SST25_WP);

else

GPIO_ResetBits(SST25_WPPORT,SST25_WP);

}

voidSST_FM_CE_Level(uint8_tlevel)

{

if(level==1){

delay_us(8);

GPIO_SetBits(SST25_CEPORT,SST25_CE);

}else{

GPIO_ResetBits(SST25_CEPORT,SST25_CE);

}

}

/*******************************************************************************

*FunctionName:

SST25_GPIOInit

*Description:

InitializeGPIO(CE\WP\HLD)configurationforSST25

*Input:

None

*Output:

None

*Return:

None

*Attention:

None

*******************************************************************************/

voidSST25_GPIOInit(void)

{

GPIO_InitTypeDefGPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_SST25,ENABLE);

GPIO_InitStructure.GPIO_Pin=SST25_CE;

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;

GPIO_Init(SST25_CEPORT,&GPIO_InitStructure);

SST_FM_CE_Level

(1);

SST_FM_CE_Level(0);

SST_FM_CE_Level

(1);

GPIO_InitStructure.GPIO_Pin=SST25_WP;

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;

GPIO_Init(SST25_WPPORT,&GPIO_InitStructure);

SST_FM_WP_Level

(1);

SST_FM_WP_Level(0);

SST_FM_WP_Level

(1);

GPIO_InitStructure.GPIO_Pin=SST25_HLD;

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;

GPIO_Init(SST25_HLDPORT,&GPIO_InitStructure);

SST_FM_HLD_Level

(1);

SST_FM_HLD_Level(0);

SST_FM_HLD_Level

(1);

}

voidSPI_Send_byte(uint16_tdata)

{

while(SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_TXE)==RESET);

SPI_I2S_SendData(SPI2,data);

while(SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_RXNE)==RESET);

SPI_I2S_ReceiveData(SPI2);

}

uint16_tSPI_Receive_byte(void)

{

while(SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_TXE)==RESET);

SPI_I2S_SendData(SPI2,0x00);

while(SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_RXNE)==RESET);

returnSPI_I2S_ReceiveData(SPI2);

}

/*******************************************************************************

*FunctionName:

SST25_EHLD

*Description:

EnabletheHOLDfunctionalityofRST/HOLDpin

*Input:

None

*Output:

None

*Return:

None

*Attention:

None

*******************************************************************************/

staticvoidSST25_EHLD(void)

{

SST_FM_CE_Level(0);

SPI_Send_byte(CMD_EHLD);

SST_FM_CE_Level

(1);

}

/*******************************************************************************

*FunctionName:

SST25_EWSR

*Description:

Enablewritingstatusregister

*Input:

None

*Output:

None

*Return:

None

*Attention:

None

*******************************************************************************/

staticvoidSST25_EWSR(void)

{

SST_FM_CE_Level(0);

SPI_Send_byte(CMD_EWSR);

SST_FM_CE_Level

(1);

}

/*******************************************************************************

*FunctionName:

SST_FM_WRSR

*Description:

WritethenewvaluetoStatusRegister

*Input:

ddata-thedatatobechangedthestatusofBPxorBPL,

*andonlybits2,3,4,5,7canbewritten.

*Output:

None

*Return:

None

*Attention:

None

*******************************************************************************/

staticvoidSST_FM_WRSR(uint8_tddata)

{

SST_FM_CE_Level(0);

SPI_Send_byte(CMD_WRSR);

SPI_Send_byte(ddata);

SST_FM_CE_Level

(1);

}

/*******************************************************************************

*FunctionName:

SST_FM_WREN

*Description:

SettheWrite-Enable-LatchbitinStatusRegisterto'1'

*allowingWriteoperationstooccur.

*Input:

None

*Output:

None

*Return:

None

*Attention:

None

*******************************************************************************/

staticvoidSST_FM_WREN(void)

{

SST_FM_CE_Level(0);

SPI_Send_byte(CMD_WREN);

SST_FM_CE_Level

(1);

}

/*******************************************************************************

*FunctionName:

SST_FM_WRDI

*Description:

ResettheWrite-Enable-Latchbitto'0'

*topreventanynewWriteoperations.

*Input:

None

*Output:

None

*Return:

None

*Attention:

None

*******************************************************************************/

/*

staticvoidSST_FM_WRDI(uint8_tportnum)

{

SST_FM_CE_Level(portnum,0);

SPI_Send_byte(portnum,CMD_WRDI);

SST_FM_CE_Level(portnum,1);

}

*/

/*******************************************************************************

*FunctionName:

SST25_ReadID

*Description:

Readthemanufacturer'sanddeviceID

*Input:

Addressdata

*Output:

None

*Return:

Thevaleofmanufacturer'sanddeviceID,0xBF4Bwanted

*Attention:

None

*******************************************************************************/

staticuint16_tSST25_ReadID(uint8_tID_addr)

{

uint16_tdev_id=0x00;

SST_FM_CE_Level(0);

SPI_Send_byte(CMD_RDID);

SPI_Send_byte(0x00);//address:

A23-A16

SPI_Send_byte(0x00);//address:

A15-A8

SPI_Send_byte(ID_addr);//address,either00Hor01H

dev_id|=SPI_Receive_byte()<<8;

dev_id|=SPI_Receive_byte();

SST_FM_CE_Level

(1);

returndev_id;

}

/*******************************************************************************

*FunctionName:

SST25_JedecIDRead

*Description:

Readthemanufacturer'sandSST25VF064CdeviceID

*Input:

None

*Output:

None

*Return:

Thevaleofmanufacturer'sanddeviceID,0xBF254Bwanted

*Attention:

None

*******************************************************************************/

/*

staticuint32_tSST25_JedecIDRead(uint8_tportnum)

{

uint32_ttemp=0x00;

SST_FM_CE_Level(portnum,0);

SPI_Send_byte(portnum,CMD_JEDECID);

temp=(temp|SPI_Receive_byte(portnum))<<8;

temp=(temp|SPI_Receive_byte(portnum))<<8;

temp=(temp|SPI_Receive_byte(portnum));//tempvalueshouldbe0xBF254B

SST_FM_CE_Level(portnum,1);

returntemp;

}

*/

/*******************************************************************************

*FunctionName:

SST25_WaitBusy

*Description:

WaituntilnointernalWriteoperationisinprogress

*Input:

None

*Output:

None

*Return:

None

*Attention:

None

*******************************************************************************/

staticvoidSST25_WaitBusy(void)

{

uint8_ttemp=0x00;

uint16_tcnt=0xffff;

//temp=SST_FM_RDSR(portnum);

do{

while(cnt--);

cnt=0xffff;

temp=SST_FM_RDSR();

}while(temp&0x01);

}

/*******************************************************************************

*FunctionName:

SST25_ReadUserSID

*Description:

ReadSecurityID

*Input:

None

*Output:

None

*Return:

None

*Attention:

None

*******************************************************************************/

/*

staticvoidSST25_ReadUserSID(uint8_tportnum,uint8_tDst,uint8_t*p_buf,uint8_tlen)

{

uint8_ti=0;

if(len>32)

len=32;

SST_FM_CE_Level(portnum,0);

SPI_Send_byte(portnum,CMD_RD_SID);

SPI_Send_byte(portnum,Dst&0xff);//address

SPI_Send_byte(portnum,0xff);//dummydata

for(i=0x00;i

p_buf[i]=SPI_Receive_byte(portnum);

SST_FM_CE_Level(portnum,1);

}

*/

/*******************************************************************************

*FunctionName:

SST25_ProgUserSID

*Description:

ProgramSecurityID

*Input:

None

*Output:

None

*Return:

None

*Attention:

None

*******************************************************************************/

/*

staticvoidSST25_ProgUserSID(uint8_tportnum,uint8_t*p_buf,uint8_tlen)

{

uint8_ti=0x00;

if(len>24)

len=24;

SST_FM_WREN(portnum);

SST_FM_CE_Level(portnum,0);

SPI_Send_byte(portnum,CMD_PROG_SID);

SPI_Send_byte

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1