1 /******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
\r
2 * File Name : stm32f10x_spi.c
\r
3 * Author : MCD Application Team
\r
4 * Date First Issued : 09/29/2006
\r
5 * Description : This file provides all the SPI firmware functions.
\r
6 ********************************************************************************
\r
11 ********************************************************************************
\r
12 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
\r
14 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
\r
15 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
\r
16 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
\r
17 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
18 *******************************************************************************/
\r
20 /* Includes ------------------------------------------------------------------*/
\r
21 #include "stm32f10x_spi.h"
\r
22 #include "stm32f10x_rcc.h"
\r
24 /* Private typedef -----------------------------------------------------------*/
\r
25 /* Private define ------------------------------------------------------------*/
\r
27 #define CR1_SPE_Set ((u16)0x0040)
\r
28 #define CR1_SPE_Reset ((u16)0xFFBF)
\r
30 /* SPI CRCNext mask */
\r
31 #define CR1_CRCNext_Set ((u16)0x1000)
\r
33 /* SPI CRCEN mask */
\r
34 #define CR1_CRCEN_Set ((u16)0x2000)
\r
35 #define CR1_CRCEN_Reset ((u16)0xDFFF)
\r
38 #define CR2_SSOE_Set ((u16)0x0004)
\r
39 #define CR2_SSOE_Reset ((u16)0xFFFB)
\r
41 /* SPI registers Masks */
\r
42 #define CR1_CLEAR_Mask ((u16)0x3040)
\r
44 /* Private macro -------------------------------------------------------------*/
\r
45 /* Private variables ---------------------------------------------------------*/
\r
46 /* Private function prototypes -----------------------------------------------*/
\r
47 /* Private functions ---------------------------------------------------------*/
\r
49 /*******************************************************************************
\r
50 * Function Name : SPI_DeInit
\r
51 * Description : Deinitializes the SPIx peripheral registers to their default
\r
53 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
56 *******************************************************************************/
\r
57 void SPI_DeInit(SPI_TypeDef* SPIx)
\r
59 switch (*(u32*)&SPIx)
\r
62 /* Enable SPI1 reset state */
\r
63 RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
\r
64 /* Release SPI1 from reset state */
\r
65 RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
\r
69 /* Enable SPI2 reset state */
\r
70 RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
\r
71 /* Release SPI2 from reset state */
\r
72 RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
\r
80 /*******************************************************************************
\r
81 * Function Name : SPI_Init
\r
82 * Description : Initializes the SPIx according to the specified parameters
\r
83 * in the SPI_InitStruct.
\r
84 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
85 * - SPI_InitStruct: pointer to a SPI_InitTypeDef structure that
\r
86 * contains the configuration information for the specified
\r
90 ******************************************************************************/
\r
91 void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)
\r
95 /* Check the parameters */
\r
96 assert(IS_SPI_DIRECTION_MODE(SPI_InitStruct->SPI_Direction));
\r
97 assert(IS_SPI_MODE(SPI_InitStruct->SPI_Mode));
\r
98 assert(IS_SPI_DATASIZE(SPI_InitStruct->SPI_DataSize));
\r
99 assert(IS_SPI_CPOL(SPI_InitStruct->SPI_CPOL));
\r
100 assert(IS_SPI_CPHA(SPI_InitStruct->SPI_CPHA));
\r
101 assert(IS_SPI_NSS(SPI_InitStruct->SPI_NSS));
\r
102 assert(IS_SPI_BAUDRATE_PRESCALER(SPI_InitStruct->SPI_BaudRatePrescaler));
\r
103 assert(IS_SPI_FIRST_BIT(SPI_InitStruct->SPI_FirstBit));
\r
104 assert(IS_SPI_CRC_POLYNOMIAL(SPI_InitStruct->SPI_CRCPolynomial));
\r
106 /*---------------------------- SPIx CR1 Configuration ------------------------*/
\r
107 /* Get the SPIx CR1 value */
\r
108 tmpreg = SPIx->CR1;
\r
109 /* Clear BIDIMode, BIDIOE, RxONLY, SSM, SSI, LSBFirst, BR, MSTR, CPOL and CPHA bits */
\r
110 tmpreg &= CR1_CLEAR_Mask;
\r
111 /* Configure SPIx: direction, NSS management, first transmitted bit, BaudRate prescaler
\r
112 master/salve mode, CPOL and CPHA */
\r
113 /* Set BIDImode, BIDIOE and RxONLY bits according to SPI_Direction value */
\r
114 /* Set SSM, SSI and MSTR bits according to SPI_Mode and SPI_NSS values */
\r
115 /* Set LSBFirst bit according to SPI_FirstBit value */
\r
116 /* Set BR bits according to SPI_BaudRatePrescaler value */
\r
117 /* Set CPOL bit according to SPI_CPOL value */
\r
118 /* Set CPHA bit according to SPI_CPHA value */
\r
119 tmpreg |= (u16)((u32)SPI_InitStruct->SPI_Direction | SPI_InitStruct->SPI_Mode |
\r
120 SPI_InitStruct->SPI_DataSize | SPI_InitStruct->SPI_CPOL |
\r
121 SPI_InitStruct->SPI_CPHA | SPI_InitStruct->SPI_NSS |
\r
122 SPI_InitStruct->SPI_BaudRatePrescaler | SPI_InitStruct->SPI_FirstBit);
\r
123 /* Write to SPIx CR1 */
\r
124 SPIx->CR1 = tmpreg;
\r
126 /*---------------------------- SPIx CRCPOLY Configuration --------------------*/
\r
127 /* Write to SPIx CRCPOLY */
\r
128 SPIx->CRCPR = SPI_InitStruct->SPI_CRCPolynomial;
\r
131 /*******************************************************************************
\r
132 * Function Name : SPI_StructInit
\r
133 * Description : Fills each SPI_InitStruct member with its default value.
\r
134 * Input : - SPI_InitStruct : pointer to a SPI_InitTypeDef structure
\r
135 * which will be initialized.
\r
138 *******************************************************************************/
\r
139 void SPI_StructInit(SPI_InitTypeDef* SPI_InitStruct)
\r
141 /*--------------- Reset SPI init structure parameters values -----------------*/
\r
142 /* Initialize the SPI_Direction member */
\r
143 SPI_InitStruct->SPI_Direction = SPI_Direction_2Lines_FullDuplex;
\r
145 /* initialize the SPI_Mode member */
\r
146 SPI_InitStruct->SPI_Mode = SPI_Mode_Slave;
\r
148 /* initialize the SPI_DataSize member */
\r
149 SPI_InitStruct->SPI_DataSize = SPI_DataSize_8b;
\r
151 /* Initialize the SPI_CPOL member */
\r
152 SPI_InitStruct->SPI_CPOL = SPI_CPOL_Low;
\r
154 /* Initialize the SPI_CPHA member */
\r
155 SPI_InitStruct->SPI_CPHA = SPI_CPHA_1Edge;
\r
157 /* Initialize the SPI_NSS member */
\r
158 SPI_InitStruct->SPI_NSS = SPI_NSS_Hard;
\r
160 /* Initialize the SPI_BaudRatePrescaler member */
\r
161 SPI_InitStruct->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
\r
163 /* Initialize the SPI_FirstBit member */
\r
164 SPI_InitStruct->SPI_FirstBit = SPI_FirstBit_MSB;
\r
166 /* Initialize the SPI_CRCPolynomial member */
\r
167 SPI_InitStruct->SPI_CRCPolynomial = 7;
\r
170 /*******************************************************************************
\r
171 * Function Name : SPI_Cmd
\r
172 * Description : Enables or disables the specified SPI peripheral.
\r
173 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
174 * - NewState: new state of the SPIx peripheral.
\r
175 * This parameter can be: ENABLE or DISABLE.
\r
178 *******************************************************************************/
\r
179 void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
\r
181 /* Check the parameters */
\r
182 assert(IS_FUNCTIONAL_STATE(NewState));
\r
184 if (NewState != DISABLE)
\r
186 /* Enable the selected SPI peripheral */
\r
187 SPIx->CR1 |= CR1_SPE_Set;
\r
191 /* Disable the selected SPI peripheral */
\r
192 SPIx->CR1 &= CR1_SPE_Reset;
\r
196 /*******************************************************************************
\r
197 * Function Name : SPI_ITConfig
\r
198 * Description : Enables or disables the specified SPI interrupts.
\r
199 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
200 * - SPI_IT: specifies the SPI interrupts sources to be enabled
\r
202 * This parameter can be one of the following values:
\r
203 * - SPI_IT_TXE: Tx buffer empty interrupt mask
\r
204 * - SPI_IT_RXNE: Rx buffer not empty interrupt mask
\r
205 * - SPI_IT_ERR: Error interrupt mask
\r
206 * - NewState: new state of the specified SPI interrupts.
\r
207 * This parameter can be: ENABLE or DISABLE.
\r
210 *******************************************************************************/
\r
211 void SPI_ITConfig(SPI_TypeDef* SPIx, u8 SPI_IT, FunctionalState NewState)
\r
213 u16 itpos = 0, itmask = 0 ;
\r
215 /* Check the parameters */
\r
216 assert(IS_FUNCTIONAL_STATE(NewState));
\r
217 assert(IS_SPI_CONFIG_IT(SPI_IT));
\r
219 /* Get the SPI IT index */
\r
220 itpos = SPI_IT >> 4;
\r
221 /* Set the IT mask */
\r
222 itmask = (u16)((u16)1 << itpos);
\r
224 if (NewState != DISABLE)
\r
226 /* Enable the selected SPI interrupt */
\r
227 SPIx->CR2 |= itmask;
\r
231 /* Disable the selected SPI interrupt */
\r
232 SPIx->CR2 &= (u16)~itmask;
\r
236 /*******************************************************************************
\r
237 * Function Name : SPI_DMACmd
\r
238 * Description : Enables or disables the SPIx
\92s DMA interface.
\r
239 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
240 * - SPI_DMAReq: specifies the SPI DMA transfer request to be
\r
241 * enabled or disabled.
\r
242 * This parameter can be any combination of the following values:
\r
243 * - SPI_DMAReq_Tx: Tx buffer DMA transfer request
\r
244 * - SPI_DMAReq_Rx: Rx buffer DMA transfer request
\r
245 * - NewState: new state of the selected SPI DMA transfer request.
\r
246 * This parameter can be: ENABLE or DISABLE.
\r
249 *******************************************************************************/
\r
250 void SPI_DMACmd(SPI_TypeDef* SPIx, u16 SPI_DMAReq, FunctionalState NewState)
\r
252 /* Check the parameters */
\r
253 assert(IS_FUNCTIONAL_STATE(NewState));
\r
254 assert(IS_SPI_DMA_REQ(SPI_DMAReq));
\r
256 if (NewState != DISABLE)
\r
258 /* Enable the selected SPI DMA requests */
\r
259 SPIx->CR2 |= SPI_DMAReq;
\r
263 /* Disable the selected SPI DMA requests */
\r
264 SPIx->CR2 &= (u16)~SPI_DMAReq;
\r
268 /*******************************************************************************
\r
269 * Function Name : SPI_SendData
\r
270 * Description : Transmits a Data through the SPIx peripheral.
\r
271 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
272 * - Data : Data to be transmitted..
\r
275 *******************************************************************************/
\r
276 void SPI_SendData(SPI_TypeDef* SPIx, u16 Data)
\r
278 /* Write in the DR register the data to be sent */
\r
282 /*******************************************************************************
\r
283 * Function Name : SPI_ReceiveData
\r
284 * Description : Returns the most recent received data by the SPIx peripheral.
\r
285 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
287 * Return : The value of the received data.
\r
288 *******************************************************************************/
\r
289 u16 SPI_ReceiveData(SPI_TypeDef* SPIx)
\r
291 /* Return the data in the DR register */
\r
295 /*******************************************************************************
\r
296 * Function Name : SPI_NSSInternalSoftwareConfig
\r
297 * Description : Configures internally by software the NSS pin for the selected
\r
299 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
300 * - SPI_NSSInternalSoft: specifies the SPI NSS internal state.
\r
301 * This parameter can be one of the following values:
\r
302 * - SPI_NSSInternalSoft_Set: Set NSS pin internally
\r
303 * - SPI_NSSInternalSoft_Reset: Reset NSS pin internally
\r
306 *******************************************************************************/
\r
307 void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, u16 SPI_NSSInternalSoft)
\r
309 /* Check the parameters */
\r
310 assert(IS_SPI_NSS_INTERNAL(SPI_NSSInternalSoft));
\r
312 if (SPI_NSSInternalSoft != SPI_NSSInternalSoft_Reset)
\r
314 /* Set NSS pin internally by software */
\r
315 SPIx->CR1 |= SPI_NSSInternalSoft_Set;
\r
319 /* Reset NSS pin internally by software */
\r
320 SPIx->CR1 &= SPI_NSSInternalSoft_Reset;
\r
324 /*******************************************************************************
\r
325 * Function Name : SPI_SSOutputCmd
\r
326 * Description : Enables or disables the SS output for the selected SPI.
\r
327 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
328 * - NewState: new state of the SPIx SS output.
\r
329 * This parameter can be: ENABLE or DISABLE.
\r
332 *******************************************************************************/
\r
333 void SPI_SSOutputCmd(SPI_TypeDef* SPIx, FunctionalState NewState)
\r
335 /* Check the parameters */
\r
336 assert(IS_FUNCTIONAL_STATE(NewState));
\r
338 if (NewState != DISABLE)
\r
340 /* Enable the selected SPI SS output */
\r
341 SPIx->CR2 |= CR2_SSOE_Set;
\r
345 /* Disable the selected SPI SS output */
\r
346 SPIx->CR2 &= CR2_SSOE_Reset;
\r
350 /*******************************************************************************
\r
351 * Function Name : SPI_DataSizeConfig
\r
352 * Description : Configures the data size for the selected SPI.
\r
353 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
354 * - SPI_DataSize: specifies the SPI data size.
\r
355 * This parameter can be one of the following values:
\r
356 * - SPI_DataSize_16b: Set data frame format to 16bit
\r
357 * - SPI_DataSize_8b: Set data frame format to 8bit
\r
360 *******************************************************************************/
\r
361 void SPI_DataSizeConfig(SPI_TypeDef* SPIx, u16 SPI_DataSize)
\r
363 /* Check the parameters */
\r
364 assert(IS_SPI_DATASIZE(SPI_DataSize));
\r
366 if (SPI_DataSize != SPI_DataSize_8b)
\r
368 /* Set data frame format to 16bit */
\r
369 SPIx->CR1 |= SPI_DataSize_16b;
\r
373 /* Set data frame format to 8bit */
\r
374 SPIx->CR1 &= SPI_DataSize_8b;
\r
378 /*******************************************************************************
\r
379 * Function Name : SPI_TransmitCRC
\r
380 * Description : Transmit the SPIx CRC value.
\r
381 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
384 *******************************************************************************/
\r
385 void SPI_TransmitCRC(SPI_TypeDef* SPIx)
\r
387 /* Enable the selected SPI CRC transmission */
\r
388 SPIx->CR1 |= CR1_CRCNext_Set;
\r
391 /*******************************************************************************
\r
392 * Function Name : SPI_CalculateCRC
\r
393 * Description : Enables or disables the CRC value calculation of the
\r
394 * transfered bytes.
\r
395 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
396 * - NewState: new state of the SPIx CRC value calculation.
\r
397 * This parameter can be: ENABLE or DISABLE.
\r
400 *******************************************************************************/
\r
401 void SPI_CalculateCRC(SPI_TypeDef* SPIx, FunctionalState NewState)
\r
403 /* Check the parameters */
\r
404 assert(IS_FUNCTIONAL_STATE(NewState));
\r
406 if (NewState != DISABLE)
\r
408 /* Enable the selected SPI CRC calculation */
\r
409 SPIx->CR1 |= CR1_CRCEN_Set;
\r
413 /* Disable the selected SPI CRC calculation */
\r
414 SPIx->CR1 &= CR1_CRCEN_Reset;
\r
418 /*******************************************************************************
\r
419 * Function Name : SPI_GetCRC
\r
420 * Description : Returns the transmit or the receive CRC register value for
\r
421 * the specified SPI.
\r
422 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
423 * - SPI_CRC: specifies the CRC register to be read.
\r
424 * This parameter can be one of the following values:
\r
425 * - SPI_CRC_Tx: Selects Tx CRC register
\r
426 * - SPI_CRC_Rx: Selects Rx CRC register
\r
428 * Return : The selected CRC register value..
\r
429 *******************************************************************************/
\r
430 u16 SPI_GetCRC(SPI_TypeDef* SPIx, u8 SPI_CRC)
\r
434 /* Check the parameters */
\r
435 assert(IS_SPI_CRC(SPI_CRC));
\r
437 if (SPI_CRC != SPI_CRC_Rx)
\r
439 /* Get the Tx CRC register */
\r
440 crcreg = SPIx->TXCRCR;
\r
444 /* Get the Rx CRC register */
\r
445 crcreg = SPIx->RXCRCR;
\r
448 /* Return the selected CRC register */
\r
452 /*******************************************************************************
\r
453 * Function Name : SPI_GetCRCPolynomial
\r
454 * Description : Returns the CRC Polynomial register value for the specified SPI.
\r
455 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
457 * Return : The CRC Polynomial register value.
\r
458 *******************************************************************************/
\r
459 u16 SPI_GetCRCPolynomial(SPI_TypeDef* SPIx)
\r
461 /* Return the CRC polynomial register */
\r
462 return SPIx->CRCPR;
\r
465 /*******************************************************************************
\r
466 * Function Name : SPI_BiDirectionalLineConfig
\r
467 * Description : Selects the data transfer direction in bi-directional mode
\r
468 * for the specified SPI.
\r
469 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
470 * - SPI_Direction: specifies the data transfer direction in
\r
471 * bi-directional mode.
\r
472 * This parameter can be one of the following values:
\r
473 * - SPI_Direction_Tx: Selects Tx transmission direction
\r
474 * - SPI_Direction_Rx: Selects Rx receive direction
\r
477 *******************************************************************************/
\r
478 void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, u16 SPI_Direction)
\r
480 /* Check the parameters */
\r
481 assert(IS_SPI_DIRECTION(SPI_Direction));
\r
483 if (SPI_Direction == SPI_Direction_Tx)
\r
485 /* Set the Tx only mode */
\r
486 SPIx->CR1 |= SPI_Direction_Tx;
\r
490 /* Set the Rx only mode */
\r
491 SPIx->CR1 &= SPI_Direction_Rx;
\r
495 /*******************************************************************************
\r
496 * Function Name : SPI_GetFlagStatus
\r
497 * Description : Checks whether the specified SPI flag is set or not.
\r
498 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
499 * - SPI_FLAG: specifies the flag to check.
\r
500 * This parameter can be one of the following values:
\r
501 * - SPI_FLAG_BSY: Busy flag.
\r
502 * - SPI_FLAG_OVR: Overrun flag.
\r
503 * - SPI_FLAG_MODF: Mode Fault flag.
\r
504 * - SPI_FLAG_CRCERR: CRC Error flag.
\r
505 * - SPI_FLAG_TXE: Transmit buffer empty flag.
\r
506 * - SPI_FLAG_RXNE: Receive buffer not empty flag.
\r
508 * Return : The new state of SPI_FLAG (SET or RESET).
\r
509 *******************************************************************************/
\r
510 FlagStatus SPI_GetFlagStatus(SPI_TypeDef* SPIx, u16 SPI_FLAG)
\r
512 FlagStatus bitstatus = RESET;
\r
514 /* Check the parameters */
\r
515 assert(IS_SPI_GET_FLAG(SPI_FLAG));
\r
517 /* Check the status of the specified SPI flag */
\r
518 if ((SPIx->SR & SPI_FLAG) != (u16)RESET)
\r
520 /* SPI_FLAG is set */
\r
525 /* SPI_FLAG is reset */
\r
528 /* Return the SPI_FLAG status */
\r
532 /*******************************************************************************
\r
533 * Function Name : SPI_ClearFlag
\r
534 * Description : Clears the SPIx's pending flags.
\r
535 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
536 * - SPI_FLAG: specifies the flag to clear.
\r
537 * This parameter can be any combination of the following values:
\r
538 * - SPI_FLAG_OVR: Overrun flag.
\r
539 * - SPI_FLAG_MODF: Mode Fault flag.
\r
540 * - SPI_FLAG_CRCERR: CRC Error flag.
\r
543 *******************************************************************************/
\r
544 void SPI_ClearFlag(SPI_TypeDef* SPIx, u16 SPI_FLAG)
\r
546 /* Check the parameters */
\r
547 assert(IS_SPI_CLEAR_FLAG(SPI_FLAG));
\r
549 /* SPI_FLAG_MODF flag clear */
\r
550 if(SPI_FLAG == SPI_FLAG_MODF)
\r
552 /* Read SR register */
\r
554 /* Write on CR1 register */
\r
555 SPIx->CR1 |= CR1_SPE_Set;
\r
557 /* SPI_FLAG_OVR flag clear */
\r
558 else if(SPI_FLAG == SPI_FLAG_OVR)
\r
560 /* Read SR register */
\r
563 else /* SPI_FLAG_CRCERR flag clear */
\r
565 /* Clear the selected SPI flag */
\r
566 SPIx->SR &= (u16)~SPI_FLAG;
\r
570 /*******************************************************************************
\r
571 * Function Name : SPI_GetITStatus
\r
572 * Description : Checks whether the specified SPI interrupt has occurred or not.
\r
573 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
574 * - SPI_IT: specifies the SPI interrupt source to check.
\r
575 * This parameter can be one of the following values:
\r
576 * - SPI_IT_OVR: Overrun interrupt.
\r
577 * - SPI_IT_MODF: Mode Fault interrupt.
\r
578 * - SPI_IT_CRCERR: CRC Error interrupt.
\r
579 * - SPI_IT_TXE: Transmit buffer empty interrupt.
\r
580 * - SPI_IT_RXNE: Receive buffer not empty interrupt.
\r
582 * Return : The new state of SPI_IT (SET or RESET).
\r
583 *******************************************************************************/
\r
584 ITStatus SPI_GetITStatus(SPI_TypeDef* SPIx, u8 SPI_IT)
\r
586 ITStatus bitstatus = RESET;
\r
587 u16 itpos = 0, itmask = 0, enablestatus = 0;
\r
589 /* Check the parameters */
\r
590 assert(IS_SPI_GET_IT(SPI_IT));
\r
592 /* Get the SPI IT index */
\r
593 itpos = (u16)((u16)0x01 << (SPI_IT & (u8)0x0F));
\r
595 /* Get the SPI IT index */
\r
596 itmask = SPI_IT >> 4;
\r
597 /* Set the IT mask */
\r
598 itmask = (u16)((u16)0x01 << itmask);
\r
599 /* Get the SPI_IT enable bit status */
\r
600 enablestatus = (SPIx->CR2 & itmask) ;
\r
602 /* Check the status of the specified SPI interrupt */
\r
603 if (((SPIx->SR & itpos) != (u16)RESET) && enablestatus)
\r
605 /* SPI_IT is set */
\r
610 /* SPI_IT is reset */
\r
613 /* Return the SPI_IT status */
\r
617 /*******************************************************************************
\r
618 * Function Name : SPI_ClearITPendingBit
\r
619 * Description : Clears the SPI
\92s interrupt pending bits.
\r
620 * Input : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
\r
621 * - SPI_IT: specifies the SPI interrupt pending bit to clear.
\r
622 * This parameter can be one of the following values:
\r
623 * - SPI_IT_OVR: Overrun interrupt.
\r
624 * - SPI_IT_MODF: Mode Fault interrupt.
\r
625 * - SPI_IT_CRCERR: CRC Error interrupt.
\r
628 *******************************************************************************/
\r
629 void SPI_ClearITPendingBit(SPI_TypeDef* SPIx, u8 SPI_IT)
\r
633 /* Check the parameters */
\r
634 assert(IS_SPI_CLEAR_IT(SPI_IT));
\r
636 /* SPI_IT_MODF pending bit clear */
\r
637 if(SPI_IT == SPI_IT_MODF)
\r
639 /* Read SR register */
\r
641 /* Write on CR1 register */
\r
642 SPIx->CR1 |= CR1_SPE_Set;
\r
644 else if(SPI_IT == SPI_IT_OVR) /* SPI_IT_OVR pending bit clear */
\r
646 /* Read SR register */
\r
649 else /* SPI_IT_CRCERR pending bit clear */
\r
651 /* Get the SPI IT index */
\r
652 itpos = (u16)((u16)0x01 << (SPI_IT & (u8)0x0F));
\r
653 /* Clear the selected SPI interrupt pending bits */
\r
654 SPIx->SR &= (u16)~itpos;
\r
658 /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
\r