打印
[STM32F0]

stm32f0 spi读写flash问题

[复制链接]
4740|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
胡斯哲|  楼主 | 2014-2-25 12:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 胡斯哲 于 2014-2-25 15:57 编辑

用的是XX的程序,自己焊的板子
spi能够把W25Q16的flashID和deviceID读出来 ,分别是679509和20
单写进去一个1  读出示个255
求各位高手判断是哪的错误   或者给个f0的程序
沙发
mmuuss586| | 2014-2-25 13:47 | 只看该作者

只有AT45B的,基于F4。
可能芯片有问题吧

at45db.rar

1.8 KB

1

使用特权

评论回复
板凳
sxhhhjicbb| | 2014-2-25 15:53 | 只看该作者
写命令用错了也是一种可能。

使用特权

评论回复
地板
胡斯哲|  楼主 | 2014-2-25 16:08 | 只看该作者
mmuuss586 发表于 2014-2-25 13:47
只有AT45B的,基于F4。
可能芯片有问题吧

先谢谢啦   
读的出id都会有问题吗?

使用特权

评论回复
5
胡斯哲|  楼主 | 2014-2-25 16:16 | 只看该作者
本帖最后由 胡斯哲 于 2014-2-25 16:17 编辑
sxhhhjicbb 发表于 2014-2-25 15:53
写命令用错了也是一种可能。

写命令跟野火的程序几乎一样
就几个宏有差别
/*******************************************************************************
* Function Name  : SPI_FLASH_BufferWrite
* Description    : Writes block of data to the FLASH. In this function, the
*                  number of WRITE cycles are reduced, using Page WRITE sequence.
* Input          : - pBuffer : pointer to the buffer  containing the data to be
*                    written to the FLASH.
*                  - WriteAddr : FLASH's internal address to write to.
*                  - NumByteToWrite : number of bytes to write to the FLASH.
* Output         : None
* Return         : None
*******************************************************************************/
void SPI_FLASH_BufferWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
{
  uint8_t NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0, temp = 0;

  Addr = WriteAddr % SPI_FLASH_PageSize;
  count = SPI_FLASH_PageSize - Addr;
  NumOfPage =  NumByteToWrite / SPI_FLASH_PageSize;
  NumOfSingle = NumByteToWrite % SPI_FLASH_PageSize;

  if (Addr == 0) /* WriteAddr is SPI_FLASH_PageSize aligned  */
  {
    if (NumOfPage == 0) /* NumByteToWrite < SPI_FLASH_PageSize */
    {
      SPI_FLASH_PageWrite(pBuffer, WriteAddr, NumByteToWrite);
    }
    else /* NumByteToWrite > SPI_FLASH_PageSize */
    {
      while (NumOfPage--)
      {
        SPI_FLASH_PageWrite(pBuffer, WriteAddr, SPI_FLASH_PageSize);
        WriteAddr +=  SPI_FLASH_PageSize;
        pBuffer += SPI_FLASH_PageSize;
      }

      SPI_FLASH_PageWrite(pBuffer, WriteAddr, NumOfSingle);
    }
  }
  else /* WriteAddr is not SPI_FLASH_PageSize aligned  */
  {
    if (NumOfPage == 0) /* NumByteToWrite < SPI_FLASH_PageSize */
    {
      if (NumOfSingle > count) /* (NumByteToWrite + WriteAddr) > SPI_FLASH_PageSize */
      {
        temp = NumOfSingle - count;

        SPI_FLASH_PageWrite(pBuffer, WriteAddr, count);
        WriteAddr +=  count;
        pBuffer += count;

        SPI_FLASH_PageWrite(pBuffer, WriteAddr, temp);
      }
      else
      {
        SPI_FLASH_PageWrite(pBuffer, WriteAddr, NumByteToWrite);
      }
    }
    else /* NumByteToWrite > SPI_FLASH_PageSize */
    {
      NumByteToWrite -= count;
      NumOfPage =  NumByteToWrite / SPI_FLASH_PageSize;
      NumOfSingle = NumByteToWrite % SPI_FLASH_PageSize;

      SPI_FLASH_PageWrite(pBuffer, WriteAddr, count);
      WriteAddr +=  count;
      pBuffer += count;

      while (NumOfPage--)
      {
        SPI_FLASH_PageWrite(pBuffer, WriteAddr, SPI_FLASH_PageSize);
        WriteAddr +=  SPI_FLASH_PageSize;
        pBuffer += SPI_FLASH_PageSize;
      }

      if (NumOfSingle != 0)
      {
        SPI_FLASH_PageWrite(pBuffer, WriteAddr, NumOfSingle);
      }
    }
  }
}

使用特权

评论回复
6
airwill| | 2014-2-25 17:26 | 只看该作者
spi 对于 W25Q16, SPI 是通用的, 其他芯片的代码也能用的

上传一份 coIde 下的 w25x 的驱动代码, 写得很规范, 不过更适合在 gccarm 下编译.
W25X.zip (9.41 KB)

使用特权

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

本版积分规则

个人签名:读书喝茶,不争朝夕

141

主题

1431

帖子

6

粉丝