找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2033|回复: 0
打印 上一主题 下一主题
收起左侧

学习SPI之我为AT45DB041D写驱动程序

[复制链接]
跳转到指定楼层
楼主
认真阅读了AT45DB041D的编程手册,尤其是关于SPI读写时序、命令的传送,直接在文档中做了笔记。
感兴趣的伙伴可以下载查看。这里推荐TI公司制作的关于SPI mode讲解视频:SPI modes tutorial

程序:
  1. #ifndef __AT45DB014D_H
  2. #define __AT45DB014D_H

  3. #include "stm32f10x.h"
  4. #include "SPI.h"

  5. #define AT45DB_CS_asserted()                   GPIO_ResetBits(GPIOA,GPIO_Pin_4);
  6. #define AT45DB_CS_disasserted()         GPIO_SetBits(GPIOA,GPIO_Pin_4);

  7. enum ReadCommands{
  8.         MainMoryPageRead                         = 0xD2,
  9. //        ContinuousArrayReadLegacy          = 0xE8,
  10.         ContinuousArrayReadLowFreqcy       = 0x03,
  11.         ContinuousArrayReadHighFreqcy       = 0x0B,
  12.         Buf1ReadLowFreqcy                        = 0xD1,
  13.         Buf2ReadLowFreqcy                        = 0xD3,
  14.         Buf1Read                                       = 0xD4,
  15.         Buf2Read                                        = 0xD6
  16. };

  17. enum ProgramEraseCommands{
  18.         Buf1Write                                                = 0x84,
  19.         Buf2Write                                                = 0x87,
  20.         Buf1toMaiMoryPageProgramWithBuiltin        = 0x83,
  21.         Buf2toMaiMoryPageProgramWithBuiltin        = 0x86,
  22.         Buf1toMaiMoryPageProgramNullBuiltin         = 0x88,
  23.         Buf2toMaiMoryPageProgramNullBuiltin       = 0x89,
  24.         MainMoryPageProgramByBuf1                   = 0x82,
  25.         MainMoryPageProgramByBuf2                  = 0x85,
  26.         PageEraseCommand                               = 0x81,
  27.         BlockEraseCommand                             = 0x50,
  28.         SectorEraseCommand                             = 0x7C,
  29.         ChipEraseCommand                                = 0xC7 //C7H + 94H + 80H + 9AH
  30. };

  31. enum AdditionalCommands{
  32.         MainMoryPagetoBuf1Transfer                          = 0x53,
  33.         MainMoryPagetoBuf2Transfer                         = 0x55,
  34.         MainMoryPagetoBuf1Compare                          = 0x60,
  35.         MainMoryPagetoBuf2Compare                          = 0x61,
  36.         AutoPageRewriteByBuf1                                    = 0x58,
  37.         AutoPageRewriteByBuf2                                   = 0x59,
  38.         DeepPowerdownCommand                             = 0xB9,
  39.         ResumefromDeepPowerdownCommand          = 0xAB,
  40.         ReadStatusRegisterCommand                       = 0xD7,
  41.         ManufacturerDeviceIDReadCommand         = 0x9F
  42. };
  43. enum ProtectionSecurityCommands{
  44.         EnableSectorProtection                  = 0xA9,//3DH + 2AH + 7FH + A9H
  45.         DisableSectorProtection                 = 0x9A,//3DH + 2AH + 7FH + 9AH
  46.         EraseSectorProtectionReg            = 0xCF,//3DH + 2AH + 7FH + CFH
  47.         ProgramSectorProtectionReg         = 0xFC,//3DH + 2AH + 7FH + FCH
  48.         ReadSectorProtectionReg              = 0x32,
  49.         SectorLockdownCommand            = 0x30,//3DH + 2AH + 7FH + 30H
  50.         ReadSectorLockdownReg               = 0x35,
  51.         ProgramSecurityReg                       = 0x9B,//9BH + 00H + 00H + 00H
  52.         ReadSecurityReg                            = 0x77
  53. };

  54. typedef struct  
  55. {
  56.         u8 READY_BUSY :1 ;
  57.         u8 COMP           :1 ;
  58.         u8 PROTECT       :1 ;
  59.         u8 PAGE_SIZE    :1 ;
  60. }StatusRegType;

  61. typedef struct{
  62.         u8 FirstByte;
  63.         u8 SecondByte;
  64.         u8 ThirdByte;
  65. }ThreeAddressBytesType;

  66. void Config_AT45DB_CS_1_Pin(void);
  67. u8 ReadStatusRegister( StatusRegType *StatusRegTypeStruct);
  68. void ReadSecurityRegister( u8 *Output64Bytes );
  69. void ReadManufacturerDeviceID( u8 *StoreIC4BytesInfor);
  70. void ReadSectorProtectionRegister(u8 *Output8Bytes);
  71. void ReadSectorLockdownRegister(u8 *Output8Bytes);
  72. void MainMemoryPageRead(u16 PageSize,u16 WhichPage,u16 WhereStart,u16 HowManyBytes,u8 *WhereStore);
  73. void MainMemoryPageProgramThroughBuffer(u16 PageSize,u8 WhichBuffer,u16 WhichPage,u16 WhereStart,u16 HowManyBytes,u8 *FromWhere );
  74. void ContinuousArrayRead(u16 PageSize,u16 WhichPage,u16 WhereStart,u8 Speed_66_33MHZ,u32 HowManyBytes,u8 *WhereStore);
  75. void ChipErase(void);
  76. void PageErase(u16 PageSize,u16 WhichPage);
  77. void Block_SectorErase(u16 PageSize,u8 IsBlock0OrSector1,u8 WhichBlock_Sector);
  78. void BufferRead(u16 PageSize,u8 WhichBuffer,u8 Speed_66_33MHZ,u16 WhereStart,u16 HowManyBytes,u8 *WhereStore);
  79. void BufferWrite(u16 PageSize,u8 WhichBuffer,u16 WhereStart,u16 HowManyBytes,u8 *FromWhere);
  80. void AutoPageRewrite(u16 PageSize,u16 WhichPage,u8 WhichBuffer);
  81. void BuffertoMainMemoryPageWith_NullBuiltInErase(u16 PageSize,u8 WhichBuffer,u16 WhichPage,u8 With_Null_BuiltIn);
  82. void DeepPowerdown_ON1_OFF0(u8 On1_Off0);
  83. void EraseSectorProtectionRegister(void);
  84. void ProgramSectorProtectionRegister(u8 *ProtectedOrNot8Bytes);
  85. void SectorLockdown(u8 WhichSector0a0b_7);
  86. void ProgramSecurityRegister(u8 *Input64Bytes);
  87. void MainMemoryPagetoBufferTransfer(u16 PageSize,u16 FromWhichPage,u8 ToWhichBuffer);
  88. signed char MainMemoryPagetoBufferCompare(u16 PageSize,u16 WhichPage,u8 WhichBuffer);
  89. void SectorProtection_ON1_OFF0(u8 On1_Off0);
  90. void static SendDummyBytes(u8 HowManyDummy);
  91. void static Send4BytesCommands(u8 OperationCommand, ThreeAddressBytesType *ThreeAddrCommand);
  92. signed char static Get3AddressBytes_PageBuffer(u16 PageSize,u16 WhichPage,u16 PageStartOrBuffStart);
  93. signed char static Get3AddressBytes_BlockSector(u16 PageSize, u8 IsBlock0OrSector1,u8 WhichBlock_Sector);
  94. #endif
复制代码

last but not least, 也请提出宝贵建议。

1.PNG (144.55 KB, 下载次数: 50)

头文件

头文件

AT45DB041D代码Projet.7z

201.36 KB, 下载次数: 29, 下载积分: 黑币 -5

AT45DB041D-SU 编程手册阅读笔记.pdf

1.79 MB, 下载次数: 22, 下载积分: 黑币 -5

评分

参与人数 1黑币 +80 收起 理由
admin + 80 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表