我写的读写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);
那位大侠帮帮忙,感谢万分! |