stm32f0xx_spi.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_spi.h
  4. * @author MCD Application Team
  5. * @version V1.5.0
  6. * @date 05-December-2014
  7. * @brief This file contains all the functions prototypes for the SPI
  8. * firmware library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM32F0XX_SPI_H
  30. #define __STM32F0XX_SPI_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f0xx.h"
  36. /** @addtogroup STM32F0xx_StdPeriph_Driver
  37. * @{
  38. */
  39. /** @addtogroup SPI
  40. * @{
  41. */
  42. /* Exported types ------------------------------------------------------------*/
  43. /**
  44. * @brief SPI Init structure definition
  45. */
  46. typedef struct
  47. {
  48. uint16_t SPI_Direction; /*!< Specifies the SPI unidirectional or bidirectional data mode.
  49. This parameter can be a value of @ref SPI_data_direction */
  50. uint16_t SPI_Mode; /*!< Specifies the SPI mode (Master/Slave).
  51. This parameter can be a value of @ref SPI_mode */
  52. uint16_t SPI_DataSize; /*!< Specifies the SPI data size.
  53. This parameter can be a value of @ref SPI_data_size */
  54. uint16_t SPI_CPOL; /*!< Specifies the serial clock steady state.
  55. This parameter can be a value of @ref SPI_Clock_Polarity */
  56. uint16_t SPI_CPHA; /*!< Specifies the clock active edge for the bit capture.
  57. This parameter can be a value of @ref SPI_Clock_Phase */
  58. uint16_t SPI_NSS; /*!< Specifies whether the NSS signal is managed by
  59. hardware (NSS pin) or by software using the SSI bit.
  60. This parameter can be a value of @ref SPI_Slave_Select_management */
  61. uint16_t SPI_BaudRatePrescaler; /*!< Specifies the Baud Rate prescaler value which will be
  62. used to configure the transmit and receive SCK clock.
  63. This parameter can be a value of @ref SPI_BaudRate_Prescaler
  64. @note The communication clock is derived from the master
  65. clock. The slave clock does not need to be set. */
  66. uint16_t SPI_FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
  67. This parameter can be a value of @ref SPI_MSB_LSB_transmission */
  68. uint16_t SPI_CRCPolynomial; /*!< Specifies the polynomial used for the CRC calculation. */
  69. }SPI_InitTypeDef;
  70. /**
  71. * @brief I2S Init structure definition
  72. * @note These parameters are not available for STM32F030 devices.
  73. */
  74. typedef struct
  75. {
  76. uint16_t I2S_Mode; /*!< Specifies the I2S operating mode.
  77. This parameter can be a value of @ref SPI_I2S_Mode */
  78. uint16_t I2S_Standard; /*!< Specifies the standard used for the I2S communication.
  79. This parameter can be a value of @ref SPI_I2S_Standard */
  80. uint16_t I2S_DataFormat; /*!< Specifies the data format for the I2S communication.
  81. This parameter can be a value of @ref SPI_I2S_Data_Format */
  82. uint16_t I2S_MCLKOutput; /*!< Specifies whether the I2S MCLK output is enabled or not.
  83. This parameter can be a value of @ref SPI_I2S_MCLK_Output */
  84. uint32_t I2S_AudioFreq; /*!< Specifies the frequency selected for the I2S communication.
  85. This parameter can be a value of @ref SPI_I2S_Audio_Frequency */
  86. uint16_t I2S_CPOL; /*!< Specifies the idle state of the I2S clock.
  87. This parameter can be a value of @ref SPI_I2S_Clock_Polarity */
  88. }I2S_InitTypeDef;
  89. /* Exported constants --------------------------------------------------------*/
  90. /** @defgroup SPI_Exported_Constants
  91. * @{
  92. */
  93. #define IS_SPI_ALL_PERIPH(PERIPH) (((PERIPH) == SPI1) || \
  94. ((PERIPH) == SPI2))
  95. #define IS_SPI_1_PERIPH(PERIPH) (((PERIPH) == SPI1))
  96. /** @defgroup SPI_data_direction
  97. * @{
  98. */
  99. #define SPI_Direction_2Lines_FullDuplex ((uint16_t)0x0000)
  100. #define SPI_Direction_2Lines_RxOnly ((uint16_t)0x0400)
  101. #define SPI_Direction_1Line_Rx ((uint16_t)0x8000)
  102. #define SPI_Direction_1Line_Tx ((uint16_t)0xC000)
  103. #define IS_SPI_DIRECTION_MODE(MODE) (((MODE) == SPI_Direction_2Lines_FullDuplex) || \
  104. ((MODE) == SPI_Direction_2Lines_RxOnly) || \
  105. ((MODE) == SPI_Direction_1Line_Rx) || \
  106. ((MODE) == SPI_Direction_1Line_Tx))
  107. /**
  108. * @}
  109. */
  110. /** @defgroup SPI_mode
  111. * @{
  112. */
  113. #define SPI_Mode_Master ((uint16_t)0x0104)
  114. #define SPI_Mode_Slave ((uint16_t)0x0000)
  115. #define IS_SPI_MODE(MODE) (((MODE) == SPI_Mode_Master) || \
  116. ((MODE) == SPI_Mode_Slave))
  117. /**
  118. * @}
  119. */
  120. /** @defgroup SPI_data_size
  121. * @{
  122. */
  123. #define SPI_DataSize_4b ((uint16_t)0x0300)
  124. #define SPI_DataSize_5b ((uint16_t)0x0400)
  125. #define SPI_DataSize_6b ((uint16_t)0x0500)
  126. #define SPI_DataSize_7b ((uint16_t)0x0600)
  127. #define SPI_DataSize_8b ((uint16_t)0x0700)
  128. #define SPI_DataSize_9b ((uint16_t)0x0800)
  129. #define SPI_DataSize_10b ((uint16_t)0x0900)
  130. #define SPI_DataSize_11b ((uint16_t)0x0A00)
  131. #define SPI_DataSize_12b ((uint16_t)0x0B00)
  132. #define SPI_DataSize_13b ((uint16_t)0x0C00)
  133. #define SPI_DataSize_14b ((uint16_t)0x0D00)
  134. #define SPI_DataSize_15b ((uint16_t)0x0E00)
  135. #define SPI_DataSize_16b ((uint16_t)0x0F00)
  136. #define IS_SPI_DATA_SIZE(SIZE) (((SIZE) == SPI_DataSize_4b) || \
  137. ((SIZE) == SPI_DataSize_5b) || \
  138. ((SIZE) == SPI_DataSize_6b) || \
  139. ((SIZE) == SPI_DataSize_7b) || \
  140. ((SIZE) == SPI_DataSize_8b) || \
  141. ((SIZE) == SPI_DataSize_9b) || \
  142. ((SIZE) == SPI_DataSize_10b) || \
  143. ((SIZE) == SPI_DataSize_11b) || \
  144. ((SIZE) == SPI_DataSize_12b) || \
  145. ((SIZE) == SPI_DataSize_13b) || \
  146. ((SIZE) == SPI_DataSize_14b) || \
  147. ((SIZE) == SPI_DataSize_15b) || \
  148. ((SIZE) == SPI_DataSize_16b))
  149. /**
  150. * @}
  151. */
  152. /** @defgroup SPI_CRC_length
  153. * @{
  154. */
  155. #define SPI_CRCLength_8b ((uint16_t)0x0000)
  156. #define SPI_CRCLength_16b SPI_CR1_CRCL
  157. #define IS_SPI_CRC_LENGTH(LENGTH) (((LENGTH) == SPI_CRCLength_8b) || \
  158. ((LENGTH) == SPI_CRCLength_16b))
  159. /**
  160. * @}
  161. */
  162. /** @defgroup SPI_Clock_Polarity
  163. * @{
  164. */
  165. #define SPI_CPOL_Low ((uint16_t)0x0000)
  166. #define SPI_CPOL_High SPI_CR1_CPOL
  167. #define IS_SPI_CPOL(CPOL) (((CPOL) == SPI_CPOL_Low) || \
  168. ((CPOL) == SPI_CPOL_High))
  169. /**
  170. * @}
  171. */
  172. /** @defgroup SPI_Clock_Phase
  173. * @{
  174. */
  175. #define SPI_CPHA_1Edge ((uint16_t)0x0000)
  176. #define SPI_CPHA_2Edge SPI_CR1_CPHA
  177. #define IS_SPI_CPHA(CPHA) (((CPHA) == SPI_CPHA_1Edge) || \
  178. ((CPHA) == SPI_CPHA_2Edge))
  179. /**
  180. * @}
  181. */
  182. /** @defgroup SPI_Slave_Select_management
  183. * @{
  184. */
  185. #define SPI_NSS_Soft SPI_CR1_SSM
  186. #define SPI_NSS_Hard ((uint16_t)0x0000)
  187. #define IS_SPI_NSS(NSS) (((NSS) == SPI_NSS_Soft) || \
  188. ((NSS) == SPI_NSS_Hard))
  189. /**
  190. * @}
  191. */
  192. /** @defgroup SPI_BaudRate_Prescaler
  193. * @{
  194. */
  195. #define SPI_BaudRatePrescaler_2 ((uint16_t)0x0000)
  196. #define SPI_BaudRatePrescaler_4 ((uint16_t)0x0008)
  197. #define SPI_BaudRatePrescaler_8 ((uint16_t)0x0010)
  198. #define SPI_BaudRatePrescaler_16 ((uint16_t)0x0018)
  199. #define SPI_BaudRatePrescaler_32 ((uint16_t)0x0020)
  200. #define SPI_BaudRatePrescaler_64 ((uint16_t)0x0028)
  201. #define SPI_BaudRatePrescaler_128 ((uint16_t)0x0030)
  202. #define SPI_BaudRatePrescaler_256 ((uint16_t)0x0038)
  203. #define IS_SPI_BAUDRATE_PRESCALER(PRESCALER) (((PRESCALER) == SPI_BaudRatePrescaler_2) || \
  204. ((PRESCALER) == SPI_BaudRatePrescaler_4) || \
  205. ((PRESCALER) == SPI_BaudRatePrescaler_8) || \
  206. ((PRESCALER) == SPI_BaudRatePrescaler_16) || \
  207. ((PRESCALER) == SPI_BaudRatePrescaler_32) || \
  208. ((PRESCALER) == SPI_BaudRatePrescaler_64) || \
  209. ((PRESCALER) == SPI_BaudRatePrescaler_128) || \
  210. ((PRESCALER) == SPI_BaudRatePrescaler_256))
  211. /**
  212. * @}
  213. */
  214. /** @defgroup SPI_MSB_LSB_transmission
  215. * @{
  216. */
  217. #define SPI_FirstBit_MSB ((uint16_t)0x0000)
  218. #define SPI_FirstBit_LSB SPI_CR1_LSBFIRST
  219. #define IS_SPI_FIRST_BIT(BIT) (((BIT) == SPI_FirstBit_MSB) || \
  220. ((BIT) == SPI_FirstBit_LSB))
  221. /**
  222. * @}
  223. */
  224. /** @defgroup SPI_I2S_Mode
  225. * @{
  226. */
  227. #define I2S_Mode_SlaveTx ((uint16_t)0x0000)
  228. #define I2S_Mode_SlaveRx ((uint16_t)0x0100)
  229. #define I2S_Mode_MasterTx ((uint16_t)0x0200)
  230. #define I2S_Mode_MasterRx ((uint16_t)0x0300)
  231. #define IS_I2S_MODE(MODE) (((MODE) == I2S_Mode_SlaveTx) || \
  232. ((MODE) == I2S_Mode_SlaveRx) || \
  233. ((MODE) == I2S_Mode_MasterTx)|| \
  234. ((MODE) == I2S_Mode_MasterRx))
  235. /**
  236. * @}
  237. */
  238. /** @defgroup SPI_I2S_Standard
  239. * @{
  240. */
  241. #define I2S_Standard_Phillips ((uint16_t)0x0000)
  242. #define I2S_Standard_MSB ((uint16_t)0x0010)
  243. #define I2S_Standard_LSB ((uint16_t)0x0020)
  244. #define I2S_Standard_PCMShort ((uint16_t)0x0030)
  245. #define I2S_Standard_PCMLong ((uint16_t)0x00B0)
  246. #define IS_I2S_STANDARD(STANDARD) (((STANDARD) == I2S_Standard_Phillips) || \
  247. ((STANDARD) == I2S_Standard_MSB) || \
  248. ((STANDARD) == I2S_Standard_LSB) || \
  249. ((STANDARD) == I2S_Standard_PCMShort) || \
  250. ((STANDARD) == I2S_Standard_PCMLong))
  251. /**
  252. * @}
  253. */
  254. /** @defgroup SPI_I2S_Data_Format
  255. * @{
  256. */
  257. #define I2S_DataFormat_16b ((uint16_t)0x0000)
  258. #define I2S_DataFormat_16bextended ((uint16_t)0x0001)
  259. #define I2S_DataFormat_24b ((uint16_t)0x0003)
  260. #define I2S_DataFormat_32b ((uint16_t)0x0005)
  261. #define IS_I2S_DATA_FORMAT(FORMAT) (((FORMAT) == I2S_DataFormat_16b) || \
  262. ((FORMAT) == I2S_DataFormat_16bextended) || \
  263. ((FORMAT) == I2S_DataFormat_24b) || \
  264. ((FORMAT) == I2S_DataFormat_32b))
  265. /**
  266. * @}
  267. */
  268. /** @defgroup SPI_I2S_MCLK_Output
  269. * @{
  270. */
  271. #define I2S_MCLKOutput_Enable SPI_I2SPR_MCKOE
  272. #define I2S_MCLKOutput_Disable ((uint16_t)0x0000)
  273. #define IS_I2S_MCLK_OUTPUT(OUTPUT) (((OUTPUT) == I2S_MCLKOutput_Enable) || \
  274. ((OUTPUT) == I2S_MCLKOutput_Disable))
  275. /**
  276. * @}
  277. */
  278. /** @defgroup SPI_I2S_Audio_Frequency
  279. * @{
  280. */
  281. #define I2S_AudioFreq_192k ((uint32_t)192000)
  282. #define I2S_AudioFreq_96k ((uint32_t)96000)
  283. #define I2S_AudioFreq_48k ((uint32_t)48000)
  284. #define I2S_AudioFreq_44k ((uint32_t)44100)
  285. #define I2S_AudioFreq_32k ((uint32_t)32000)
  286. #define I2S_AudioFreq_22k ((uint32_t)22050)
  287. #define I2S_AudioFreq_16k ((uint32_t)16000)
  288. #define I2S_AudioFreq_11k ((uint32_t)11025)
  289. #define I2S_AudioFreq_8k ((uint32_t)8000)
  290. #define I2S_AudioFreq_Default ((uint32_t)2)
  291. #define IS_I2S_AUDIO_FREQ(FREQ) ((((FREQ) >= I2S_AudioFreq_8k) && \
  292. ((FREQ) <= I2S_AudioFreq_192k)) || \
  293. ((FREQ) == I2S_AudioFreq_Default))
  294. /**
  295. * @}
  296. */
  297. /** @defgroup SPI_I2S_Clock_Polarity
  298. * @{
  299. */
  300. #define I2S_CPOL_Low ((uint16_t)0x0000)
  301. #define I2S_CPOL_High SPI_I2SCFGR_CKPOL
  302. #define IS_I2S_CPOL(CPOL) (((CPOL) == I2S_CPOL_Low) || \
  303. ((CPOL) == I2S_CPOL_High))
  304. /**
  305. * @}
  306. */
  307. /** @defgroup SPI_FIFO_reception_threshold
  308. * @{
  309. */
  310. #define SPI_RxFIFOThreshold_HF ((uint16_t)0x0000)
  311. #define SPI_RxFIFOThreshold_QF SPI_CR2_FRXTH
  312. #define IS_SPI_RX_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SPI_RxFIFOThreshold_HF) || \
  313. ((THRESHOLD) == SPI_RxFIFOThreshold_QF))
  314. /**
  315. * @}
  316. */
  317. /** @defgroup SPI_I2S_DMA_transfer_requests
  318. * @{
  319. */
  320. #define SPI_I2S_DMAReq_Tx SPI_CR2_TXDMAEN
  321. #define SPI_I2S_DMAReq_Rx SPI_CR2_RXDMAEN
  322. #define IS_SPI_I2S_DMA_REQ(REQ) ((((REQ) & (uint16_t)0xFFFC) == 0x00) && ((REQ) != 0x00))
  323. /**
  324. * @}
  325. */
  326. /** @defgroup SPI_last_DMA_transfers
  327. * @{
  328. */
  329. #define SPI_LastDMATransfer_TxEvenRxEven ((uint16_t)0x0000)
  330. #define SPI_LastDMATransfer_TxOddRxEven ((uint16_t)0x4000)
  331. #define SPI_LastDMATransfer_TxEvenRxOdd ((uint16_t)0x2000)
  332. #define SPI_LastDMATransfer_TxOddRxOdd ((uint16_t)0x6000)
  333. #define IS_SPI_LAST_DMA_TRANSFER(TRANSFER) (((TRANSFER) == SPI_LastDMATransfer_TxEvenRxEven) || \
  334. ((TRANSFER) == SPI_LastDMATransfer_TxOddRxEven) || \
  335. ((TRANSFER) == SPI_LastDMATransfer_TxEvenRxOdd) || \
  336. ((TRANSFER) == SPI_LastDMATransfer_TxOddRxOdd))
  337. /**
  338. * @}
  339. */
  340. /** @defgroup SPI_NSS_internal_software_management
  341. * @{
  342. */
  343. #define SPI_NSSInternalSoft_Set SPI_CR1_SSI
  344. #define SPI_NSSInternalSoft_Reset ((uint16_t)0xFEFF)
  345. #define IS_SPI_NSS_INTERNAL(INTERNAL) (((INTERNAL) == SPI_NSSInternalSoft_Set) || \
  346. ((INTERNAL) == SPI_NSSInternalSoft_Reset))
  347. /**
  348. * @}
  349. */
  350. /** @defgroup SPI_CRC_Transmit_Receive
  351. * @{
  352. */
  353. #define SPI_CRC_Tx ((uint8_t)0x00)
  354. #define SPI_CRC_Rx ((uint8_t)0x01)
  355. #define IS_SPI_CRC(CRC) (((CRC) == SPI_CRC_Tx) || ((CRC) == SPI_CRC_Rx))
  356. /**
  357. * @}
  358. */
  359. /** @defgroup SPI_direction_transmit_receive
  360. * @{
  361. */
  362. #define SPI_Direction_Rx ((uint16_t)0xBFFF)
  363. #define SPI_Direction_Tx ((uint16_t)0x4000)
  364. #define IS_SPI_DIRECTION(DIRECTION) (((DIRECTION) == SPI_Direction_Rx) || \
  365. ((DIRECTION) == SPI_Direction_Tx))
  366. /**
  367. * @}
  368. */
  369. /** @defgroup SPI_I2S_interrupts_definition
  370. * @{
  371. */
  372. #define SPI_I2S_IT_TXE ((uint8_t)0x71)
  373. #define SPI_I2S_IT_RXNE ((uint8_t)0x60)
  374. #define SPI_I2S_IT_ERR ((uint8_t)0x50)
  375. #define IS_SPI_I2S_CONFIG_IT(IT) (((IT) == SPI_I2S_IT_TXE) || \
  376. ((IT) == SPI_I2S_IT_RXNE) || \
  377. ((IT) == SPI_I2S_IT_ERR))
  378. #define I2S_IT_UDR ((uint8_t)0x53)
  379. #define SPI_IT_MODF ((uint8_t)0x55)
  380. #define SPI_I2S_IT_OVR ((uint8_t)0x56)
  381. #define SPI_I2S_IT_FRE ((uint8_t)0x58)
  382. #define IS_SPI_I2S_GET_IT(IT) (((IT) == SPI_I2S_IT_RXNE) || ((IT) == SPI_I2S_IT_TXE) || \
  383. ((IT) == SPI_I2S_IT_OVR) || ((IT) == SPI_IT_MODF) || \
  384. ((IT) == SPI_I2S_IT_FRE)|| ((IT) == I2S_IT_UDR))
  385. /**
  386. * @}
  387. */
  388. /** @defgroup SPI_transmission_fifo_status_level
  389. * @{
  390. */
  391. #define SPI_TransmissionFIFOStatus_Empty ((uint16_t)0x0000)
  392. #define SPI_TransmissionFIFOStatus_1QuarterFull ((uint16_t)0x0800)
  393. #define SPI_TransmissionFIFOStatus_HalfFull ((uint16_t)0x1000)
  394. #define SPI_TransmissionFIFOStatus_Full ((uint16_t)0x1800)
  395. /**
  396. * @}
  397. */
  398. /** @defgroup SPI_reception_fifo_status_level
  399. * @{
  400. */
  401. #define SPI_ReceptionFIFOStatus_Empty ((uint16_t)0x0000)
  402. #define SPI_ReceptionFIFOStatus_1QuarterFull ((uint16_t)0x0200)
  403. #define SPI_ReceptionFIFOStatus_HalfFull ((uint16_t)0x0400)
  404. #define SPI_ReceptionFIFOStatus_Full ((uint16_t)0x0600)
  405. /**
  406. * @}
  407. */
  408. /** @defgroup SPI_I2S_flags_definition
  409. * @{
  410. */
  411. #define SPI_I2S_FLAG_RXNE SPI_SR_RXNE
  412. #define SPI_I2S_FLAG_TXE SPI_SR_TXE
  413. #define I2S_FLAG_CHSIDE SPI_SR_CHSIDE
  414. #define I2S_FLAG_UDR SPI_SR_UDR
  415. #define SPI_FLAG_CRCERR SPI_SR_CRCERR
  416. #define SPI_FLAG_MODF SPI_SR_MODF
  417. #define SPI_I2S_FLAG_OVR SPI_SR_OVR
  418. #define SPI_I2S_FLAG_BSY SPI_SR_BSY
  419. #define SPI_I2S_FLAG_FRE SPI_SR_FRE
  420. #define IS_SPI_CLEAR_FLAG(FLAG) (((FLAG) == SPI_FLAG_CRCERR))
  421. #define IS_SPI_I2S_GET_FLAG(FLAG) (((FLAG) == SPI_I2S_FLAG_BSY) || ((FLAG) == SPI_I2S_FLAG_OVR) || \
  422. ((FLAG) == SPI_FLAG_MODF) || ((FLAG) == SPI_FLAG_CRCERR) || \
  423. ((FLAG) == SPI_I2S_FLAG_TXE) || ((FLAG) == SPI_I2S_FLAG_RXNE)|| \
  424. ((FLAG) == SPI_I2S_FLAG_FRE)|| ((FLAG) == I2S_FLAG_CHSIDE)|| \
  425. ((FLAG) == I2S_FLAG_UDR))
  426. /**
  427. * @}
  428. */
  429. /** @defgroup SPI_CRC_polynomial
  430. * @{
  431. */
  432. #define IS_SPI_CRC_POLYNOMIAL(POLYNOMIAL) ((POLYNOMIAL) >= 0x1)
  433. /**
  434. * @}
  435. */
  436. /**
  437. * @}
  438. */
  439. /* Exported macro ------------------------------------------------------------*/
  440. /* Exported functions ------------------------------------------------------- */
  441. /* Initialization and Configuration functions *********************************/
  442. void SPI_I2S_DeInit(SPI_TypeDef* SPIx);
  443. void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct);
  444. void I2S_Init(SPI_TypeDef* SPIx, I2S_InitTypeDef* I2S_InitStruct); /*!< Not applicable for STM32F030 devices */
  445. void SPI_StructInit(SPI_InitTypeDef* SPI_InitStruct);
  446. void I2S_StructInit(I2S_InitTypeDef* I2S_InitStruct); /*!< Not applicable for STM32F030 devices */
  447. void SPI_TIModeCmd(SPI_TypeDef* SPIx, FunctionalState NewState);
  448. void SPI_NSSPulseModeCmd(SPI_TypeDef* SPIx, FunctionalState NewState);
  449. void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState);
  450. void I2S_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState); /*!< Not applicable for STM32F030 devices */
  451. void SPI_DataSizeConfig(SPI_TypeDef* SPIx, uint16_t SPI_DataSize);
  452. void SPI_RxFIFOThresholdConfig(SPI_TypeDef* SPIx, uint16_t SPI_RxFIFOThreshold);
  453. void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, uint16_t SPI_Direction);
  454. void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, uint16_t SPI_NSSInternalSoft);
  455. void SPI_SSOutputCmd(SPI_TypeDef* SPIx, FunctionalState NewState);
  456. /* Data transfers functions ***************************************************/
  457. void SPI_SendData8(SPI_TypeDef* SPIx, uint8_t Data);
  458. void SPI_I2S_SendData16(SPI_TypeDef* SPIx, uint16_t Data);
  459. uint8_t SPI_ReceiveData8(SPI_TypeDef* SPIx);
  460. uint16_t SPI_I2S_ReceiveData16(SPI_TypeDef* SPIx);
  461. /* Hardware CRC Calculation functions *****************************************/
  462. void SPI_CRCLengthConfig(SPI_TypeDef* SPIx, uint16_t SPI_CRCLength);
  463. void SPI_CalculateCRC(SPI_TypeDef* SPIx, FunctionalState NewState);
  464. void SPI_TransmitCRC(SPI_TypeDef* SPIx);
  465. uint16_t SPI_GetCRC(SPI_TypeDef* SPIx, uint8_t SPI_CRC);
  466. uint16_t SPI_GetCRCPolynomial(SPI_TypeDef* SPIx);
  467. /* DMA transfers management functions *****************************************/
  468. void SPI_I2S_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState);
  469. void SPI_LastDMATransferCmd(SPI_TypeDef* SPIx, uint16_t SPI_LastDMATransfer);
  470. /* Interrupts and flags management functions **********************************/
  471. void SPI_I2S_ITConfig(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState);
  472. uint16_t SPI_GetTransmissionFIFOStatus(SPI_TypeDef* SPIx);
  473. uint16_t SPI_GetReceptionFIFOStatus(SPI_TypeDef* SPIx);
  474. FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG);
  475. void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG);
  476. ITStatus SPI_I2S_GetITStatus(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT);
  477. #ifdef __cplusplus
  478. }
  479. #endif
  480. #endif /*__STM32F0XX_SPI_H */
  481. /**
  482. * @}
  483. */
  484. /**
  485. * @}
  486. */
  487. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/