STM32写华邦w25X16时读正确,却写不进去,用自己的程序可以读出例程写进去的的字符串,但是自己的程序写不进去内容
/*要写入到W25X16的字符串数组*/
const u8 TEXT_Buffer[]={"神州三号 SPI 读写访问程序"};
#define SIZE sizeof(TEXT_Buffer)
SPI_FLASH_Write_Page(chars,100,SIZE);
/*
SPI在一页内写入数据
NumByte:要写入的字节数(《256),不超过该页的剩余字节数
*/
void SPI_FLASH_Write_Page(u8 *pBuffer, u32 WriteAddr,u16 NumByte)
{
u16 i = 0;
SPI_FLASH_Write_Enable();
SPI_FLASH_CS_Low();
SPI_ReadWriteByte(W25X_PageProgram);//发送写页命令
SPI_ReadWriteByte((u8)((WriteAddr)>>16));//24位地址
SPI_ReadWriteByte((u8)((WriteAddr)>>8));//
SPI_ReadWriteByte((u8)(WriteAddr));//
for( i= 0;i < NumByte;i++)
SPI_ReadWriteByte(pBuffer
);//
SPI_FLASH_CS_High();
SPI_FLASH_Wait_Busy();
}
为什么会写不进去
/*
SPI读写
*/
u8 SPI_ReadWriteByte(u8 TxData)
{
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
/* Send byte through the SPI1 peripheral */
SPI_I2S_SendData(SPI1, TxData);
/* 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);
}
此帖出自小平头技术问答
一周热门 更多>