STM32F103与STM32F407的SPI调试笔记

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gaoweiweiw/article/details/72122643

在写入SPI数据数,必须调用

SPI_I2S_ReceiveData(SPI1);读取一次,不然会对数据的读取不正确

u8 SPI_Flash_GetChar(void){
 
u8 Data = 0;


Data = SPI_I2S_ReceiveData(SPI1);//必须读取一次,应该是读后清空寄存器
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
//SPI_I2S_ClearITPendingBit(SPI1,SPI_I2S_FLAG_TXE);
SPI_I2S_SendData(SPI1, 0xff);
 
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);


//SPI_I2S_ClearITPendingBit(SPI1,SPI_I2S_FLAG_RXNE);
Data = SPI_I2S_ReceiveData(SPI1);

while ((SPI1->SR & BSY) == 0x80);
return Data;


}






/*******************************************************************************
* Function Name  : SPI_Flash_PutChar
* Description    : ´ÓSPI1·¢ËÍÒ»¸ö×Ö½Ú
* Input          : outb--the byte to be sended 
* Output         : None
* Return         : None
*******************************************************************************/
void SPI_Flash_PutChar(u8 Byte)
{  


while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);


SPI_I2S_SendData(SPI1, Byte);


  //while ((SPI1->SR & BSY) == 0x80);
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);//µÈ´ý½ÓÊÕÍêÒ»¸öbyte  
SPI_I2S_ReceiveData(SPI1);///必须读取一次,应该是读后清空寄存器

}

展开阅读全文

没有更多推荐了,返回首页