SPI实验擦出操作

[复制链接]
5045|6
 楼主| jy02326166 发表于 2013-1-28 16:44 | 显示全部楼层 |阅读模式
void SPI_FLASH_SectorErase(u32 SectorAddr)
{
  /* Send write enable instruction */
  SPI_FLASH_WriteEnable();
  SPI_FLASH_WaitForWriteEnd();
。。。
}
为什么要这两个操作

void SPI_FLASH_WaitForWriteEnd(void)
{
        u8 FLASH_Status = 0;
       
        /* Select the FLASH: Chip Select low */
        SPI_FLASH_CS_LOW();
       
        /* Send "Read Status Register" instruction */
        SPI_FLASH_SendByte(W25X_ReadStatusReg);
       
        /* Loop as long as the memory is busy with a write cycle */
        do
        {
                /* Send a dummy byte to generate the clock needed by the FLASH
                and put the value of the status register in FLASH_Status variable */
                FLASH_Status = SPI_FLASH_SendByte(Dummy_Byte);         
        }while ((FLASH_Status & WIP_Flag) == SET); /* Write in progress */
       
        /* Deselect the FLASH: Chip Select high */
        SPI_FLASH_CS_HIGH();
}
这个函数是什么意思?
IJK 发表于 2013-1-28 17:27 | 显示全部楼层
很正常,先发出擦除命令,然后查询状态、等待擦除操作完成。
SPI_FLASH_WaitForWriteEnd 就是用于 等待擦除操作完成 的
 楼主| jy02326166 发表于 2013-1-28 20:13 | 显示全部楼层
IJK 发表于 2013-1-28 17:27
很正常,先发出擦除命令,然后查询状态、等待擦除操作完成。
SPI_FLASH_WaitForWriteEnd 就是用于 等待擦除 ...

void SPI_FLASH_SectorErase(u32 SectorAddr)
{
  /* Send write enable instruction */
  SPI_FLASH_WriteEnable();
  SPI_FLASH_WaitForWriteEnd();
  /* Sector Erase */
  /* Select the FLASH: Chip Select low */
  SPI_FLASH_CS_LOW();
  /* Send Sector Erase instruction */
  SPI_FLASH_SendByte(W25X_SectorErase);
  /* Send SectorAddr high nibble address byte */
  SPI_FLASH_SendByte((SectorAddr & 0xFF0000) >> 16);
  /* Send SectorAddr medium nibble address byte */
  SPI_FLASH_SendByte((SectorAddr & 0xFF00) >> 8);
  /* Send SectorAddr low nibble address byte */
  SPI_FLASH_SendByte(SectorAddr & 0xFF);
  /* Deselect the FLASH: Chip Select high */
  SPI_FLASH_CS_HIGH();
  /* Wait the end of Flash writing */
  SPI_FLASH_WaitForWriteEnd();
}
请问前两句有什么用?
SPI_FLASH_WaitForWriteEnd();我还是没懂它的原理
reille 发表于 2013-1-28 20:51 | 显示全部楼层
flash是个慢速设备,写数据(包括擦除)的时候是需要时间的,且写等操作是异步的,因此,在进行一个诸如扇区擦除(就是你指的SPI_FLASH_SectorErase()函数)之前,需要检测flash是否正处在写的状态(busy状态),如果正在写则不能进行其它操作,直到flash的一个写操作完成,才能进行下一个写操作,否则会引起flash中的数据混乱。
IJK 发表于 2013-1-29 09:34 | 显示全部楼层
LZ应该先下载1个SPI FLASH的datasheet来看,里面有擦除等操作的流程。
另外4L解释得不错
江口工程师 发表于 2016-9-7 00:54 | 显示全部楼层
江口工程师 发表于 2016-9-7 00:56 | 显示全部楼层
ST SPI WRITE 那位有例程 小弟想学习下,QQ604775543
您需要登录后才可以回帖 登录 | 注册

本版积分规则

35

主题

105

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部