打印

SPI方式读写sst25vf032b

[复制链接]
2624|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
longmeixuehai|  楼主 | 2011-7-20 16:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我写的读写sst25vf032b的程序,用串口方式显示出来的id不知为什么一直会是0xffffff,
u32 Jedec_ID_Read(void)
{
u32 temp = 0;
SPI_FLASH_CS_LOW();    /* enable device */
SPI_FLASH_SendByte(0x9F);   /* send JEDEC ID command (9Fh) */
temp = (temp | SPI_FLASH_ReadByte()) << 8; /* receive byte */
temp = (temp | SPI_FLASH_ReadByte()) << 8;
temp = (temp | SPI_FLASH_ReadByte());   /* temp value = 0xBF254A */
SPI_FLASH_CS_HIGH();    /* disable device */
return temp;
}

u8 SPI_FLASH_SendByte(u8 byte)
{
  /* Loop while DR register in not emplty */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
  /* Send byte through the SPI2 peripheral */
  SPI_I2S_SendData(SPI1, byte);
  /* Wait to receive a byte */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
  /* Return the byte read from the SPI bus */
  return SPI_I2S_ReceiveData(SPI1);
}
SPI配置
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPI1, &SPI_InitStructure);
  /* Enable SPI1  */
  SPI_Cmd(SPI1, ENABLE);

那位大侠帮帮忙,感谢万分!

相关帖子

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

本版积分规则

0

主题

5

帖子

1

粉丝