久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 6232|回復: 0
打印 上一主題 下一主題
收起左側

16MB的FLASHW25Q128驅動

[復制鏈接]
跳轉到指定樓層
樓主
ID:75926 發表于 2015-4-10 17:00 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
  1. #define SPI_SCK_LOW() GPIOB->ODR&=~(1<<3)
  2. #define SPI_SCK_HIGH()         GPIOB->ODR|=1<<3

  3. #define SPI_MOSI_LOW()GPIOB->ODR&=~(1<<5)
  4. #define SPI_MOSI_HIGH()GPIOB->ODR|=1<<5

  5. #define SPI_CS_LOW()GPIOB->ODR&=~(1<<14)
  6. #define SPI_CS_HIGH()        GPIOB->ODR|=1<<14

  7. #define SPI_MISO_Read()(GPIOB->IDR&(1<<4))


  8. #define W25X_WriteEnable          0x06     //寫允許命令
  9. #define W25X_WriteDisable          0x04    //禁止命令
  10. #define W25X_ReadStatusReg      0x05   //讀狀態寄存器
  11. #define W25X_WriteStatusReg      0x01  //寫狀態寄存器
  12. #define W25X_ReadData                0x03  //讀數據
  13. #define W25X_FastReadData         0x0B //快讀
  14. #define W25X_FastReadDual         0x3B  
  15. #define W25X_PageProgram          0x02  //頁寫
  16. #define W25X_BlockErase               0xD8  //快擦除
  17. #define W25X_SectorErase         0x20  //扇區擦除
  18. #define W25X_ChipErase                            0xC7  //整盤擦除
  19. #define W25X_PowerDown                         0xB9  //低功耗
  20. #define W25X_ReleasePowerDown           0xAB
  21. #define W25X_DeviceID                             0xAB
  22. #define W25X_ManufactDeviceID             0x90
  23. #define W25X_JedecDeviceID                 0x9F


  24. static void SPI_SendByte(uint8_t Byte)         //使用SPI總線發送1個字節的數據
  25. {
  26. //uint8_t Cnt;
  27. //SPI_SCK_LOW();
  28. //for(Cnt=0;Cnt<8;Cnt++)
  29. //{
  30. //if(Byte&0x80)
  31. //SPI_MOSI_HIGH();
  32. //else
  33. //SPI_MOSI_LOW();
  34. //SPI_SCK_HIGH();
  35. //Byte<<=1;
  36. //SPI_SCK_LOW();
  37. //}
  38. while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE)==RESET);
  39. SPI_I2S_SendData(SPI1,Byte);
  40. while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE)==RESET);
  41. SPI_I2S_ReceiveData(SPI1);
  42. }

  43. static uint8_t SPI_ReceiveByte(void)   //使用SPI總線接收1個字節的數據
  44. {
  45. //uint8_t Byte=0,Cnt;
  46. ////GPIOB->ODR|=1<<4;
  47. //for(Cnt=0;Cnt<8;Cnt++)
  48. //{
  49. //SPI_SCK_HIGH();
  50. //Byte<<=1;
  51. //if(SPI_MISO_Read())
  52. //Byte++;
  53. //SPI_SCK_LOW();
  54. //}
  55. //return Byte;
  56. while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE)==RESET);
  57. SPI_I2S_SendData(SPI1,0xff);
  58. while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE)==RESET);
  59. return SPI_I2S_ReceiveData(SPI1);
  60. }
  61. /************************FLASH****************************/

  62. uint8_t FLASH_ReadStatusReg(void)   //讀狀態寄存器
  63. {
  64. uint8_t Status;
  65. SPI_CS_LOW();        
  66. SPI_SendByte(W25X_ReadStatusReg);      
  67. Status=SPI_ReceiveByte();        
  68. SPI_CS_HIGH();     
  69. return Status;
  70. }

  71. void FLASH_WriteEnable(void)
  72. {
  73. SPI_CS_LOW();
  74. SPI_SendByte(W25X_WriteEnable);
  75. SPI_CS_HIGH();
  76. }
  77. void FLASH_WriteByte(uint32_t Address,uint8_t Byte)
  78. {
  79. FLASH_WriteEnable();//改變磁盤的操作都需要寫允許命令
  80. SPI_CS_LOW();
  81. SPI_SendByte(W25X_PageProgram);
  82. SPI_SendByte(Address>>16);
  83. SPI_SendByte(Address>>8);
  84. SPI_SendByte(Address);
  85. SPI_SendByte(Byte);
  86. SPI_CS_HIGH();
  87. while(FLASH_ReadStatusReg()&0x01);
  88. }

  89. void FLASH_ReadByte(uint32_t Address ,uint8_t *pByte)
  90. {
  91. SPI_CS_LOW();
  92. SPI_SendByte(W25X_ReadData);
  93. SPI_SendByte(Address>>16);
  94. SPI_SendByte(Address>>8);
  95. SPI_SendByte(Address);
  96. *pByte=SPI_ReceiveByte();
  97. SPI_CS_HIGH();
  98. }

  99. uint16_t FLASH_ReadID(void)
  100. {
  101. uint16_t Temp=0;
  102. SPI_CS_LOW();
  103. SPI_SendByte(W25X_ManufactDeviceID);
  104. SPI_SendByte(0x00);
  105. SPI_SendByte(0x00);
  106. SPI_SendByte(0x00);
  107. Temp|=SPI_ReceiveByte()<<8;
  108. Temp|=SPI_ReceiveByte();
  109. SPI_CS_HIGH();
  110. return Temp;
  111. }

  112. void FLASH_Erase_Sector(uint32_t Address)
  113. {
  114. FLASH_WriteEnable();
  115. while(FLASH_ReadStatusReg()&0x01);
  116. SPI_CS_LOW();
  117. SPI_SendByte(W25X_SectorErase);
  118. SPI_SendByte(Address>>16);
  119. SPI_SendByte(Address>>8);
  120. SPI_SendByte(Address);
  121. SPI_CS_HIGH();
  122. while(FLASH_ReadStatusReg()&0x01);
  123. }

  124. void FLASH_Wrase_Chip(void)
  125. {
  126. FLASH_WriteEnable();
  127. SPI_SendByte(0x00);
  128. while(FLASH_ReadStatusReg()&0x01);
  129. SPI_CS_LOW();
  130. SPI_SendByte(W25X_ChipErase);
  131. SPI_CS_HIGH();
  132. while(FLASH_ReadStatusReg()&0x01);
  133. }
復制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 巨大荫蒂视频欧美另类大 | 国产高清一区二区 | av黄色在线 | 国产精品久久久久久久久久三级 | 人成在线| 日本小电影在线 | 日韩在线免费 | 天天弄天天操 | 亚洲视频在线看 | 国产丝袜一区二区三区免费视频 | 色橹橹欧美在线观看视频高清 | 午夜资源 | 在线看中文字幕 | 国产aⅴ爽av久久久久久久 | 欧美在线小视频 | 国产精品极品美女在线观看免费 | 三级免费 | 久久不卡| 一区二区av在线 | 自拍视频网站 | 精品一区二区不卡 | 亚洲欧美另类在线观看 | 日本在线网站 | 欧美色综合一区二区三区 | 亚洲欧美日韩精品久久亚洲区 | 人人干人人爽 | 国产在线播放av | 久久精品一二三影院 | 欧美精品乱码99久久影院 | 精品视频一区二区三区 | 亚洲国产精品久久久 | 天天干狠狠 | 一级大片免费 | 国产一区二区精 | 97色综合 | 91污在线| 亚洲成av人片在线观看无码 | 亚洲二区视频 | 情侣酒店偷拍一区二区在线播放 | 亚洲三级国产 | 欧美国产视频 |