main.c:
#include "stm32f10x_lib.h"#include "hw_conf.h"#include"SST25V.h"void delay(int d);u8 Tx_Buffer[] = {0x72,0x62,0x02,0x78,0x60,0x96,0x86,0x79,0x85,0x24,0x36,0x48,0x56,0x68,0x70,0x75,0x88,0x24};u8 Rx_Buffer[BufferSize];u8 DataByte=0;int main(void){#ifdef DEBUGdebug();#endifSetup_System(); //系统启动SST25V_Init(); //Flash芯片初始化SST25V_ChipErase(); //擦除整个芯片空间DataByte = SST25V_ByteRead(0x000000); //读取0x000000地址空间的数据信息DataByte = SST25V_ByteRead(0x000010); //读取0x000000地址空间的数据信息DataByte = SST25V_ByteRead(0x000100); //读取0x000100地址空间的数据信息DataByte = SST25V_ByteRead(0x001000); //读取0x001000地址空间的数据信息DataByte = SST25V_ByteRead(0x010000); //读取0x010000地址空间的数据信息DataByte = SST25V_ByteRead(0x100000); //读取0x100000地址空间的数据信息DataByte = SST25V_ByteRead(0x600000); //读取0x000000地址空间的数据信息DataByte = SST25V_ByteRead(0xF00000); //读取0x600000地址空间的数据信息DataByte = SST25V_ByteRead(0xFFFFFF); //读取0xFFFFFF地址空间的数据信息SST25V_AAI_WriteBytes(0x72, 0xFFF000,0x001000); //向以0xFFF000为开端地址的数据空间写入0x001000个0x10--即向最终4KB空间写入0x10DataByte = SST25V_ByteRead(0x000000); //读取0x000000地址空间的数据信息DataByte = SST25V_ByteRead(0x000001); //读取0x000001地址空间的数据信息DataByte = SST25V_ByteRead(0x000002); //读取0x000002地址空间的数据信息DataByte = SST25V_ByteRead(0xFFF000); //读取0xFFF000地址空间的数据信息DataByte = SST25V_ByteRead(0xFFF0EE); //读取0xFFF0EE地址空间的数据信息DataByte = SST25V_ByteRead(0xFFFEEE); //读取0xFFFEEE地址空间的数据信息DataByte = SST25V_ByteRead(0xFFFFFF); //读取0xFFFFFF地址空间的数据信息SST25V_SectorErase_4KByte(0xFFF000); //擦除以0xFFF000为开端地址的4KB数据空间DataByte = SST25V_ByteRead(0x000000); //读取0x000000地址空间的数据信息DataByte = SST25V_ByteRead(0xFFF000); //读取0xFFF000地址空间的数据信息DataByte = SST25V_ByteRead(0x000001); //读取0x000001地址空间的数据信息DataByte = SST25V_ByteRead(0x000002); //读取0x000002地址空间的数据信息DataByte = SST25V_ByteRead(0xFFEEEE); //读取0xFFEEEE地址空间的数据信息DataByte = SST25V_ByteRead(0xFFFFFF); //读取0xFFFFFF地址空间的数据信息//SST25V_BufferWrite(Tx_Buffer,0xFFF000,16); //将Tx_Buffer中的16个字节数据写入以0xFFF000为开端地址的数据空间SST25V_AAI_BufferProgram(Tx_Buffer,0xFFF000,16); //选用AAI形式,将Tx_Buffer中的16个字节数据写入以0xFFF000为开端地址的数据空间SST25V_BufferRead(Rx_Buffer,0xFFF000,16); //读出0xFFF000为开端地址的16字节数据,存放于Rx_Buffer中DataByte = SST25V_ByteRead(0xFFEEEE); //读取0xFFEEEE地址空间的数据信息while (1){if(Rx_Buffer[0]==0x72){GPIO_WriteBit(GPIOC,GPIO_Pin_6,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOC,GPIO_Pin_6)));delay(100);}if(Rx_Buffer[1]==0x62){GPIO_WriteBit(GPIOC,GPIO_Pin_7,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOC,GPIO_Pin_7)));delay(100);}if(Rx_Buffer[2]==0x02){GPIO_WriteBit(GPIOC,GPIO_Pin_4,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOC,GPIO_Pin_4)));delay(100);}if(Rx_Buffer[3]==0x78){GPIO_WriteBit(GPIOC,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOC,GPIO_Pin_5)));delay(100);}}}void delay(int d){int i = 0;for ( ;d;--d)for (i = 0;i<10000;i++);}SST25VF.c:#include "stm32f10x_lib.h"#include "SST25V.h"void SST25V_Init(void) //Flash芯片初始化{SST25V_CS_HIGH(); //片选CS#管脚置高--不选中芯片SST25V_WP_HIGH(); //维护WP#管脚置高--BPL的状况决议是否答应写状况寄存器SST25V_HOLD_HIGH(); //坚持HOLD#管脚置高SST25V_WriteStatusRegister(0x02); //给状况寄存器写入数据02SST25V_DBSY(); //制止AAI形式时,SO脚输出忙状况}u8 SST25V_ByteRead(u32 ReadAddr) //从ReadAddr地址读取一个字节数据{u8 Temp = 0;SST25V_CS_LOW(); //片选端置低--选中芯片SPI_Flash_SendByte(Read_Data); //发送读取数据指令SPI_Flash_SendByte((ReadAddr & 0xFF0000) >> 16); //发送24位的读取数据地址SPI_Flash_SendByte((ReadAddr& 0xFF00) >> 8);SPI_Flash_SendByte(ReadAddr & 0xFF);Temp = SPI_Flash_ReceiveByte(); //接纳读取到的数据SST25V_CS_HIGH(); //片选CS#管脚置高--不选中芯片return Temp; //回来读取到的数据}void SST25V_BufferRead(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead)//从ReadAddr地址开端读取NumByteToRead个字节数据{SST25V_CS_LOW(); //片选端置低--选中芯片SPI_Flash_SendByte(Read_Data); //发送读取数据指令SPI_Flash_SendByte((ReadAddr & 0xFF0000) >> 16); //发送24位的读取数据开端地址SPI_Flash_SendByte((ReadAddr& 0xFF00) >> 8);SPI_Flash_SendByte(ReadAddr & 0xFF);while(NumByteToRead--) //判别是否完结读取NumByteToRead个字节数据{*pBuffer = SPI_Flash_ReceiveByte(); //承受读取到的数据,并存储于pBuffer中pBuffer++; //pBuffer指针自增1}SST25V_CS_HIGH(); //片选CS#管脚置高--不选中芯片}u8 SST25V_HighSpeedByteRead(u32 ReadAddr) //从ReadAddr高速读取一个字节数据{u32 Temp = 0;SST25V_CS_LOW(); //片选端置低--选中芯片SPI_Flash_SendByte(HighSpeedReadData); //发送快速读取数据指令SPI_Flash_SendByte((ReadAddr & 0xFF0000) >> 16); //发送24位的读取数据地址SPI_Flash_SendByte((ReadAddr& 0xFF00) >> 8);SPI_Flash_SendByte(ReadAddr & 0xFF);SPI_Flash_SendByte(Dummy_Byte); //发送虚拟字节数据Temp = SPI_Flash_ReceiveByte(); //接纳读取到的数据SST25V_CS_HIGH(); //片选CS#管脚置高--不选中芯片return Temp; //回来读取到的数据}void SST25V_HighSpeedBufferRead(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead)//从ReadAddr开端高速读取NumByteToRead个字节数据,并存储于pBuffer中{SST25V_CS_LOW(); //片选端置低--选中芯片SPI_Flash_SendByte(HighSpeedReadData); //发送快速读取数据指令SPI_Flash_SendByte((ReadAddr & 0xFF0000) >> 16); //发送24位的读取数据开端地址SPI_Flash_SendByte((ReadAddr& 0xFF00) >> 8);SPI_Flash_SendByte(ReadAddr & 0xFF);SPI_Flash_SendByte(Dummy_Byte); //发送虚拟字节数据while(NumByteToRead--) //判别是否完结读取NumByteToRead个字节数据{*pBuffer = SPI_Flash_ReceiveByte(); //承受读取到的数据,并存储于pBuffer中pBuffer++; //pBuffer指针自增1}SST25V_CS_HIGH(); //片选CS#管脚置高--不选中芯片}u8 SPI_Flash_SendByte(u8 byte) //SPI发送数据{while(SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == RESET); //等候SPI1的Tx buffer为空SPI_SendData(SPI1, byte); //发送数据字节bytewhile(SPI_GetFlagStatus(SPI1, SPI_FLAG_RXNE) == RESET); //等候SPI1完结数据接纳return SPI_ReceiveData(SPI1); //回来读取到的数据}u8 SPI_Flash_ReceiveByte(void) //SPI接纳数据{return (SPI_Flash_SendByte(Dummy_Byte)); //发送虚拟字节,供给接纳数据时钟}void SST25V_ByteWrite(u8 Byte, u32 WriteAddr) //写入一个数据字节{SST25V_WriteEnable(); //答应写入操作SST25V_CS_LOW(); //片选端置低--选中芯片SPI_Flash_SendByte(Byte_Program); //发送写数据指令SPI_Flash_SendByte((WriteAddr & 0xFF0000) >> 16); //发送24位的写入数据地址SPI_Flash_SendByte((WriteAddr & 0xFF00) >> 8);SPI_Flash_SendByte(WriteAddr & 0xFF);SPI_Flash_SendByte(Byte); //发送要写入的数据SST25V_CS_HIGH(); //片选CS#管脚置高--不选中芯片SST25V_WaitForWriteEnd(); //等候写操作完结}void SST25V_BufferWrite(u8 *pBuffer,u32 Addr,u16 BufferLength)//将pBuffer中的BufferLength个字节数据写入到以Addr为开端地址的区域{while(BufferLength--) //判别是否完结写入NumByteToRead个字节数据{SST25V_ByteWrite(*pBuffer,Addr); //把当时pBuffer对应的数据,写入当时Addr中pBuffer++; //数据指针自增1Addr++; //写入地址自增1}}