当前位置: 代码迷 >> 单片机 >> stm32之FLASH的使用,该怎么处理
  详细解决方案

stm32之FLASH的使用,该怎么处理

热度:254   发布时间:2016-04-28 14:44:54.0
stm32之FLASH的使用
小弟最近在玩STM32 的SPI通讯方式,FLASH使用的是W25Q64,我看datasheet上说:扇区擦除的最小单位是扇区(而扇区的大小是4KB)
void SPI_SectorErase(u32 SectorAddr)
{
SPI_WriteEnable();
SPI_WaitForWriteEnd();
SPI_FLASH_Low();
SPI_FLASH_SendByte(W25X_SectorErase);
SPI_FLASH_SendByte((SectorAddr&0xff0000)>>16);//这里0xff是2^4,不是4KB啊,为什么一次擦书的大小是2^4Byte?
SPI_FLASH_SendByte((SectorAddr&0xff00)>>8);
SPI_FLASH_SendByte(SectorAddr&0xff);
SPI_FLASH_High();
SPI_WaitForWriteEnd();
}

------解决思路----------------------
    SPI_FLASH_SendByte((SectorAddr&0xff0000)>>16);//设置扇区地址的第三字节
    SPI_FLASH_SendByte((SectorAddr&0xff00)>>8);//设置扇区地址的第二字节
    SPI_FLASH_SendByte(SectorAddr&0xff);//设置扇区地址的低字节
  相关解决方案