|
认真阅读了AT45DB041D的编程手册,尤其是关于SPI读写时序、命令的传送,直接在文档中做了笔记。
程序:
- #ifndef __AT45DB014D_H
- #define __AT45DB014D_H
- #include "stm32f10x.h"
- #include "SPI.h"
- #define AT45DB_CS_asserted() GPIO_ResetBits(GPIOA,GPIO_Pin_4);
- #define AT45DB_CS_disasserted() GPIO_SetBits(GPIOA,GPIO_Pin_4);
- enum ReadCommands{
- MainMoryPageRead = 0xD2,
- // ContinuousArrayReadLegacy = 0xE8,
- ContinuousArrayReadLowFreqcy = 0x03,
- ContinuousArrayReadHighFreqcy = 0x0B,
- Buf1ReadLowFreqcy = 0xD1,
- Buf2ReadLowFreqcy = 0xD3,
- Buf1Read = 0xD4,
- Buf2Read = 0xD6
- };
- enum ProgramEraseCommands{
- Buf1Write = 0x84,
- Buf2Write = 0x87,
- Buf1toMaiMoryPageProgramWithBuiltin = 0x83,
- Buf2toMaiMoryPageProgramWithBuiltin = 0x86,
- Buf1toMaiMoryPageProgramNullBuiltin = 0x88,
- Buf2toMaiMoryPageProgramNullBuiltin = 0x89,
- MainMoryPageProgramByBuf1 = 0x82,
- MainMoryPageProgramByBuf2 = 0x85,
- PageEraseCommand = 0x81,
- BlockEraseCommand = 0x50,
- SectorEraseCommand = 0x7C,
- ChipEraseCommand = 0xC7 //C7H + 94H + 80H + 9AH
- };
- enum AdditionalCommands{
- MainMoryPagetoBuf1Transfer = 0x53,
- MainMoryPagetoBuf2Transfer = 0x55,
- MainMoryPagetoBuf1Compare = 0x60,
- MainMoryPagetoBuf2Compare = 0x61,
- AutoPageRewriteByBuf1 = 0x58,
- AutoPageRewriteByBuf2 = 0x59,
- DeepPowerdownCommand = 0xB9,
- ResumefromDeepPowerdownCommand = 0xAB,
- ReadStatusRegisterCommand = 0xD7,
- ManufacturerDeviceIDReadCommand = 0x9F
- };
- enum ProtectionSecurityCommands{
- EnableSectorProtection = 0xA9,//3DH + 2AH + 7FH + A9H
- DisableSectorProtection = 0x9A,//3DH + 2AH + 7FH + 9AH
- EraseSectorProtectionReg = 0xCF,//3DH + 2AH + 7FH + CFH
- ProgramSectorProtectionReg = 0xFC,//3DH + 2AH + 7FH + FCH
- ReadSectorProtectionReg = 0x32,
- SectorLockdownCommand = 0x30,//3DH + 2AH + 7FH + 30H
- ReadSectorLockdownReg = 0x35,
- ProgramSecurityReg = 0x9B,//9BH + 00H + 00H + 00H
- ReadSecurityReg = 0x77
- };
- typedef struct
- {
- u8 READY_BUSY :1 ;
- u8 COMP :1 ;
- u8 PROTECT :1 ;
- u8 PAGE_SIZE :1 ;
- }StatusRegType;
- typedef struct{
- u8 FirstByte;
- u8 SecondByte;
- u8 ThirdByte;
- }ThreeAddressBytesType;
- void Config_AT45DB_CS_1_Pin(void);
- u8 ReadStatusRegister( StatusRegType *StatusRegTypeStruct);
- void ReadSecurityRegister( u8 *Output64Bytes );
- void ReadManufacturerDeviceID( u8 *StoreIC4BytesInfor);
- void ReadSectorProtectionRegister(u8 *Output8Bytes);
- void ReadSectorLockdownRegister(u8 *Output8Bytes);
- void MainMemoryPageRead(u16 PageSize,u16 WhichPage,u16 WhereStart,u16 HowManyBytes,u8 *WhereStore);
- void MainMemoryPageProgramThroughBuffer(u16 PageSize,u8 WhichBuffer,u16 WhichPage,u16 WhereStart,u16 HowManyBytes,u8 *FromWhere );
- void ContinuousArrayRead(u16 PageSize,u16 WhichPage,u16 WhereStart,u8 Speed_66_33MHZ,u32 HowManyBytes,u8 *WhereStore);
- void ChipErase(void);
- void PageErase(u16 PageSize,u16 WhichPage);
- void Block_SectorErase(u16 PageSize,u8 IsBlock0OrSector1,u8 WhichBlock_Sector);
- void BufferRead(u16 PageSize,u8 WhichBuffer,u8 Speed_66_33MHZ,u16 WhereStart,u16 HowManyBytes,u8 *WhereStore);
- void BufferWrite(u16 PageSize,u8 WhichBuffer,u16 WhereStart,u16 HowManyBytes,u8 *FromWhere);
- void AutoPageRewrite(u16 PageSize,u16 WhichPage,u8 WhichBuffer);
- void BuffertoMainMemoryPageWith_NullBuiltInErase(u16 PageSize,u8 WhichBuffer,u16 WhichPage,u8 With_Null_BuiltIn);
- void DeepPowerdown_ON1_OFF0(u8 On1_Off0);
- void EraseSectorProtectionRegister(void);
- void ProgramSectorProtectionRegister(u8 *ProtectedOrNot8Bytes);
- void SectorLockdown(u8 WhichSector0a0b_7);
- void ProgramSecurityRegister(u8 *Input64Bytes);
- void MainMemoryPagetoBufferTransfer(u16 PageSize,u16 FromWhichPage,u8 ToWhichBuffer);
- signed char MainMemoryPagetoBufferCompare(u16 PageSize,u16 WhichPage,u8 WhichBuffer);
- void SectorProtection_ON1_OFF0(u8 On1_Off0);
- void static SendDummyBytes(u8 HowManyDummy);
- void static Send4BytesCommands(u8 OperationCommand, ThreeAddressBytesType *ThreeAddrCommand);
- signed char static Get3AddressBytes_PageBuffer(u16 PageSize,u16 WhichPage,u16 PageStartOrBuffStart);
- signed char static Get3AddressBytes_BlockSector(u16 PageSize, u8 IsBlock0OrSector1,u8 WhichBlock_Sector);
- #endif
复制代码
last but not least, 也请您提出宝贵建议。 |
评分
-
查看全部评分
|