2 ******************************************************************************
\r
3 * @file stm32l1xx_spi.c
\r
4 * @author MCD Application Team
\r
7 * @brief This file provides all the SPI firmware functions.
\r
8 ******************************************************************************
\r
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
\r
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
\r
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
\r
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
\r
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
18 * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
\r
21 /* Includes ------------------------------------------------------------------*/
\r
22 #include "stm32l1xx_spi.h"
\r
23 #include "stm32l1xx_rcc.h"
\r
25 /** @addtogroup STM32L1xx_StdPeriph_Driver
\r
30 * @brief SPI driver modules
\r
34 /** @defgroup SPI_Private_TypesDefinitions
\r
43 /** @defgroup SPI_Private_Defines
\r
47 /* SPI registers Masks */
\r
48 #define CR1_CLEAR_MASK ((uint16_t)0x3040)
\r
54 /** @defgroup SPI_Private_Macros
\r
62 /** @defgroup SPI_Private_Variables
\r
70 /** @defgroup SPI_Private_FunctionPrototypes
\r
78 /** @defgroup SPI_Private_Functions
\r
83 * @brief Deinitializes the SPIx peripheral registers to their default
\r
85 * @param SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
88 void SPI_DeInit(SPI_TypeDef* SPIx)
\r
90 /* Check the parameters */
\r
91 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
95 /* Enable SPI1 reset state */
\r
96 RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
\r
97 /* Release SPI1 from reset state */
\r
98 RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
\r
104 /* Enable SPI2 reset state */
\r
105 RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
\r
106 /* Release SPI2 from reset state */
\r
107 RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
\r
113 * @brief Initializes the SPIx peripheral according to the specified
\r
114 * parameters in the SPI_InitStruct.
\r
115 * @param SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
116 * @param SPI_InitStruct: pointer to a SPI_InitTypeDef structure that
\r
117 * contains the configuration information for the specified SPI peripheral.
\r
120 void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)
\r
122 uint16_t tmpreg = 0;
\r
124 /* check the parameters */
\r
125 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
127 /* Check the SPI parameters */
\r
128 assert_param(IS_SPI_DIRECTION_MODE(SPI_InitStruct->SPI_Direction));
\r
129 assert_param(IS_SPI_MODE(SPI_InitStruct->SPI_Mode));
\r
130 assert_param(IS_SPI_DATASIZE(SPI_InitStruct->SPI_DataSize));
\r
131 assert_param(IS_SPI_CPOL(SPI_InitStruct->SPI_CPOL));
\r
132 assert_param(IS_SPI_CPHA(SPI_InitStruct->SPI_CPHA));
\r
133 assert_param(IS_SPI_NSS(SPI_InitStruct->SPI_NSS));
\r
134 assert_param(IS_SPI_BAUDRATE_PRESCALER(SPI_InitStruct->SPI_BaudRatePrescaler));
\r
135 assert_param(IS_SPI_FIRST_BIT(SPI_InitStruct->SPI_FirstBit));
\r
136 assert_param(IS_SPI_CRC_POLYNOMIAL(SPI_InitStruct->SPI_CRCPolynomial));
\r
138 /*---------------------------- SPIx CR1 Configuration ------------------------*/
\r
139 /* Get the SPIx CR1 value */
\r
140 tmpreg = SPIx->CR1;
\r
141 /* Clear BIDIMode, BIDIOE, RxONLY, SSM, SSI, LSBFirst, BR, MSTR, CPOL and CPHA bits */
\r
142 tmpreg &= CR1_CLEAR_MASK;
\r
143 /* Configure SPIx: direction, NSS management, first transmitted bit, BaudRate prescaler
\r
144 master/salve mode, CPOL and CPHA */
\r
145 /* Set BIDImode, BIDIOE and RxONLY bits according to SPI_Direction value */
\r
146 /* Set SSM, SSI and MSTR bits according to SPI_Mode and SPI_NSS values */
\r
147 /* Set LSBFirst bit according to SPI_FirstBit value */
\r
148 /* Set BR bits according to SPI_BaudRatePrescaler value */
\r
149 /* Set CPOL bit according to SPI_CPOL value */
\r
150 /* Set CPHA bit according to SPI_CPHA value */
\r
151 tmpreg |= (uint16_t)((uint32_t)SPI_InitStruct->SPI_Direction | SPI_InitStruct->SPI_Mode |
\r
152 SPI_InitStruct->SPI_DataSize | SPI_InitStruct->SPI_CPOL |
\r
153 SPI_InitStruct->SPI_CPHA | SPI_InitStruct->SPI_NSS |
\r
154 SPI_InitStruct->SPI_BaudRatePrescaler | SPI_InitStruct->SPI_FirstBit);
\r
155 /* Write to SPIx CR1 */
\r
156 SPIx->CR1 = tmpreg;
\r
158 /*---------------------------- SPIx CRCPOLY Configuration --------------------*/
\r
159 /* Write to SPIx CRCPOLY */
\r
160 SPIx->CRCPR = SPI_InitStruct->SPI_CRCPolynomial;
\r
164 * @brief Fills each SPI_InitStruct member with its default value.
\r
165 * @param SPI_InitStruct : pointer to a SPI_InitTypeDef structure which will be initialized.
\r
168 void SPI_StructInit(SPI_InitTypeDef* SPI_InitStruct)
\r
170 /*--------------- Reset SPI init structure parameters values -----------------*/
\r
171 /* Initialize the SPI_Direction member */
\r
172 SPI_InitStruct->SPI_Direction = SPI_Direction_2Lines_FullDuplex;
\r
173 /* initialize the SPI_Mode member */
\r
174 SPI_InitStruct->SPI_Mode = SPI_Mode_Slave;
\r
175 /* initialize the SPI_DataSize member */
\r
176 SPI_InitStruct->SPI_DataSize = SPI_DataSize_8b;
\r
177 /* Initialize the SPI_CPOL member */
\r
178 SPI_InitStruct->SPI_CPOL = SPI_CPOL_Low;
\r
179 /* Initialize the SPI_CPHA member */
\r
180 SPI_InitStruct->SPI_CPHA = SPI_CPHA_1Edge;
\r
181 /* Initialize the SPI_NSS member */
\r
182 SPI_InitStruct->SPI_NSS = SPI_NSS_Hard;
\r
183 /* Initialize the SPI_BaudRatePrescaler member */
\r
184 SPI_InitStruct->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
\r
185 /* Initialize the SPI_FirstBit member */
\r
186 SPI_InitStruct->SPI_FirstBit = SPI_FirstBit_MSB;
\r
187 /* Initialize the SPI_CRCPolynomial member */
\r
188 SPI_InitStruct->SPI_CRCPolynomial = 7;
\r
193 * @brief Enables or disables the specified SPI peripheral.
\r
194 * @param SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
195 * @param NewState: new state of the SPIx peripheral.
\r
196 * This parameter can be: ENABLE or DISABLE.
\r
199 void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
\r
201 /* Check the parameters */
\r
202 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
203 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
204 if (NewState != DISABLE)
\r
206 /* Enable the selected SPI peripheral */
\r
207 SPIx->CR1 |= SPI_CR1_SPE;
\r
211 /* Disable the selected SPI peripheral */
\r
212 SPIx->CR1 &= (uint16_t)~((uint16_t)SPI_CR1_SPE);
\r
217 * @brief Enables or disables the specified SPI interrupts.
\r
218 * @param SPIx: where x can be 1 or 2 in SPI mode
\r
219 * @param SPI_IT: specifies the SPI interrupt source to be enabled or disabled.
\r
220 * This parameter can be one of the following values:
\r
221 * @arg SPI_IT_TXE: Tx buffer empty interrupt mask
\r
222 * @arg SPI_IT_RXNE: Rx buffer not empty interrupt mask
\r
223 * @arg SPI_IT_ERR: Error interrupt mask
\r
224 * @param NewState: new state of the specified SPI interrupt.
\r
225 * This parameter can be: ENABLE or DISABLE.
\r
228 void SPI_ITConfig(SPI_TypeDef* SPIx, uint8_t SPI_IT, FunctionalState NewState)
\r
230 uint16_t itpos = 0, itmask = 0 ;
\r
231 /* Check the parameters */
\r
232 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
233 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
234 assert_param(IS_SPI_CONFIG_IT(SPI_IT));
\r
236 /* Get the SPI IT index */
\r
237 itpos = SPI_IT >> 4;
\r
239 /* Set the IT mask */
\r
240 itmask = (uint16_t)1 << (uint16_t)itpos;
\r
242 if (NewState != DISABLE)
\r
244 /* Enable the selected SPI interrupt */
\r
245 SPIx->CR2 |= itmask;
\r
249 /* Disable the selected SPI interrupt */
\r
250 SPIx->CR2 &= (uint16_t)~itmask;
\r
255 * @brief Enables or disables the SPIx DMA interface.
\r
256 * @param SPIx: where x can be 1 or 2 in SPI mode
\r
257 * @param SPI_DMAReq: specifies the SPI DMA transfer request to be enabled or disabled.
\r
258 * This parameter can be any combination of the following values:
\r
259 * @arg SPI_DMAReq_Tx: Tx buffer DMA transfer request
\r
260 * @arg SPI_DMAReq_Rx: Rx buffer DMA transfer request
\r
261 * @param NewState: new state of the selected SPI DMA transfer request.
\r
262 * This parameter can be: ENABLE or DISABLE.
\r
265 void SPI_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_DMAReq, FunctionalState NewState)
\r
267 /* Check the parameters */
\r
268 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
269 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
270 assert_param(IS_SPI_DMAREQ(SPI_DMAReq));
\r
271 if (NewState != DISABLE)
\r
273 /* Enable the selected SPI DMA requests */
\r
274 SPIx->CR2 |= SPI_DMAReq;
\r
278 /* Disable the selected SPI DMA requests */
\r
279 SPIx->CR2 &= (uint16_t)~SPI_DMAReq;
\r
284 * @brief Transmits a Data through the SPIx peripheral.
\r
285 * @param SPIx: where x can be 1 or 2 in SPI mode
\r
286 * @param Data : Data to be transmitted.
\r
289 void SPI_SendData(SPI_TypeDef* SPIx, uint16_t Data)
\r
291 /* Check the parameters */
\r
292 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
294 /* Write in the DR register the data to be sent */
\r
299 * @brief Returns the most recent received data by the SPIx peripheral.
\r
300 * @param SPIx: where x can be 1 or 2 in SPI mode
\r
301 * @retval The value of the received data.
\r
303 uint16_t SPI_ReceiveData(SPI_TypeDef* SPIx)
\r
305 /* Check the parameters */
\r
306 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
308 /* Return the data in the DR register */
\r
313 * @brief Configures internally by software the NSS pin for the selected SPI.
\r
314 * @param SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
315 * @param SPI_NSSInternalSoft: specifies the SPI NSS internal state.
\r
316 * This parameter can be one of the following values:
\r
317 * @arg SPI_NSSInternalSoft_Set: Set NSS pin internally
\r
318 * @arg SPI_NSSInternalSoft_Reset: Reset NSS pin internally
\r
321 void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, uint16_t SPI_NSSInternalSoft)
\r
323 /* Check the parameters */
\r
324 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
325 assert_param(IS_SPI_NSS_INTERNAL(SPI_NSSInternalSoft));
\r
326 if (SPI_NSSInternalSoft != SPI_NSSInternalSoft_Reset)
\r
328 /* Set NSS pin internally by software */
\r
329 SPIx->CR1 |= SPI_NSSInternalSoft_Set;
\r
333 /* Reset NSS pin internally by software */
\r
334 SPIx->CR1 &= SPI_NSSInternalSoft_Reset;
\r
339 * @brief Enables or disables the SS output for the selected SPI.
\r
340 * @param SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
341 * @param NewState: new state of the SPIx SS output.
\r
342 * This parameter can be: ENABLE or DISABLE.
\r
345 void SPI_SSOutputCmd(SPI_TypeDef* SPIx, FunctionalState NewState)
\r
347 /* Check the parameters */
\r
348 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
349 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
350 if (NewState != DISABLE)
\r
352 /* Enable the selected SPI SS output */
\r
353 SPIx->CR2 |= (uint16_t)SPI_CR2_SSOE;
\r
357 /* Disable the selected SPI SS output */
\r
358 SPIx->CR2 &= (uint16_t)~((uint16_t)SPI_CR2_SSOE);
\r
363 * @brief Configures the data size for the selected SPI.
\r
364 * @param SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
365 * @param SPI_DataSize: specifies the SPI data size.
\r
366 * This parameter can be one of the following values:
\r
367 * @arg SPI_DataSize_16b: Set data frame format to 16bit
\r
368 * @arg SPI_DataSize_8b: Set data frame format to 8bit
\r
371 void SPI_DataSizeConfig(SPI_TypeDef* SPIx, uint16_t SPI_DataSize)
\r
373 /* Check the parameters */
\r
374 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
375 assert_param(IS_SPI_DATASIZE(SPI_DataSize));
\r
376 /* Clear DFF bit */
\r
377 SPIx->CR1 &= (uint16_t)~SPI_DataSize_16b;
\r
378 /* Set new DFF bit value */
\r
379 SPIx->CR1 |= SPI_DataSize;
\r
383 * @brief Transmit the SPIx CRC value.
\r
384 * @param SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
387 void SPI_TransmitCRC(SPI_TypeDef* SPIx)
\r
389 /* Check the parameters */
\r
390 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
392 /* Enable the selected SPI CRC transmission */
\r
393 SPIx->CR1 |= SPI_CR1_CRCNEXT;
\r
397 * @brief Enables or disables the CRC value calculation of the transfered bytes.
\r
398 * @param SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
399 * @param NewState: new state of the SPIx CRC value calculation.
\r
400 * This parameter can be: ENABLE or DISABLE.
\r
403 void SPI_CalculateCRC(SPI_TypeDef* SPIx, FunctionalState NewState)
\r
405 /* Check the parameters */
\r
406 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
407 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
408 if (NewState != DISABLE)
\r
410 /* Enable the selected SPI CRC calculation */
\r
411 SPIx->CR1 |= SPI_CR1_CRCEN;
\r
415 /* Disable the selected SPI CRC calculation */
\r
416 SPIx->CR1 &= (uint16_t)~((uint16_t)SPI_CR1_CRCEN);
\r
421 * @brief Returns the transmit or the receive CRC register value for the specified SPI.
\r
422 * @param SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
423 * @param SPI_CRC: specifies the CRC register to be read.
\r
424 * This parameter can be one of the following values:
\r
425 * @arg SPI_CRC_Tx: Selects Tx CRC register
\r
426 * @arg SPI_CRC_Rx: Selects Rx CRC register
\r
427 * @retval The selected CRC register value..
\r
429 uint16_t SPI_GetCRC(SPI_TypeDef* SPIx, uint8_t SPI_CRC)
\r
431 uint16_t crcreg = 0;
\r
432 /* Check the parameters */
\r
433 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
434 assert_param(IS_SPI_CRC(SPI_CRC));
\r
435 if (SPI_CRC != SPI_CRC_Rx)
\r
437 /* Get the Tx CRC register */
\r
438 crcreg = SPIx->TXCRCR;
\r
442 /* Get the Rx CRC register */
\r
443 crcreg = SPIx->RXCRCR;
\r
445 /* Return the selected CRC register */
\r
450 * @brief Returns the CRC Polynomial register value for the specified SPI.
\r
451 * @param SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
452 * @retval The CRC Polynomial register value.
\r
454 uint16_t SPI_GetCRCPolynomial(SPI_TypeDef* SPIx)
\r
456 /* Check the parameters */
\r
457 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
459 /* Return the CRC polynomial register */
\r
460 return SPIx->CRCPR;
\r
464 * @brief Selects the data transfer direction in bi-directional mode for the specified SPI.
\r
465 * @param SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
466 * @param SPI_Direction: specifies the data transfer direction in bi-directional mode.
\r
467 * This parameter can be one of the following values:
\r
468 * @arg SPI_Direction_Tx: Selects Tx transmission direction
\r
469 * @arg SPI_Direction_Rx: Selects Rx receive direction
\r
472 void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, uint16_t SPI_Direction)
\r
474 /* Check the parameters */
\r
475 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
476 assert_param(IS_SPI_DIRECTION(SPI_Direction));
\r
477 if (SPI_Direction == SPI_Direction_Tx)
\r
479 /* Set the Tx only mode */
\r
480 SPIx->CR1 |= SPI_Direction_Tx;
\r
484 /* Set the Rx only mode */
\r
485 SPIx->CR1 &= SPI_Direction_Rx;
\r
490 * @brief Checks whether the specified SPI flag is set or not.
\r
491 * @param SPIx: where x can be 1 or 2 in SPI mode
\r
492 * @param SPI_FLAG: specifies the SPI flag to check.
\r
493 * This parameter can be one of the following values:
\r
494 * @arg SPI_FLAG_TXE: Transmit buffer empty flag.
\r
495 * @arg SPI_FLAG_RXNE: Receive buffer not empty flag.
\r
496 * @arg SPI_FLAG_BSY: Busy flag.
\r
497 * @arg SPI_FLAG_OVR: Overrun flag.
\r
498 * @arg SPI_FLAG_MODF: Mode Fault flag.
\r
499 * @arg SPI_FLAG_CRCERR: CRC Error flag.
\r
500 * @retval The new state of SPI_FLAG (SET or RESET).
\r
502 FlagStatus SPI_GetFlagStatus(SPI_TypeDef* SPIx, uint16_t SPI_FLAG)
\r
504 FlagStatus bitstatus = RESET;
\r
505 /* Check the parameters */
\r
506 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
507 assert_param(IS_SPI_GET_FLAG(SPI_FLAG));
\r
508 /* Check the status of the specified SPI flag */
\r
509 if ((SPIx->SR & SPI_FLAG) != (uint16_t)RESET)
\r
511 /* SPI_FLAG is set */
\r
516 /* SPI_FLAG is reset */
\r
519 /* Return the SPI_FLAG status */
\r
524 * @brief Clears the SPIx CRC Error (CRCERR) flag.
\r
525 * @param SPIx: where x can be 1 or 2 in SPI mode
\r
526 * @param SPI_FLAG: specifies the SPI flag to clear.
\r
527 * This function clears only CRCERR flag.
\r
529 * - OVR (OverRun error) flag is cleared by software sequence: a read
\r
530 * operation to SPI_DR register (SPI_ReceiveData()) followed by a read
\r
531 * operation to SPI_SR register (SPI_GetFlagStatus()).
\r
532 * - UDR (UnderRun error) flag is cleared by a read operation to
\r
533 * SPI_SR register (SPI_GetFlagStatus()).
\r
534 * - MODF (Mode Fault) flag is cleared by software sequence: a read/write
\r
535 * operation to SPI_SR register (SPI_GetFlagStatus()) followed by a
\r
536 * write operation to SPI_CR1 register (SPI_Cmd() to enable the SPI).
\r
539 void SPI_ClearFlag(SPI_TypeDef* SPIx, uint16_t SPI_FLAG)
\r
541 /* Check the parameters */
\r
542 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
543 assert_param(IS_SPI_CLEAR_FLAG(SPI_FLAG));
\r
545 /* Clear the selected SPI CRC Error (CRCERR) flag */
\r
546 SPIx->SR = (uint16_t)~SPI_FLAG;
\r
550 * @brief Checks whether the specified SPI interrupt has occurred or not.
\r
551 * @param SPIx: where x can be
\r
552 * - 1 or 2 in SPI mode
\r
553 * @param SPI_IT: specifies the SPI interrupt source to check.
\r
554 * This parameter can be one of the following values:
\r
555 * @arg SPI_IT_TXE: Transmit buffer empty interrupt.
\r
556 * @arg SPI_IT_RXNE: Receive buffer not empty interrupt.
\r
557 * @arg SPI_IT_OVR: Overrun interrupt.
\r
558 * @arg SPI_IT_MODF: Mode Fault interrupt.
\r
559 * @arg SPI_IT_CRCERR: CRC Error interrupt.
\r
560 * @retval The new state of SPI_IT (SET or RESET).
\r
562 ITStatus SPI_GetITStatus(SPI_TypeDef* SPIx, uint8_t SPI_IT)
\r
564 ITStatus bitstatus = RESET;
\r
565 uint16_t itpos = 0, itmask = 0, enablestatus = 0;
\r
567 /* Check the parameters */
\r
568 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
569 assert_param(IS_SPI_GET_IT(SPI_IT));
\r
571 /* Get the SPI IT index */
\r
572 itpos = 0x01 << (SPI_IT & 0x0F);
\r
574 /* Get the SPI IT mask */
\r
575 itmask = SPI_IT >> 4;
\r
577 /* Set the IT mask */
\r
578 itmask = 0x01 << itmask;
\r
580 /* Get the SPI_IT enable bit status */
\r
581 enablestatus = (SPIx->CR2 & itmask) ;
\r
583 /* Check the status of the specified SPI interrupt */
\r
584 if (((SPIx->SR & itpos) != (uint16_t)RESET) && enablestatus)
\r
586 /* SPI_IT is set */
\r
591 /* SPI_IT is reset */
\r
594 /* Return the SPI_IT status */
\r
599 * @brief Clears the SPIx CRC Error (CRCERR) interrupt pending bit.
\r
600 * @param SPIx: where x can be
\r
601 * - 1 or 2 in SPI mode
\r
602 * @param SPI_IT: specifies the SPI interrupt pending bit to clear.
\r
603 * This function clears only CRCERR intetrrupt pending bit.
\r
605 * - OVR (OverRun Error) interrupt pending bit is cleared by software
\r
606 * sequence: a read operation to SPI_DR register (SPI_ReceiveData())
\r
607 * followed by a read operation to SPI_SR register (SPI_GetITStatus()).
\r
608 * - UDR (UnderRun Error) interrupt pending bit is cleared by a read
\r
609 * operation to SPI_SR register (SPI_GetITStatus()).
\r
610 * - MODF (Mode Fault) interrupt pending bit is cleared by software sequence:
\r
611 * a read/write operation to SPI_SR register (SPI_GetITStatus())
\r
612 * followed by a write operation to SPI_CR1 register (SPI_Cmd() to enable
\r
616 void SPI_ClearITPendingBit(SPI_TypeDef* SPIx, uint8_t SPI_IT)
\r
618 uint16_t itpos = 0;
\r
619 /* Check the parameters */
\r
620 assert_param(IS_SPI_ALL_PERIPH(SPIx));
\r
621 assert_param(IS_SPI_CLEAR_IT(SPI_IT));
\r
623 /* Get the SPI IT index */
\r
624 itpos = 0x01 << (SPI_IT & 0x0F);
\r
626 /* Clear the selected SPI CRC Error (CRCERR) interrupt pending bit */
\r
627 SPIx->SR = (uint16_t)~itpos;
\r
641 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
\r