- 00050 void SPI_DeInit(void)
- 00051 {
- 00052 SPI->CR1 = SPI_CR1_RESET_VALUE;
- 00053 SPI->CR2 = SPI_CR2_RESET_VALUE;
- 00054 SPI->ICR = SPI_ICR_RESET_VALUE;
- 00055 SPI->SR = SPI_SR_RESET_VALUE;
- 00056 SPI->CRCPR = SPI_CRCPR_RESET_VALUE;
- 00057 }
- 00058
- 00059 /**
- 00060 * [url=home.php?mod=space&uid=247401]@brief[/url] Initializes the SPI according to the specified parameters.
- 00061 * @param FirstBit : This parameter can be any of the
- 00062 * [url=home.php?mod=space&uid=144993]@ref[/url] SPI_FirstBit_TypeDef enumeration.
- 00063 * @param BaudRatePrescaler : This parameter can be any of the
- 00064 * @ref SPI_BaudRatePrescaler_TypeDef enumeration.
- 00065 * @param Mode : This parameter can be any of the
- 00066 * @ref SPI_Mode_TypeDef enumeration.
- 00067 * @param ClockPolarity : This parameter can be any of the
- 00068 * @ref SPI_ClockPolarity_TypeDef enumeration.
- 00069 * @param ClockPhase : This parameter can be any of the
- 00070 * @ref SPI_ClockPhase_TypeDef enumeration.
- 00071 * @param Data_Direction : This parameter can be any of the
- 00072 * @ref SPI_DataDirection_TypeDef enumeration.
- 00073 * @param Slave_Management : This parameter can be any of the
- 00074 * @ref SPI_NSS_TypeDef enumeration.
- 00075 * @param CRCPolynomial : Configures the CRC polynomial.
- 00076 * @retval None
- 00077 */
- 00078 void SPI_Init(SPI_FirstBit_TypeDef FirstBit, SPI_BaudRatePrescaler_TypeDef BaudRatePrescaler, SPI_Mode_TypeDef Mode, SPI_ClockPolarity_TypeDef ClockPolarity, SPI_ClockPhase_TypeDef ClockPhase, SPI_DataDirection_TypeDef Data_Direction, SPI_NSS_TypeDef Slave_Management, uint8_t CRCPolynomial)
- 00079 {
- 00080 /* Check structure elements */
- 00081 assert_param(IS_SPI_FIRSTBIT_OK(FirstBit));
- 00082 assert_param(IS_SPI_BAUDRATE_PRESCALER_OK(BaudRatePrescaler));
- 00083 assert_param(IS_SPI_MODE_OK(Mode));
- 00084 assert_param(IS_SPI_POLARITY_OK(ClockPolarity));
- 00085 assert_param(IS_SPI_PHASE_OK(ClockPhase));
- 00086 assert_param(IS_SPI_DATA_DIRECTION_OK(Data_Direction));
- 00087 assert_param(IS_SPI_SLAVEMANAGEMENT_OK(Slave_Management));
- 00088 assert_param(IS_SPI_CRC_POLYNOMIAL_OK(CRCPolynomial));
- 00089
- 00090 /* Frame Format, BaudRate, Clock Polarity and Phase configuration */
- 00091 SPI->CR1 = (uint8_t)((uint8_t)((uint8_t)FirstBit | BaudRatePrescaler) |
- 00092 (uint8_t)((uint8_t)ClockPolarity | ClockPhase));
- 00093
- 00094 /* Data direction configuration: BDM, BDOE and RXONLY bits */
- 00095 SPI->CR2 = (uint8_t)((uint8_t)(Data_Direction) | (uint8_t)(Slave_Management));
- 00096
- 00097 if (Mode == SPI_MODE_MASTER)
- 00098 {
- 00099 SPI->CR2 |= (uint8_t)SPI_CR2_SSI;
- 00100 }
- 00101 else
- 00102 {
- 00103 SPI->CR2 &= (uint8_t)~(SPI_CR2_SSI);
- 00104 }
- 00105
- 00106 /* Master/Slave mode configuration */
- 00107 SPI->CR1 |= (uint8_t)(Mode);
- 00108
- 00109 /* CRC configuration */
- 00110 SPI->CRCPR = (uint8_t)CRCPolynomial;
- 00111 }
STM8S103是可以用官方的库的。这里库中对spi的初始化。
|