HAL_spi.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /**
  2. ******************************************************************************
  3. * @file HAL_spi.c
  4. * @author IC Applications Department
  5. * @version V0.8
  6. * @date 2019_08_02
  7. * @brief This file provides all the SPI firmware functions.
  8. ******************************************************************************
  9. * @copy
  10. *
  11. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13. * TIME. AS A RESULT, HOLOCENE SHALL NOT BE HELD LIABLE FOR ANY
  14. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17. *
  18. * <h2><center>&copy; COPYRIGHT 2016 HOLOCENE</center></h2>
  19. */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "HAL_spi.h"
  22. #include "HAL_rcc.h"
  23. /** @addtogroup StdPeriph_Driver
  24. * @{
  25. */
  26. /** @defgroup SPI
  27. * @brief SPI driver modules
  28. * @{
  29. */
  30. /** @defgroup SPI_Private_TypesDefinitions
  31. * @{
  32. */
  33. /**
  34. * @}
  35. */
  36. /** @defgroup SPI_Private_Defines
  37. * @{
  38. */
  39. /* SPI SPIENE mask */
  40. #define GCTL_SPIEN_Set ((uint16_t)0x0001)
  41. #define GCTL_SPIEN_Reset ((uint16_t)0xFFFE)
  42. /* SPI registers Masks */
  43. #define GCTL_CLEAR_Mask ((uint16_t)0xF000)
  44. #define CCTL_CLEAR_Mask ((uint16_t)0xFFC0)
  45. #define SPBRG_CLEAR_Mask ((uint16_t)0x0000)
  46. #define SPI_DataSize_Mask ((uint16_t)0xFCFF)
  47. /**
  48. * @}
  49. */
  50. /** @defgroup SPI_Private_Macros
  51. * @{
  52. */
  53. /**
  54. * @}
  55. */
  56. /** @defgroup SPI_Private_Variables
  57. * @{
  58. */
  59. /**
  60. * @}
  61. */
  62. /** @defgroup SPI_Private_FunctionPrototypes
  63. * @{
  64. */
  65. /**
  66. * @}
  67. */
  68. /** @defgroup SPI_Private_Functions
  69. * @{
  70. */
  71. /**
  72. * @brief Deinitializes the SPIx peripheral registers to their default
  73. * reset values .
  74. * @param SPIx: where x can be 0, 1 to select the SPI peripheral.
  75. * @retval : None
  76. */
  77. void SPI_DeInit(SPI_TypeDef* SPIx)
  78. {
  79. /* Check the parameters */
  80. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  81. switch (*(uint32_t*)&SPIx)
  82. {
  83. case SPI1_BASE:
  84. /* Enable SPI1 reset state */
  85. RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
  86. /* Release SPI1 from reset state */
  87. RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
  88. break;
  89. default:
  90. break;
  91. }
  92. }
  93. /**
  94. * @brief Initializes the SPIx peripheral according to the specified
  95. * parameters in the SPI_InitStruct.
  96. * @param SPIx: where x can be 0, 1 to select the SPI peripheral.
  97. * @param SPI_InitStruct: pointer to a SPI_InitTypeDef structure that
  98. * contains the configuration information for the specified
  99. * SPI peripheral.
  100. * @retval : None
  101. */
  102. void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)
  103. {
  104. uint32_t tmpreg = 0;
  105. /* check the parameters */
  106. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  107. /* Check the SPI parameters */
  108. assert_param(IS_SPI_DIRECTION_MODE(SPI_InitStruct->SPI_Direction));
  109. assert_param(IS_SPI_MODE(SPI_InitStruct->SPI_Mode));
  110. assert_param(IS_SPI_DATASIZE(SPI_InitStruct->SPI_DataSize));
  111. assert_param(IS_SPI_CPOL(SPI_InitStruct->SPI_CPOL));
  112. assert_param(IS_SPI_CPHA(SPI_InitStruct->SPI_CPHA));
  113. assert_param(IS_SPI_NSS(SPI_InitStruct->SPI_NSS));
  114. assert_param(IS_SPI_BAUDRATE_PRESCALER(SPI_InitStruct->SPI_BaudRatePrescaler));
  115. assert_param(IS_SPI_FIRST_BIT(SPI_InitStruct->SPI_FirstBit));
  116. assert_param(IS_SPI_DATAWIDRH(SPI_InitStruct->SPI_DataWidth));
  117. assert_param(IS_SPI_CRC_POLYNOMIAL(SPI_InitStruct->SPI_CRCPolynomial));
  118. /*---------------------------- SPIx GCTL Configuration ------------------------*/
  119. /* Get the SPIx GCTL value */
  120. tmpreg = SPIx->GCTL;
  121. /* Clear csn_sel, dmamode, txtlf, rxtlf,data_sel, rxen, txen, mm, int_en, spien bits */
  122. tmpreg &= GCTL_CLEAR_Mask;
  123. /* Configure SPIx: direction, NSS management, first transmitted bit, BaudRate prescaler
  124. master/salve mode, CPOL and CPHA */
  125. /* Set dat_sel bits according to SPI_DataSize value */
  126. /* Set csn and csn_sel bits according to SPI_NSS value */
  127. /* Set mm bit according to SPI_Mode value */
  128. tmpreg |= (uint32_t)((uint32_t) SPI_InitStruct->SPI_DataSize | SPI_InitStruct->SPI_NSS |
  129. SPI_InitStruct->SPI_Mode );
  130. /* Write to SPIx GCTL */
  131. // if(SPI_InitStruct->SPI_DataSize==SPI_DataSize_8b) tmpreg |= 0x1000;
  132. SPIx->GCTL = tmpreg;
  133. /*---------------------------- SPIx CCTL Configuration ------------------------*/
  134. tmpreg = SPIx->CCTL;
  135. /* Clear spilen, lsbfe, CPOL, CPHA bits */
  136. tmpreg &= CCTL_CLEAR_Mask;
  137. /* Set Spilen bit according to SPI_DataWidth value */
  138. /* Set LSBFirst bit according to SPI_FirstBit value */
  139. /* Set CPOL bit according to SPI_CPOL value */
  140. /* Set CPHA bit according to SPI_CPHA value */
  141. tmpreg |= (uint16_t)((uint16_t) SPI_InitStruct->SPI_DataWidth | SPI_InitStruct->SPI_FirstBit | SPI_InitStruct->SPI_CPOL |
  142. SPI_InitStruct->SPI_CPHA );
  143. /* Write to SPIx CCTL */
  144. SPIx->CCTL = tmpreg;
  145. /*---------------------------- SPIx SPBRG Configuration ------------------------*/
  146. tmpreg = SPIx->SPBRG;
  147. /* Clear spbrg bits */
  148. tmpreg &= (uint16_t)SPBRG_CLEAR_Mask;
  149. /* Set BR bits according to SPI_BaudRatePrescaler value */
  150. tmpreg |= (uint16_t) SPI_InitStruct->SPI_BaudRatePrescaler;
  151. /* Write to SPIx SPBRG */
  152. SPIx->SPBRG = tmpreg;
  153. }
  154. /**
  155. * @brief Fills each SPI_InitStruct member with its default value.
  156. * @param SPI_InitStruct : pointer to a SPI_InitTypeDef structure
  157. * which will be initialized.
  158. * @retval : None
  159. */
  160. void SPI_StructInit(SPI_InitTypeDef* SPI_InitStruct)
  161. {
  162. /*--------------- Reset SPI init structure parameters values -----------------*/
  163. /* initialize the SPI_Mode member */
  164. SPI_InitStruct->SPI_Mode = SPI_Mode_Slave;
  165. /* initialize the SPI_DataSize member */
  166. SPI_InitStruct->SPI_DataSize = SPI_DataSize_8b;
  167. /* Initialize the SPILEN member */
  168. SPI_InitStruct->SPI_DataWidth = SPI_DataWidth_8b;
  169. /* Initialize the SPI_CPOL member */
  170. SPI_InitStruct->SPI_CPOL = SPI_CPOL_Low;
  171. /* Initialize the SPI_CPHA member */
  172. SPI_InitStruct->SPI_CPHA = SPI_CPHA_1Edge;
  173. /* Initialize the SPI_NSS member */
  174. SPI_InitStruct->SPI_NSS = SPI_NSS_Soft;
  175. /* Initialize the SPI_BaudRatePrescaler member */
  176. SPI_InitStruct->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
  177. /* Initialize the SPI_FirstBit member */
  178. SPI_InitStruct->SPI_FirstBit = SPI_FirstBit_MSB;
  179. }
  180. /**
  181. * @brief Enables or disables the specified SPI peripheral.
  182. * @param SPIx: where x can be 0, 1 to select the SPI peripheral.
  183. * @param NewState: new state of the SPIx peripheral.
  184. * This parameter can be: ENABLE or DISABLE.
  185. * @retval : None
  186. */
  187. void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
  188. {
  189. /* Check the parameters */
  190. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  191. assert_param(IS_FUNCTIONAL_STATE(NewState));
  192. if (NewState != DISABLE)
  193. {
  194. /* Enable the selected SPI peripheral */
  195. SPIx->GCTL |= GCTL_SPIEN_Set;
  196. }
  197. else
  198. {
  199. /* Disable the selected SPI peripheral */
  200. SPIx->GCTL &= GCTL_SPIEN_Reset;
  201. }
  202. }
  203. /**
  204. * @brief Enables or disables the specified SPIinterrupts.
  205. * @param SPIx: where x can be :
  206. * 0, 1 in SPI mode
  207. * @param SPI_IT: specifies the SPI interrupt source to be
  208. * enabled or disabled.
  209. * This parameter can be one of the following values:
  210. * @arg SPI_IT_TX: Tx buffer empty interrupt mask
  211. * @arg SPI_IT_RX: Rx buffer interrupt mask
  212. * @arg SPI_IT_UNDERRUN: under Error interrupt mask in slave mode
  213. * @arg SPI_IT_RXOVER: RX OVER Error interrupt mask
  214. * @arg SPI_IT_RXMATCH: spectials rx data numbers interrupt mask
  215. * @arg SPI_IT_RXFULL: Rx buffer full interrupt mask
  216. * @arg SPI_IT_TXEPT: Tx buffer empty interrupt mask
  217. * @param NewState: new state of the specified SPI interrupt.
  218. * This parameter can be: ENABLE or DISABLE.
  219. * @retval : None
  220. */
  221. void SPI_ITConfig(SPI_TypeDef* SPIx, uint8_t SPI_IT, FunctionalState NewState)
  222. {
  223. /* Check the parameters */
  224. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  225. assert_param(IS_FUNCTIONAL_STATE(NewState));
  226. assert_param(IS_SPI_CONFIG_IT(SPI_IT));
  227. if (NewState != DISABLE)
  228. {
  229. /* Enable the selected SPI Global interrupt */
  230. SPIx->GCTL |= SPI_INT_EN;
  231. /* Enable the selected SPI interrupt */
  232. SPIx->INTEN |= SPI_IT;
  233. }
  234. else
  235. {
  236. /* Disable the selected SPI interrupt */
  237. SPIx->INTEN &= (uint16_t)~SPI_IT;
  238. /* Disable the selected SPI Global interrupt */
  239. SPIx->GCTL &= (uint16_t)~SPI_INT_EN;
  240. }
  241. }
  242. /**
  243. * @brief Enables or disables the SPIx DMA interface.
  244. * @param SPIx: where x can be :
  245. * 0, 1 in SPI mode
  246. * @param SPI_DMAReq: specifies the SPI DMA transfer request
  247. * to be enabled or disabled.
  248. * This parameter can be any combination of the following values:
  249. * @arg SPI_DMAReq_EN: DMA transfer request enable
  250. * @param NewState: new state of the selected SPI DMA transfer
  251. * request.
  252. * This parameter can be: ENABLE or DISABLE.
  253. * @retval : None
  254. */
  255. void SPI_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_DMAReq, FunctionalState NewState)
  256. {
  257. /* Check the parameters */
  258. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  259. assert_param(IS_FUNCTIONAL_STATE(NewState));
  260. assert_param(IS_SPI_DMAREQ(SPI_DMAReq));
  261. if (NewState != DISABLE)
  262. {
  263. /* Enable the selected SPI DMA requests */
  264. SPIx->GCTL |= SPI_DMAReq;
  265. }
  266. else
  267. {
  268. /* Disable the selected SPI DMA requests */
  269. SPIx->GCTL &= (uint32_t)~SPI_DMAReq;
  270. }
  271. }
  272. /**
  273. * @brief configure tn Fifo trigger level bit.
  274. * @param SPIx: where x can be :
  275. * 0, 1 in SPI mode
  276. * @param SPI_FifoTriggerValue: specifies the Fifo trigger level
  277. * This parameter can be any combination of the following values:
  278. * SPI_TXTLF : SPI TX FIFO Trigger value set
  279. * SPI_RXTLF : SPI RX FIFO Trigger value set
  280. * @param NewState: new state of the selected SPI DMA transfer
  281. * request.
  282. * This parameter can be: ENABLE or DISABLE.
  283. * @retval : None
  284. */
  285. void SPI_FifoTrigger(SPI_TypeDef* SPIx, uint16_t SPI_FifoTriggerValue, FunctionalState NewState)
  286. {
  287. /* Check the parameters */
  288. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  289. assert_param(IS_FUNCTIONAL_STATE(NewState));
  290. assert_param(IS_SPI_FIFOTRIGGER(SPI_FifoTriggerValue));
  291. if (NewState != DISABLE)
  292. {
  293. /* Enable the selected SPI DMA requests */
  294. SPIx->GCTL |= SPI_FifoTriggerValue;
  295. }
  296. else
  297. {
  298. /* Disable the selected SPI DMA requests */
  299. SPIx->GCTL &= (uint32_t)~SPI_FifoTriggerValue;
  300. }
  301. }
  302. /**
  303. * @brief Transmits a Data through the SPIx peripheral.
  304. * @param SPIx: where x can be :
  305. * 0, 1 in SPI mode
  306. * @param Data : Data to be transmitted..
  307. * @retval : None
  308. */
  309. void SPI_SendData(SPI_TypeDef* SPIx, uint16_t Data)
  310. {
  311. /* Check the parameters */
  312. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  313. /* Write in the TXREG register the data to be sent */
  314. SPIx->TXREG = Data;
  315. }
  316. /**
  317. * @brief Returns the most recent received data by the SPIx peripheral.
  318. * @param SPIx: where x can be :
  319. * 0, 1 in SPI mode
  320. * @retval : The value of the received data.
  321. */
  322. uint16_t SPI_ReceiveData(SPI_TypeDef* SPIx)
  323. {
  324. /* Check the parameters */
  325. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  326. /* Return the data in the RXREG register */
  327. return SPIx->RXREG;
  328. }
  329. /**
  330. * @brief Slave chip csn single by selected
  331. * @param SPIx: where x can be 0, 1 to select the SPI peripheral.
  332. * @param SPI_CSInternalSelected: specifies the SPI CS internal selected.
  333. * This parameter can be one of the following values:
  334. * @arg SPI_CS_BIT0: cs bit 0 selected
  335. * @arg SPI_CS_BIT1: cs bit 1 selected
  336. * @arg SPI_CS_BIT2: cs bit 2 selected
  337. * @arg SPI_CS_BIT3: cs bit 3 selected
  338. * @arg SPI_CS_BIT4: cs bit 4 selected
  339. * @arg SPI_CS_BIT5: cs bit 5 selected
  340. * @arg SPI_CS_BIT6: cs bit 6 selected
  341. * @arg SPI_CS_BIT7: cs bit 7 selected
  342. * @param NewState: new state of the selected SPI CS pin
  343. * request.
  344. * This parameter can be: ENABLE or DISABLE.
  345. * @retval : None
  346. */
  347. void SPI_CSInternalSelected(SPI_TypeDef* SPIx, uint16_t SPI_CSInternalSelected,FunctionalState NewState)
  348. {
  349. /* Check the parameters */
  350. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  351. assert_param(IS_SPI_CS(SPI_CSInternalSelected));
  352. assert_param(IS_FUNCTIONAL_STATE(NewState));
  353. if (NewState != DISABLE)
  354. {
  355. /* selected cs pin according SCSR Value */
  356. SPIx->SCSR &= SPI_CSInternalSelected;
  357. }
  358. else
  359. {
  360. /* release cs pin according SCSR Value*/
  361. SPIx->SCSR |= ~SPI_CSInternalSelected;
  362. }
  363. }
  364. /**
  365. * @brief Configures the data size for the selected SPI.
  366. * @param SPIx: where x can be 0, 1 to select the SPI peripheral.
  367. * @param SPI_DataSize: specifies the SPI data size.
  368. * This parameter can be one of the following values:
  369. * @arg SPI_DataSize_32b: Set data frame format to 32bit
  370. * @arg SPI_DataSize_16b: Set data frame format to 16bit
  371. * @arg SPI_DataSize_8b: Set data frame format to 8bit
  372. * @retval : None
  373. */
  374. void SPI_DataSizeConfig(SPI_TypeDef* SPIx, uint16_t SPI_DataSize)
  375. {
  376. /* Check the parameters */
  377. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  378. assert_param(IS_SPI_DATASIZE(SPI_DataSize));
  379. /* Clear data_sel bit */
  380. SPIx->GCTL &= SPI_DataSize_Mask;
  381. /* Set new data_sel bit value */
  382. SPIx->GCTL |= SPI_DataSize;
  383. }
  384. /**
  385. * @brief Selects the data transfer direction in bi-directional mode
  386. * for the specified SPI.
  387. * @param SPIx: where x can be 0, 1 to select the SPI peripheral.
  388. * @param SPI_Direction: specifies the data transfer direction in
  389. * bi-directional mode.
  390. * This parameter can be one of the following values:
  391. * @arg SPI_Direction_Tx: Selects Tx transmission direction
  392. * @arg SPI_Direction_Rx: Selects Rx receive direction
  393. @arg SPI_Disable_Tx: Selects Rx receive direction
  394. @arg SPI_Disable_Rx: Selects Rx receive direction
  395. * @retval : None
  396. */
  397. void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, uint16_t SPI_Direction)
  398. {
  399. /* Check the parameters */
  400. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  401. assert_param(IS_SPI_DIRECTION(SPI_Direction));
  402. /* Set the Tx only mode */
  403. if(SPI_Direction==SPI_Direction_Tx)
  404. {
  405. SPIx->GCTL |= SPI_Direction_Tx;
  406. }
  407. /* Set the Rx only mode */
  408. if(SPI_Direction==SPI_Direction_Rx)
  409. {
  410. SPIx->GCTL |= SPI_Direction_Rx;
  411. }
  412. /* Disable the Tx only mode */
  413. if(SPI_Direction==SPI_Disable_Tx)
  414. {
  415. SPIx->GCTL &= SPI_Disable_Tx;
  416. }
  417. /* Disable the Rx only mode */
  418. if(SPI_Direction==SPI_Disable_Rx)
  419. {
  420. SPIx->GCTL &= SPI_Disable_Rx;
  421. }
  422. }
  423. /**
  424. * @brief Checks whether the specified SPI flag is set or not.
  425. * @param SPIx: where x can be :
  426. * 0, 1 in SPI mode
  427. * @param SPI_FLAG: specifies the SPI flag to check.
  428. * This parameter can be one of the following values:
  429. * @arg SPI_FLAG_RXAVL: Rx buffer has bytes flag
  430. * @arg SPI_FLAG_TXEPT: Tx buffer and tx shifter empty flag
  431. * @retval : The new state of SPI_FLAG (SET or RESET).
  432. */
  433. FlagStatus SPI_GetFlagStatus(SPI_TypeDef* SPIx, uint16_t SPI_FLAG)
  434. {
  435. FlagStatus bitstatus = RESET;
  436. /* Check the parameters */
  437. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  438. assert_param(IS_SPI_GET_FLAG(SPI_FLAG));
  439. /* Check the status of the specified SPI flag */
  440. if ((SPIx->CSTAT & SPI_FLAG) != (uint16_t)RESET)
  441. {
  442. /* SPI_FLAG is set */
  443. bitstatus = SET;
  444. }
  445. else
  446. {
  447. /* SPI_FLAG is reset */
  448. bitstatus = RESET;
  449. }
  450. /* Return the SPI_FLAG status */
  451. return bitstatus;
  452. }
  453. /**
  454. * @brief Checks whether the specified SPI interrupt has occurred or not.
  455. * @param SPIx: where x can be :
  456. * 0, 1 in SPI mode
  457. * @param SPI_IT: specifies the SPI interrupt source to check.
  458. * This parameter can be one of the following values:
  459. * @arg SPI_IT_TX: Tx buffer empty interrupt
  460. * @arg SPI_IT_RX: Rx buffer interrupt
  461. * @arg SPI_IT_UNDERRUN: under Error interrupt in slave mode
  462. * @arg SPI_IT_RXOVER: RX OVER Error interrupt
  463. * @arg SPI_IT_RXMATCH: spectials rx data numbers interrupt
  464. * @arg SPI_IT_RXFULL: Rx buffer full interrupt
  465. * @arg SPI_IT_TXEPT: Tx buffer and tx shifter empty interrupt
  466. * @retval : The new state of SPI_IT (SET or RESET).
  467. */
  468. ITStatus SPI_GetITStatus(SPI_TypeDef* SPIx, uint8_t SPI_IT)
  469. {
  470. ITStatus bitstatus = RESET;
  471. /* Check the parameters */
  472. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  473. assert_param(IS_SPI_GET_IT(SPI_IT));
  474. /* Check the status of the specified SPI interrupt */
  475. if ((SPIx->INTSTAT & SPI_IT) != (uint16_t)RESET)
  476. {
  477. /* SPI_IT is set */
  478. bitstatus = SET;
  479. }
  480. else
  481. {
  482. /* SPI_IT is reset */
  483. bitstatus = RESET;
  484. }
  485. /* Return the SPI_IT status */
  486. return bitstatus;
  487. }
  488. /**
  489. * @brief Clears the SPIx Error interrupt pending bit.
  490. * @param SPIx: where x can be :
  491. * 0, 1 in SPI mode
  492. * @param SPI_IT: specifies the SPI interrupt pending bit to clear.
  493. * @arg SPI_IT_TX: Tx buffer empty interrupt
  494. * @arg SPI_IT_RX: Rx buffer interrupt
  495. * @arg SPI_IT_UNDERRUN: under Error interrupt in slave mode
  496. * @arg SPI_IT_RXOVER: RX OVER Error interrupt
  497. * @arg SPI_IT_RXMATCH: spectials rx data numbers interrupt
  498. * @arg SPI_IT_RXFULL: Rx buffer full interrupt
  499. * @arg SPI_IT_TXEPT: Tx buffer and tx shifter empty interrupt
  500. * This function clears only ERR intetrrupt pending bit.
  501. * @retval : None
  502. */
  503. void SPI_ClearITPendingBit(SPI_TypeDef* SPIx, uint8_t SPI_IT)
  504. {
  505. /* Check the parameters */
  506. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  507. assert_param(IS_SPI_CLEAR_IT(SPI_IT));
  508. /* Clear the selected SPI IT INTERRUPT */
  509. SPIx->INTCLR |= (uint16_t)SPI_IT;
  510. }
  511. /**
  512. * @brief SPI Hole a count Received bytes in next receive process.
  513. * @param SPIx: where x can be 0, 1 in SPI mode
  514. * @param Number: specifies the SPI receive Number.
  515. * This parament can be 1-65535.
  516. * This function can use only in SPI master single receive mode.
  517. * @retval : None
  518. */
  519. void SPI_RxBytes(SPI_TypeDef* SPIx, uint16_t Number)
  520. {
  521. /* Check the parameters */
  522. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  523. /*set the received bytes in next receive process */
  524. SPIx->RXDNR = Number;
  525. }
  526. /**
  527. * @brief slave mode tx data transmit phase adjust set.
  528. * @param SPIx: where x can be 0, 1 in SPI mode
  529. * @param AdjustValue: specifies the SPI receive Number.
  530. * This parament can be :
  531. * SPI_SlaveAdjust_FAST: fast speed use
  532. * SPI_SlaveAdjust_LOW: low speed use
  533. * This function can use only in SPI master single receive mode.
  534. * @retval : None
  535. */
  536. void SPI_SlaveAdjust(SPI_TypeDef* SPIx, uint16_t AdjustValue)
  537. {
  538. /* Check the parameters */
  539. assert_param(IS_SPI_ALL_PERIPH(SPIx));
  540. assert_param(IS_SPI_SlaveAdjust(AdjustValue));
  541. /*set the AdjustValue according to txedge bit of CCTL register*/
  542. SPIx->CCTL |= AdjustValue;
  543. }
  544. /**
  545. * @}
  546. */
  547. /**
  548. * @}
  549. */
  550. /**
  551. * @}
  552. */
  553. /*-------------------------(C) COPYRIGHT 2016 HOLOCENE ----------------------*/