spi通信时序图详解 spi四种工作模式时序图( 三 )


/***************************************************************************//************************* éè??SPIμ?2?êy ***********************************//***************************************************************************/
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//????è???1¤SPI?£ê?SPI_InitStructure.SPI_Mode = SPI_Mode_Master;//?÷?ú?£ê?SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //8??SPISPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;//ê±?óDü????μ???SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;//?úμú?t??ê±?ó2é?ˉêy?YSPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//Nssê1ó?èí?t????/* ????2¨ì??ê?¤·??μ?a256 */SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;//′ó×??????aê?′?ê?SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Cmd(SPI2, ENABLE);SPI_Init(SPI2, &SPI_InitStructure);}
/***************************************************************************** Function Name: SPI1_SetSpeed* Description: éè??SPI1μ?′?ê??ù?è?£* Input: ?ù?è2¨ì??ê·??μ* Output: None* Return: None****************************************************************************/
void SPI1_SetSpeed(uint8_t speed){SPI1->CR1 &= 0xFFC7;SPI1->CR1 |= speed;SPI_Cmd(SPI1, ENABLE);
}
/***************************************************************************** Function Name: SPI2_SetSpeed* Description: éè??SPI2μ?·??μêy£?ò???±?SPI2μ??ù?è.* Input: Speed£o·??μêy* Output: None* Return: None****************************************************************************/
void SPI2_SetSpeed(uint8_t Speed){
SPI2->CR1 &= 0xFFC7;SPI2->CR1 |= Speed;SPI_Cmd(SPI2,ENABLE);
}
/***************************************************************************** Function Name: SPI1_WriteReadData* Description: ê1ó?SPI1D′è?ò???×??úêy?Yí?ê±?áè?ò???×??úêy?Y?£* Input: dat£oòaD′μ?8??êy?Y* Output: None* Return: ?áè?μ?μ?8??êy?Y****************************************************************************/
uint8_t SPI1_WriteReadData(uint8_t dat){uint16_t i = 0;
/* μ±·¢?í?o3??÷?? */ while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET){i++;if(i > 10000){return 0xFF;}}
/* ·¢?íêy?Y */SPI_I2S_SendData(SPI1, dat);
/* μè′y?óê??o3??÷?a·??? */while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
/* ???áè?μ?μ?êy?μ·μ?? */ return SPI_I2S_ReceiveData(SPI1);}
/***************************************************************************** Function Name: SPI2_WriteReadData* Description: ê1ó?SPI2D′è?ò???×??úêy?Yí?ê±?áè?ò???×??úêy?Y?£* Input: dat£oD′è?μ?êy?Y* Output: None* Return: ?áè?μ?μ?êy?Y** ?áè?꧰ü·μ??0xFF****************************************************************************/
uint8_t SPI2_WriteReadData(uint8_t dat){uint16_t i = 0;
/* μ±·¢?í?o3??÷?? */ while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET){i++;if(i > 10000){return 0xFF;}}
/* ·¢?íêy?Y */SPI_I2S_SendData(SPI2, dat);
/* μè′y?óê??o3??÷?a·??? */while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
【spi通信时序图详解 spi四种工作模式时序图】 /* ???áè?μ?μ?êy?μ·μ?? */ return SPI_I2S_ReceiveData(SPI2);}