打印

SPI实验擦出操作

[复制链接]
4396|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中的数据混乱。

使用特权

评论回复
5
IJK| | 2013-1-29 09:34 | 只看该作者
LZ应该先下载1个SPI FLASH的datasheet来看,里面有擦除等操作的流程。
另外4L解释得不错

使用特权

评论回复
6
江口工程师| | 2016-9-7 00:54 | 只看该作者

使用特权

评论回复
7
江口工程师| | 2016-9-7 00:56 | 只看该作者
ST SPI WRITE 那位有例程 小弟想学习下,QQ604775543

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

35

主题

105

帖子

0

粉丝