You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

2208 lines
80 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_ll_i2c.h
  4. * @author MCD Application Team
  5. * @version V1.2.2
  6. * @date 14-April-2017
  7. * @brief Header file of I2C LL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_LL_I2C_H
  39. #define __STM32F7xx_LL_I2C_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx.h"
  45. /** @addtogroup STM32F7xx_LL_Driver
  46. * @{
  47. */
  48. #if defined (I2C1) || defined (I2C2) || defined (I2C3) || defined (I2C4)
  49. /** @defgroup I2C_LL I2C
  50. * @{
  51. */
  52. /* Private types -------------------------------------------------------------*/
  53. /* Private variables ---------------------------------------------------------*/
  54. /* Private constants ---------------------------------------------------------*/
  55. /** @defgroup I2C_LL_Private_Constants I2C Private Constants
  56. * @{
  57. */
  58. /**
  59. * @}
  60. */
  61. /* Private macros ------------------------------------------------------------*/
  62. #if defined(USE_FULL_LL_DRIVER)
  63. /** @defgroup I2C_LL_Private_Macros I2C Private Macros
  64. * @{
  65. */
  66. /**
  67. * @}
  68. */
  69. #endif /*USE_FULL_LL_DRIVER*/
  70. /* Exported types ------------------------------------------------------------*/
  71. #if defined(USE_FULL_LL_DRIVER)
  72. /** @defgroup I2C_LL_ES_INIT I2C Exported Init structure
  73. * @{
  74. */
  75. typedef struct
  76. {
  77. uint32_t PeripheralMode; /*!< Specifies the peripheral mode.
  78. This parameter can be a value of @ref I2C_LL_EC_PERIPHERAL_MODE
  79. This feature can be modified afterwards using unitary function @ref LL_I2C_SetMode(). */
  80. uint32_t Timing; /*!< Specifies the SDA setup, hold time and the SCL high, low period values.
  81. This parameter must be set by referring to the STM32CubeMX Tool and
  82. the helper macro @ref __LL_I2C_CONVERT_TIMINGS()
  83. This feature can be modified afterwards using unitary function @ref LL_I2C_SetTiming(). */
  84. uint32_t AnalogFilter; /*!< Enables or disables analog noise filter.
  85. This parameter can be a value of @ref I2C_LL_EC_ANALOGFILTER_SELECTION
  86. This feature can be modified afterwards using unitary functions @ref LL_I2C_EnableAnalogFilter() or LL_I2C_DisableAnalogFilter(). */
  87. uint32_t DigitalFilter; /*!< Configures the digital noise filter.
  88. This parameter can be a number between Min_Data = 0x00 and Max_Data = 0x0F
  89. This feature can be modified afterwards using unitary function @ref LL_I2C_SetDigitalFilter(). */
  90. uint32_t OwnAddress1; /*!< Specifies the device own address 1.
  91. This parameter must be a value between Min_Data = 0x00 and Max_Data = 0x3FF
  92. This feature can be modified afterwards using unitary function @ref LL_I2C_SetOwnAddress1(). */
  93. uint32_t TypeAcknowledge; /*!< Specifies the ACKnowledge or Non ACKnowledge condition after the address receive match code or next received byte.
  94. This parameter can be a value of @ref I2C_LL_EC_I2C_ACKNOWLEDGE
  95. This feature can be modified afterwards using unitary function @ref LL_I2C_AcknowledgeNextData(). */
  96. uint32_t OwnAddrSize; /*!< Specifies the device own address 1 size (7-bit or 10-bit).
  97. This parameter can be a value of @ref I2C_LL_EC_OWNADDRESS1
  98. This feature can be modified afterwards using unitary function @ref LL_I2C_SetOwnAddress1(). */
  99. } LL_I2C_InitTypeDef;
  100. /**
  101. * @}
  102. */
  103. #endif /*USE_FULL_LL_DRIVER*/
  104. /* Exported constants --------------------------------------------------------*/
  105. /** @defgroup I2C_LL_Exported_Constants I2C Exported Constants
  106. * @{
  107. */
  108. /** @defgroup I2C_LL_EC_CLEAR_FLAG Clear Flags Defines
  109. * @brief Flags defines which can be used with LL_I2C_WriteReg function
  110. * @{
  111. */
  112. #define LL_I2C_ICR_ADDRCF I2C_ICR_ADDRCF /*!< Address Matched flag */
  113. #define LL_I2C_ICR_NACKCF I2C_ICR_NACKCF /*!< Not Acknowledge flag */
  114. #define LL_I2C_ICR_STOPCF I2C_ICR_STOPCF /*!< Stop detection flag */
  115. #define LL_I2C_ICR_BERRCF I2C_ICR_BERRCF /*!< Bus error flag */
  116. #define LL_I2C_ICR_ARLOCF I2C_ICR_ARLOCF /*!< Arbitration Lost flag */
  117. #define LL_I2C_ICR_OVRCF I2C_ICR_OVRCF /*!< Overrun/Underrun flag */
  118. #define LL_I2C_ICR_PECCF I2C_ICR_PECCF /*!< PEC error flag */
  119. #define LL_I2C_ICR_TIMOUTCF I2C_ICR_TIMOUTCF /*!< Timeout detection flag */
  120. #define LL_I2C_ICR_ALERTCF I2C_ICR_ALERTCF /*!< Alert flag */
  121. /**
  122. * @}
  123. */
  124. /** @defgroup I2C_LL_EC_GET_FLAG Get Flags Defines
  125. * @brief Flags defines which can be used with LL_I2C_ReadReg function
  126. * @{
  127. */
  128. #define LL_I2C_ISR_TXE I2C_ISR_TXE /*!< Transmit data register empty */
  129. #define LL_I2C_ISR_TXIS I2C_ISR_TXIS /*!< Transmit interrupt status */
  130. #define LL_I2C_ISR_RXNE I2C_ISR_RXNE /*!< Receive data register not empty */
  131. #define LL_I2C_ISR_ADDR I2C_ISR_ADDR /*!< Address matched (slave mode) */
  132. #define LL_I2C_ISR_NACKF I2C_ISR_NACKF /*!< Not Acknowledge received flag */
  133. #define LL_I2C_ISR_STOPF I2C_ISR_STOPF /*!< Stop detection flag */
  134. #define LL_I2C_ISR_TC I2C_ISR_TC /*!< Transfer Complete (master mode) */
  135. #define LL_I2C_ISR_TCR I2C_ISR_TCR /*!< Transfer Complete Reload */
  136. #define LL_I2C_ISR_BERR I2C_ISR_BERR /*!< Bus error */
  137. #define LL_I2C_ISR_ARLO I2C_ISR_ARLO /*!< Arbitration lost */
  138. #define LL_I2C_ISR_OVR I2C_ISR_OVR /*!< Overrun/Underrun (slave mode) */
  139. #define LL_I2C_ISR_PECERR I2C_ISR_PECERR /*!< PEC Error in reception (SMBus mode) */
  140. #define LL_I2C_ISR_TIMEOUT I2C_ISR_TIMEOUT /*!< Timeout detection flag (SMBus mode) */
  141. #define LL_I2C_ISR_ALERT I2C_ISR_ALERT /*!< SMBus alert (SMBus mode) */
  142. #define LL_I2C_ISR_BUSY I2C_ISR_BUSY /*!< Bus busy */
  143. /**
  144. * @}
  145. */
  146. /** @defgroup I2C_LL_EC_IT IT Defines
  147. * @brief IT defines which can be used with LL_I2C_ReadReg and LL_I2C_WriteReg functions
  148. * @{
  149. */
  150. #define LL_I2C_CR1_TXIE I2C_CR1_TXIE /*!< TX Interrupt enable */
  151. #define LL_I2C_CR1_RXIE I2C_CR1_RXIE /*!< RX Interrupt enable */
  152. #define LL_I2C_CR1_ADDRIE I2C_CR1_ADDRIE /*!< Address match Interrupt enable (slave only) */
  153. #define LL_I2C_CR1_NACKIE I2C_CR1_NACKIE /*!< Not acknowledge received Interrupt enable */
  154. #define LL_I2C_CR1_STOPIE I2C_CR1_STOPIE /*!< STOP detection Interrupt enable */
  155. #define LL_I2C_CR1_TCIE I2C_CR1_TCIE /*!< Transfer Complete interrupt enable */
  156. #define LL_I2C_CR1_ERRIE I2C_CR1_ERRIE /*!< Error interrupts enable */
  157. /**
  158. * @}
  159. */
  160. /** @defgroup I2C_LL_EC_PERIPHERAL_MODE Peripheral Mode
  161. * @{
  162. */
  163. #define LL_I2C_MODE_I2C 0x00000000U /*!< I2C Master or Slave mode */
  164. #define LL_I2C_MODE_SMBUS_HOST I2C_CR1_SMBHEN /*!< SMBus Host address acknowledge */
  165. #define LL_I2C_MODE_SMBUS_DEVICE 0x00000000U /*!< SMBus Device default mode (Default address not acknowledge) */
  166. #define LL_I2C_MODE_SMBUS_DEVICE_ARP I2C_CR1_SMBDEN /*!< SMBus Device Default address acknowledge */
  167. /**
  168. * @}
  169. */
  170. /** @defgroup I2C_LL_EC_ANALOGFILTER_SELECTION Analog Filter Selection
  171. * @{
  172. */
  173. #define LL_I2C_ANALOGFILTER_ENABLE 0x00000000U /*!< Analog filter is enabled. */
  174. #define LL_I2C_ANALOGFILTER_DISABLE I2C_CR1_ANFOFF /*!< Analog filter is disabled. */
  175. /**
  176. * @}
  177. */
  178. /** @defgroup I2C_LL_EC_ADDRESSING_MODE Master Addressing Mode
  179. * @{
  180. */
  181. #define LL_I2C_ADDRESSING_MODE_7BIT 0x00000000U /*!< Master operates in 7-bit addressing mode. */
  182. #define LL_I2C_ADDRESSING_MODE_10BIT I2C_CR2_ADD10 /*!< Master operates in 10-bit addressing mode.*/
  183. /**
  184. * @}
  185. */
  186. /** @defgroup I2C_LL_EC_OWNADDRESS1 Own Address 1 Length
  187. * @{
  188. */
  189. #define LL_I2C_OWNADDRESS1_7BIT 0x00000000U /*!< Own address 1 is a 7-bit address. */
  190. #define LL_I2C_OWNADDRESS1_10BIT I2C_OAR1_OA1MODE /*!< Own address 1 is a 10-bit address.*/
  191. /**
  192. * @}
  193. */
  194. /** @defgroup I2C_LL_EC_OWNADDRESS2 Own Address 2 Masks
  195. * @{
  196. */
  197. #define LL_I2C_OWNADDRESS2_NOMASK I2C_OAR2_OA2NOMASK /*!< Own Address2 No mask. */
  198. #define LL_I2C_OWNADDRESS2_MASK01 I2C_OAR2_OA2MASK01 /*!< Only Address2 bits[7:2] are compared. */
  199. #define LL_I2C_OWNADDRESS2_MASK02 I2C_OAR2_OA2MASK02 /*!< Only Address2 bits[7:3] are compared. */
  200. #define LL_I2C_OWNADDRESS2_MASK03 I2C_OAR2_OA2MASK03 /*!< Only Address2 bits[7:4] are compared. */
  201. #define LL_I2C_OWNADDRESS2_MASK04 I2C_OAR2_OA2MASK04 /*!< Only Address2 bits[7:5] are compared. */
  202. #define LL_I2C_OWNADDRESS2_MASK05 I2C_OAR2_OA2MASK05 /*!< Only Address2 bits[7:6] are compared. */
  203. #define LL_I2C_OWNADDRESS2_MASK06 I2C_OAR2_OA2MASK06 /*!< Only Address2 bits[7] are compared. */
  204. #define LL_I2C_OWNADDRESS2_MASK07 I2C_OAR2_OA2MASK07 /*!< No comparison is done. All Address2 are acknowledged.*/
  205. /**
  206. * @}
  207. */
  208. /** @defgroup I2C_LL_EC_I2C_ACKNOWLEDGE Acknowledge Generation
  209. * @{
  210. */
  211. #define LL_I2C_ACK 0x00000000U /*!< ACK is sent after current received byte. */
  212. #define LL_I2C_NACK I2C_CR2_NACK /*!< NACK is sent after current received byte.*/
  213. /**
  214. * @}
  215. */
  216. /** @defgroup I2C_LL_EC_ADDRSLAVE Slave Address Length
  217. * @{
  218. */
  219. #define LL_I2C_ADDRSLAVE_7BIT 0x00000000U /*!< Slave Address in 7-bit. */
  220. #define LL_I2C_ADDRSLAVE_10BIT I2C_CR2_ADD10 /*!< Slave Address in 10-bit.*/
  221. /**
  222. * @}
  223. */
  224. /** @defgroup I2C_LL_EC_REQUEST Transfer Request Direction
  225. * @{
  226. */
  227. #define LL_I2C_REQUEST_WRITE 0x00000000U /*!< Master request a write transfer. */
  228. #define LL_I2C_REQUEST_READ I2C_CR2_RD_WRN /*!< Master request a read transfer. */
  229. /**
  230. * @}
  231. */
  232. /** @defgroup I2C_LL_EC_MODE Transfer End Mode
  233. * @{
  234. */
  235. #define LL_I2C_MODE_RELOAD I2C_CR2_RELOAD /*!< Enable I2C Reload mode. */
  236. #define LL_I2C_MODE_AUTOEND I2C_CR2_AUTOEND /*!< Enable I2C Automatic end mode with no HW PEC comparison. */
  237. #define LL_I2C_MODE_SOFTEND 0x00000000U /*!< Enable I2C Software end mode with no HW PEC comparison. */
  238. #define LL_I2C_MODE_SMBUS_RELOAD LL_I2C_MODE_RELOAD /*!< Enable SMBUS Automatic end mode with HW PEC comparison. */
  239. #define LL_I2C_MODE_SMBUS_AUTOEND_NO_PEC LL_I2C_MODE_AUTOEND /*!< Enable SMBUS Automatic end mode with HW PEC comparison. */
  240. #define LL_I2C_MODE_SMBUS_SOFTEND_NO_PEC LL_I2C_MODE_SOFTEND /*!< Enable SMBUS Software end mode with HW PEC comparison. */
  241. #define LL_I2C_MODE_SMBUS_AUTOEND_WITH_PEC (uint32_t)(LL_I2C_MODE_AUTOEND | I2C_CR2_PECBYTE) /*!< Enable SMBUS Automatic end mode with HW PEC comparison. */
  242. #define LL_I2C_MODE_SMBUS_SOFTEND_WITH_PEC (uint32_t)(LL_I2C_MODE_SOFTEND | I2C_CR2_PECBYTE) /*!< Enable SMBUS Software end mode with HW PEC comparison. */
  243. /**
  244. * @}
  245. */
  246. /** @defgroup I2C_LL_EC_GENERATE Start And Stop Generation
  247. * @{
  248. */
  249. #define LL_I2C_GENERATE_NOSTARTSTOP 0x00000000U /*!< Don't Generate Stop and Start condition. */
  250. #define LL_I2C_GENERATE_STOP I2C_CR2_STOP /*!< Generate Stop condition (Size should be set to 0). */
  251. #define LL_I2C_GENERATE_START_READ (uint32_t)(I2C_CR2_START | I2C_CR2_RD_WRN) /*!< Generate Start for read request. */
  252. #define LL_I2C_GENERATE_START_WRITE I2C_CR2_START /*!< Generate Start for write request. */
  253. #define LL_I2C_GENERATE_RESTART_7BIT_READ (uint32_t)(I2C_CR2_START | I2C_CR2_RD_WRN) /*!< Generate Restart for read request, slave 7Bit address. */
  254. #define LL_I2C_GENERATE_RESTART_7BIT_WRITE I2C_CR2_START /*!< Generate Restart for write request, slave 7Bit address. */
  255. #define LL_I2C_GENERATE_RESTART_10BIT_READ (uint32_t)(I2C_CR2_START | I2C_CR2_RD_WRN | I2C_CR2_HEAD10R) /*!< Generate Restart for read request, slave 10Bit address. */
  256. #define LL_I2C_GENERATE_RESTART_10BIT_WRITE I2C_CR2_START /*!< Generate Restart for write request, slave 10Bit address.*/
  257. /**
  258. * @}
  259. */
  260. /** @defgroup I2C_LL_EC_DIRECTION Read Write Direction
  261. * @{
  262. */
  263. #define LL_I2C_DIRECTION_WRITE 0x00000000U /*!< Write transfer request by master, slave enters receiver mode. */
  264. #define LL_I2C_DIRECTION_READ I2C_ISR_DIR /*!< Read transfer request by master, slave enters transmitter mode.*/
  265. /**
  266. * @}
  267. */
  268. /** @defgroup I2C_LL_EC_DMA_REG_DATA DMA Register Data
  269. * @{
  270. */
  271. #define LL_I2C_DMA_REG_DATA_TRANSMIT 0x00000000U /*!< Get address of data register used for transmission */
  272. #define LL_I2C_DMA_REG_DATA_RECEIVE 0x00000001U /*!< Get address of data register used for reception */
  273. /**
  274. * @}
  275. */
  276. /** @defgroup I2C_LL_EC_SMBUS_TIMEOUTA_MODE SMBus TimeoutA Mode SCL SDA Timeout
  277. * @{
  278. */
  279. #define LL_I2C_SMBUS_TIMEOUTA_MODE_SCL_LOW 0x00000000U /*!< TimeoutA is used to detect SCL low level timeout. */
  280. #define LL_I2C_SMBUS_TIMEOUTA_MODE_SDA_SCL_HIGH I2C_TIMEOUTR_TIDLE /*!< TimeoutA is used to detect both SCL and SDA high level timeout.*/
  281. /**
  282. * @}
  283. */
  284. /** @defgroup I2C_LL_EC_SMBUS_TIMEOUT_SELECTION SMBus Timeout Selection
  285. * @{
  286. */
  287. #define LL_I2C_SMBUS_TIMEOUTA I2C_TIMEOUTR_TIMOUTEN /*!< TimeoutA enable bit */
  288. #define LL_I2C_SMBUS_TIMEOUTB I2C_TIMEOUTR_TEXTEN /*!< TimeoutB (extended clock) enable bit */
  289. #define LL_I2C_SMBUS_ALL_TIMEOUT (uint32_t)(I2C_TIMEOUTR_TIMOUTEN | I2C_TIMEOUTR_TEXTEN) /*!< TimeoutA and TimeoutB (extended clock) enable bits */
  290. /**
  291. * @}
  292. */
  293. /**
  294. * @}
  295. */
  296. /* Exported macro ------------------------------------------------------------*/
  297. /** @defgroup I2C_LL_Exported_Macros I2C Exported Macros
  298. * @{
  299. */
  300. /** @defgroup I2C_LL_EM_WRITE_READ Common Write and read registers Macros
  301. * @{
  302. */
  303. /**
  304. * @brief Write a value in I2C register
  305. * @param __INSTANCE__ I2C Instance
  306. * @param __REG__ Register to be written
  307. * @param __VALUE__ Value to be written in the register
  308. * @retval None
  309. */
  310. #define LL_I2C_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  311. /**
  312. * @brief Read a value in I2C register
  313. * @param __INSTANCE__ I2C Instance
  314. * @param __REG__ Register to be read
  315. * @retval Register value
  316. */
  317. #define LL_I2C_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  318. /**
  319. * @}
  320. */
  321. /** @defgroup I2C_LL_EM_CONVERT_TIMINGS Convert SDA SCL timings
  322. * @{
  323. */
  324. /**
  325. * @brief Configure the SDA setup, hold time and the SCL high, low period.
  326. * @param __PRESCALER__ This parameter must be a value between Min_Data=0 and Max_Data=0xF.
  327. * @param __DATA_SETUP_TIME__ This parameter must be a value between Min_Data=0 and Max_Data=0xF. (tscldel = (SCLDEL+1)xtpresc)
  328. * @param __DATA_HOLD_TIME__ This parameter must be a value between Min_Data=0 and Max_Data=0xF. (tsdadel = SDADELxtpresc)
  329. * @param __CLOCK_HIGH_PERIOD__ This parameter must be a value between Min_Data=0 and Max_Data=0xFF. (tsclh = (SCLH+1)xtpresc)
  330. * @param __CLOCK_LOW_PERIOD__ This parameter must be a value between Min_Data=0 and Max_Data=0xFF. (tscll = (SCLL+1)xtpresc)
  331. * @retval Value between Min_Data=0 and Max_Data=0xFFFFFFFF
  332. */
  333. #define __LL_I2C_CONVERT_TIMINGS(__PRESCALER__, __DATA_SETUP_TIME__, __DATA_HOLD_TIME__, __CLOCK_HIGH_PERIOD__, __CLOCK_LOW_PERIOD__) \
  334. ((((uint32_t)(__PRESCALER__) << I2C_TIMINGR_PRESC_Pos) & I2C_TIMINGR_PRESC) | \
  335. (((uint32_t)(__DATA_SETUP_TIME__) << I2C_TIMINGR_SCLDEL_Pos) & I2C_TIMINGR_SCLDEL) | \
  336. (((uint32_t)(__DATA_HOLD_TIME__) << I2C_TIMINGR_SDADEL_Pos) & I2C_TIMINGR_SDADEL) | \
  337. (((uint32_t)(__CLOCK_HIGH_PERIOD__) << I2C_TIMINGR_SCLH_Pos) & I2C_TIMINGR_SCLH) | \
  338. (((uint32_t)(__CLOCK_LOW_PERIOD__) << I2C_TIMINGR_SCLL_Pos) & I2C_TIMINGR_SCLL))
  339. /**
  340. * @}
  341. */
  342. /**
  343. * @}
  344. */
  345. /* Exported functions --------------------------------------------------------*/
  346. /** @defgroup I2C_LL_Exported_Functions I2C Exported Functions
  347. * @{
  348. */
  349. /** @defgroup I2C_LL_EF_Configuration Configuration
  350. * @{
  351. */
  352. /**
  353. * @brief Enable I2C peripheral (PE = 1).
  354. * @rmtoll CR1 PE LL_I2C_Enable
  355. * @param I2Cx I2C Instance.
  356. * @retval None
  357. */
  358. __STATIC_INLINE void LL_I2C_Enable(I2C_TypeDef *I2Cx)
  359. {
  360. SET_BIT(I2Cx->CR1, I2C_CR1_PE);
  361. }
  362. /**
  363. * @brief Disable I2C peripheral (PE = 0).
  364. * @note When PE = 0, the I2C SCL and SDA lines are released.
  365. * Internal state machines and status bits are put back to their reset value.
  366. * When cleared, PE must be kept low for at least 3 APB clock cycles.
  367. * @rmtoll CR1 PE LL_I2C_Disable
  368. * @param I2Cx I2C Instance.
  369. * @retval None
  370. */
  371. __STATIC_INLINE void LL_I2C_Disable(I2C_TypeDef *I2Cx)
  372. {
  373. CLEAR_BIT(I2Cx->CR1, I2C_CR1_PE);
  374. }
  375. /**
  376. * @brief Check if the I2C peripheral is enabled or disabled.
  377. * @rmtoll CR1 PE LL_I2C_IsEnabled
  378. * @param I2Cx I2C Instance.
  379. * @retval State of bit (1 or 0).
  380. */
  381. __STATIC_INLINE uint32_t LL_I2C_IsEnabled(I2C_TypeDef *I2Cx)
  382. {
  383. return (READ_BIT(I2Cx->CR1, I2C_CR1_PE) == (I2C_CR1_PE));
  384. }
  385. /**
  386. * @brief Configure Noise Filters (Analog and Digital).
  387. * @note If the analog filter is also enabled, the digital filter is added to analog filter.
  388. * The filters can only be programmed when the I2C is disabled (PE = 0).
  389. * @rmtoll CR1 ANFOFF LL_I2C_ConfigFilters\n
  390. * CR1 DNF LL_I2C_ConfigFilters
  391. * @param I2Cx I2C Instance.
  392. * @param AnalogFilter This parameter can be one of the following values:
  393. * @arg @ref LL_I2C_ANALOGFILTER_ENABLE
  394. * @arg @ref LL_I2C_ANALOGFILTER_DISABLE
  395. * @param DigitalFilter This parameter must be a value between Min_Data=0x00 (Digital filter disabled) and Max_Data=0x0F (Digital filter enabled and filtering capability up to 15*ti2cclk).
  396. * This parameter is used to configure the digital noise filter on SDA and SCL input.
  397. * The digital filter will filter spikes with a length of up to DNF[3:0]*ti2cclk.
  398. * @retval None
  399. */
  400. __STATIC_INLINE void LL_I2C_ConfigFilters(I2C_TypeDef *I2Cx, uint32_t AnalogFilter, uint32_t DigitalFilter)
  401. {
  402. MODIFY_REG(I2Cx->CR1, I2C_CR1_ANFOFF | I2C_CR1_DNF, AnalogFilter | (DigitalFilter << I2C_CR1_DNF_Pos));
  403. }
  404. /**
  405. * @brief Configure Digital Noise Filter.
  406. * @note If the analog filter is also enabled, the digital filter is added to analog filter.
  407. * This filter can only be programmed when the I2C is disabled (PE = 0).
  408. * @rmtoll CR1 DNF LL_I2C_SetDigitalFilter
  409. * @param I2Cx I2C Instance.
  410. * @param DigitalFilter This parameter must be a value between Min_Data=0x00 (Digital filter disabled) and Max_Data=0x0F (Digital filter enabled and filtering capability up to 15*ti2cclk).
  411. * This parameter is used to configure the digital noise filter on SDA and SCL input.
  412. * The digital filter will filter spikes with a length of up to DNF[3:0]*ti2cclk.
  413. * @retval None
  414. */
  415. __STATIC_INLINE void LL_I2C_SetDigitalFilter(I2C_TypeDef *I2Cx, uint32_t DigitalFilter)
  416. {
  417. MODIFY_REG(I2Cx->CR1, I2C_CR1_DNF, DigitalFilter << I2C_CR1_DNF_Pos);
  418. }
  419. /**
  420. * @brief Get the current Digital Noise Filter configuration.
  421. * @rmtoll CR1 DNF LL_I2C_GetDigitalFilter
  422. * @param I2Cx I2C Instance.
  423. * @retval Value between Min_Data=0x0 and Max_Data=0xF
  424. */
  425. __STATIC_INLINE uint32_t LL_I2C_GetDigitalFilter(I2C_TypeDef *I2Cx)
  426. {
  427. return (uint32_t)(READ_BIT(I2Cx->CR1, I2C_CR1_DNF) >> I2C_CR1_DNF_Pos);
  428. }
  429. /**
  430. * @brief Enable Analog Noise Filter.
  431. * @note This filter can only be programmed when the I2C is disabled (PE = 0).
  432. * @rmtoll CR1 ANFOFF LL_I2C_EnableAnalogFilter
  433. * @param I2Cx I2C Instance.
  434. * @retval None
  435. */
  436. __STATIC_INLINE void LL_I2C_EnableAnalogFilter(I2C_TypeDef *I2Cx)
  437. {
  438. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ANFOFF);
  439. }
  440. /**
  441. * @brief Disable Analog Noise Filter.
  442. * @note This filter can only be programmed when the I2C is disabled (PE = 0).
  443. * @rmtoll CR1 ANFOFF LL_I2C_DisableAnalogFilter
  444. * @param I2Cx I2C Instance.
  445. * @retval None
  446. */
  447. __STATIC_INLINE void LL_I2C_DisableAnalogFilter(I2C_TypeDef *I2Cx)
  448. {
  449. SET_BIT(I2Cx->CR1, I2C_CR1_ANFOFF);
  450. }
  451. /**
  452. * @brief Check if Analog Noise Filter is enabled or disabled.
  453. * @rmtoll CR1 ANFOFF LL_I2C_IsEnabledAnalogFilter
  454. * @param I2Cx I2C Instance.
  455. * @retval State of bit (1 or 0).
  456. */
  457. __STATIC_INLINE uint32_t LL_I2C_IsEnabledAnalogFilter(I2C_TypeDef *I2Cx)
  458. {
  459. return (READ_BIT(I2Cx->CR1, I2C_CR1_ANFOFF) != (I2C_CR1_ANFOFF));
  460. }
  461. /**
  462. * @brief Enable DMA transmission requests.
  463. * @rmtoll CR1 TXDMAEN LL_I2C_EnableDMAReq_TX
  464. * @param I2Cx I2C Instance.
  465. * @retval None
  466. */
  467. __STATIC_INLINE void LL_I2C_EnableDMAReq_TX(I2C_TypeDef *I2Cx)
  468. {
  469. SET_BIT(I2Cx->CR1, I2C_CR1_TXDMAEN);
  470. }
  471. /**
  472. * @brief Disable DMA transmission requests.
  473. * @rmtoll CR1 TXDMAEN LL_I2C_DisableDMAReq_TX
  474. * @param I2Cx I2C Instance.
  475. * @retval None
  476. */
  477. __STATIC_INLINE void LL_I2C_DisableDMAReq_TX(I2C_TypeDef *I2Cx)
  478. {
  479. CLEAR_BIT(I2Cx->CR1, I2C_CR1_TXDMAEN);
  480. }
  481. /**
  482. * @brief Check if DMA transmission requests are enabled or disabled.
  483. * @rmtoll CR1 TXDMAEN LL_I2C_IsEnabledDMAReq_TX
  484. * @param I2Cx I2C Instance.
  485. * @retval State of bit (1 or 0).
  486. */
  487. __STATIC_INLINE uint32_t LL_I2C_IsEnabledDMAReq_TX(I2C_TypeDef *I2Cx)
  488. {
  489. return (READ_BIT(I2Cx->CR1, I2C_CR1_TXDMAEN) == (I2C_CR1_TXDMAEN));
  490. }
  491. /**
  492. * @brief Enable DMA reception requests.
  493. * @rmtoll CR1 RXDMAEN LL_I2C_EnableDMAReq_RX
  494. * @param I2Cx I2C Instance.
  495. * @retval None
  496. */
  497. __STATIC_INLINE void LL_I2C_EnableDMAReq_RX(I2C_TypeDef *I2Cx)
  498. {
  499. SET_BIT(I2Cx->CR1, I2C_CR1_RXDMAEN);
  500. }
  501. /**
  502. * @brief Disable DMA reception requests.
  503. * @rmtoll CR1 RXDMAEN LL_I2C_DisableDMAReq_RX
  504. * @param I2Cx I2C Instance.
  505. * @retval None
  506. */
  507. __STATIC_INLINE void LL_I2C_DisableDMAReq_RX(I2C_TypeDef *I2Cx)
  508. {
  509. CLEAR_BIT(I2Cx->CR1, I2C_CR1_RXDMAEN);
  510. }
  511. /**
  512. * @brief Check if DMA reception requests are enabled or disabled.
  513. * @rmtoll CR1 RXDMAEN LL_I2C_IsEnabledDMAReq_RX
  514. * @param I2Cx I2C Instance.
  515. * @retval State of bit (1 or 0).
  516. */
  517. __STATIC_INLINE uint32_t LL_I2C_IsEnabledDMAReq_RX(I2C_TypeDef *I2Cx)
  518. {
  519. return (READ_BIT(I2Cx->CR1, I2C_CR1_RXDMAEN) == (I2C_CR1_RXDMAEN));
  520. }
  521. /**
  522. * @brief Get the data register address used for DMA transfer
  523. * @rmtoll TXDR TXDATA LL_I2C_DMA_GetRegAddr\n
  524. * RXDR RXDATA LL_I2C_DMA_GetRegAddr
  525. * @param I2Cx I2C Instance
  526. * @param Direction This parameter can be one of the following values:
  527. * @arg @ref LL_I2C_DMA_REG_DATA_TRANSMIT
  528. * @arg @ref LL_I2C_DMA_REG_DATA_RECEIVE
  529. * @retval Address of data register
  530. */
  531. __STATIC_INLINE uint32_t LL_I2C_DMA_GetRegAddr(I2C_TypeDef *I2Cx, uint32_t Direction)
  532. {
  533. register uint32_t data_reg_addr = 0U;
  534. if (Direction == LL_I2C_DMA_REG_DATA_TRANSMIT)
  535. {
  536. /* return address of TXDR register */
  537. data_reg_addr = (uint32_t) & (I2Cx->TXDR);
  538. }
  539. else
  540. {
  541. /* return address of RXDR register */
  542. data_reg_addr = (uint32_t) & (I2Cx->RXDR);
  543. }
  544. return data_reg_addr;
  545. }
  546. /**
  547. * @brief Enable Clock stretching.
  548. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  549. * @rmtoll CR1 NOSTRETCH LL_I2C_EnableClockStretching
  550. * @param I2Cx I2C Instance.
  551. * @retval None
  552. */
  553. __STATIC_INLINE void LL_I2C_EnableClockStretching(I2C_TypeDef *I2Cx)
  554. {
  555. CLEAR_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH);
  556. }
  557. /**
  558. * @brief Disable Clock stretching.
  559. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  560. * @rmtoll CR1 NOSTRETCH LL_I2C_DisableClockStretching
  561. * @param I2Cx I2C Instance.
  562. * @retval None
  563. */
  564. __STATIC_INLINE void LL_I2C_DisableClockStretching(I2C_TypeDef *I2Cx)
  565. {
  566. SET_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH);
  567. }
  568. /**
  569. * @brief Check if Clock stretching is enabled or disabled.
  570. * @rmtoll CR1 NOSTRETCH LL_I2C_IsEnabledClockStretching
  571. * @param I2Cx I2C Instance.
  572. * @retval State of bit (1 or 0).
  573. */
  574. __STATIC_INLINE uint32_t LL_I2C_IsEnabledClockStretching(I2C_TypeDef *I2Cx)
  575. {
  576. return (READ_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH) != (I2C_CR1_NOSTRETCH));
  577. }
  578. /**
  579. * @brief Enable hardware byte control in slave mode.
  580. * @rmtoll CR1 SBC LL_I2C_EnableSlaveByteControl
  581. * @param I2Cx I2C Instance.
  582. * @retval None
  583. */
  584. __STATIC_INLINE void LL_I2C_EnableSlaveByteControl(I2C_TypeDef *I2Cx)
  585. {
  586. SET_BIT(I2Cx->CR1, I2C_CR1_SBC);
  587. }
  588. /**
  589. * @brief Disable hardware byte control in slave mode.
  590. * @rmtoll CR1 SBC LL_I2C_DisableSlaveByteControl
  591. * @param I2Cx I2C Instance.
  592. * @retval None
  593. */
  594. __STATIC_INLINE void LL_I2C_DisableSlaveByteControl(I2C_TypeDef *I2Cx)
  595. {
  596. CLEAR_BIT(I2Cx->CR1, I2C_CR1_SBC);
  597. }
  598. /**
  599. * @brief Check if hardware byte control in slave mode is enabled or disabled.
  600. * @rmtoll CR1 SBC LL_I2C_IsEnabledSlaveByteControl
  601. * @param I2Cx I2C Instance.
  602. * @retval State of bit (1 or 0).
  603. */
  604. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSlaveByteControl(I2C_TypeDef *I2Cx)
  605. {
  606. return (READ_BIT(I2Cx->CR1, I2C_CR1_SBC) == (I2C_CR1_SBC));
  607. }
  608. /**
  609. * @brief Enable General Call.
  610. * @note When enabled the Address 0x00 is ACKed.
  611. * @rmtoll CR1 GCEN LL_I2C_EnableGeneralCall
  612. * @param I2Cx I2C Instance.
  613. * @retval None
  614. */
  615. __STATIC_INLINE void LL_I2C_EnableGeneralCall(I2C_TypeDef *I2Cx)
  616. {
  617. SET_BIT(I2Cx->CR1, I2C_CR1_GCEN);
  618. }
  619. /**
  620. * @brief Disable General Call.
  621. * @note When disabled the Address 0x00 is NACKed.
  622. * @rmtoll CR1 GCEN LL_I2C_DisableGeneralCall
  623. * @param I2Cx I2C Instance.
  624. * @retval None
  625. */
  626. __STATIC_INLINE void LL_I2C_DisableGeneralCall(I2C_TypeDef *I2Cx)
  627. {
  628. CLEAR_BIT(I2Cx->CR1, I2C_CR1_GCEN);
  629. }
  630. /**
  631. * @brief Check if General Call is enabled or disabled.
  632. * @rmtoll CR1 GCEN LL_I2C_IsEnabledGeneralCall
  633. * @param I2Cx I2C Instance.
  634. * @retval State of bit (1 or 0).
  635. */
  636. __STATIC_INLINE uint32_t LL_I2C_IsEnabledGeneralCall(I2C_TypeDef *I2Cx)
  637. {
  638. return (READ_BIT(I2Cx->CR1, I2C_CR1_GCEN) == (I2C_CR1_GCEN));
  639. }
  640. /**
  641. * @brief Configure the Master to operate in 7-bit or 10-bit addressing mode.
  642. * @note Changing this bit is not allowed, when the START bit is set.
  643. * @rmtoll CR2 ADD10 LL_I2C_SetMasterAddressingMode
  644. * @param I2Cx I2C Instance.
  645. * @param AddressingMode This parameter can be one of the following values:
  646. * @arg @ref LL_I2C_ADDRESSING_MODE_7BIT
  647. * @arg @ref LL_I2C_ADDRESSING_MODE_10BIT
  648. * @retval None
  649. */
  650. __STATIC_INLINE void LL_I2C_SetMasterAddressingMode(I2C_TypeDef *I2Cx, uint32_t AddressingMode)
  651. {
  652. MODIFY_REG(I2Cx->CR2, I2C_CR2_ADD10, AddressingMode);
  653. }
  654. /**
  655. * @brief Get the Master addressing mode.
  656. * @rmtoll CR2 ADD10 LL_I2C_GetMasterAddressingMode
  657. * @param I2Cx I2C Instance.
  658. * @retval Returned value can be one of the following values:
  659. * @arg @ref LL_I2C_ADDRESSING_MODE_7BIT
  660. * @arg @ref LL_I2C_ADDRESSING_MODE_10BIT
  661. */
  662. __STATIC_INLINE uint32_t LL_I2C_GetMasterAddressingMode(I2C_TypeDef *I2Cx)
  663. {
  664. return (uint32_t)(READ_BIT(I2Cx->CR2, I2C_CR2_ADD10));
  665. }
  666. /**
  667. * @brief Set the Own Address1.
  668. * @rmtoll OAR1 OA1 LL_I2C_SetOwnAddress1\n
  669. * OAR1 OA1MODE LL_I2C_SetOwnAddress1
  670. * @param I2Cx I2C Instance.
  671. * @param OwnAddress1 This parameter must be a value between Min_Data=0 and Max_Data=0x3FF.
  672. * @param OwnAddrSize This parameter can be one of the following values:
  673. * @arg @ref LL_I2C_OWNADDRESS1_7BIT
  674. * @arg @ref LL_I2C_OWNADDRESS1_10BIT
  675. * @retval None
  676. */
  677. __STATIC_INLINE void LL_I2C_SetOwnAddress1(I2C_TypeDef *I2Cx, uint32_t OwnAddress1, uint32_t OwnAddrSize)
  678. {
  679. MODIFY_REG(I2Cx->OAR1, I2C_OAR1_OA1 | I2C_OAR1_OA1MODE, OwnAddress1 | OwnAddrSize);
  680. }
  681. /**
  682. * @brief Enable acknowledge on Own Address1 match address.
  683. * @rmtoll OAR1 OA1EN LL_I2C_EnableOwnAddress1
  684. * @param I2Cx I2C Instance.
  685. * @retval None
  686. */
  687. __STATIC_INLINE void LL_I2C_EnableOwnAddress1(I2C_TypeDef *I2Cx)
  688. {
  689. SET_BIT(I2Cx->OAR1, I2C_OAR1_OA1EN);
  690. }
  691. /**
  692. * @brief Disable acknowledge on Own Address1 match address.
  693. * @rmtoll OAR1 OA1EN LL_I2C_DisableOwnAddress1
  694. * @param I2Cx I2C Instance.
  695. * @retval None
  696. */
  697. __STATIC_INLINE void LL_I2C_DisableOwnAddress1(I2C_TypeDef *I2Cx)
  698. {
  699. CLEAR_BIT(I2Cx->OAR1, I2C_OAR1_OA1EN);
  700. }
  701. /**
  702. * @brief Check if Own Address1 acknowledge is enabled or disabled.
  703. * @rmtoll OAR1 OA1EN LL_I2C_IsEnabledOwnAddress1
  704. * @param I2Cx I2C Instance.
  705. * @retval State of bit (1 or 0).
  706. */
  707. __STATIC_INLINE uint32_t LL_I2C_IsEnabledOwnAddress1(I2C_TypeDef *I2Cx)
  708. {
  709. return (READ_BIT(I2Cx->OAR1, I2C_OAR1_OA1EN) == (I2C_OAR1_OA1EN));
  710. }
  711. /**
  712. * @brief Set the 7bits Own Address2.
  713. * @note This action has no effect if own address2 is enabled.
  714. * @rmtoll OAR2 OA2 LL_I2C_SetOwnAddress2\n
  715. * OAR2 OA2MSK LL_I2C_SetOwnAddress2
  716. * @param I2Cx I2C Instance.
  717. * @param OwnAddress2 Value between Min_Data=0 and Max_Data=0x7F.
  718. * @param OwnAddrMask This parameter can be one of the following values:
  719. * @arg @ref LL_I2C_OWNADDRESS2_NOMASK
  720. * @arg @ref LL_I2C_OWNADDRESS2_MASK01
  721. * @arg @ref LL_I2C_OWNADDRESS2_MASK02
  722. * @arg @ref LL_I2C_OWNADDRESS2_MASK03
  723. * @arg @ref LL_I2C_OWNADDRESS2_MASK04
  724. * @arg @ref LL_I2C_OWNADDRESS2_MASK05
  725. * @arg @ref LL_I2C_OWNADDRESS2_MASK06
  726. * @arg @ref LL_I2C_OWNADDRESS2_MASK07
  727. * @retval None
  728. */
  729. __STATIC_INLINE void LL_I2C_SetOwnAddress2(I2C_TypeDef *I2Cx, uint32_t OwnAddress2, uint32_t OwnAddrMask)
  730. {
  731. MODIFY_REG(I2Cx->OAR2, I2C_OAR2_OA2 | I2C_OAR2_OA2MSK, OwnAddress2 | OwnAddrMask);
  732. }
  733. /**
  734. * @brief Enable acknowledge on Own Address2 match address.
  735. * @rmtoll OAR2 OA2EN LL_I2C_EnableOwnAddress2
  736. * @param I2Cx I2C Instance.
  737. * @retval None
  738. */
  739. __STATIC_INLINE void LL_I2C_EnableOwnAddress2(I2C_TypeDef *I2Cx)
  740. {
  741. SET_BIT(I2Cx->OAR2, I2C_OAR2_OA2EN);
  742. }
  743. /**
  744. * @brief Disable acknowledge on Own Address2 match address.
  745. * @rmtoll OAR2 OA2EN LL_I2C_DisableOwnAddress2
  746. * @param I2Cx I2C Instance.
  747. * @retval None
  748. */
  749. __STATIC_INLINE void LL_I2C_DisableOwnAddress2(I2C_TypeDef *I2Cx)
  750. {
  751. CLEAR_BIT(I2Cx->OAR2, I2C_OAR2_OA2EN);
  752. }
  753. /**
  754. * @brief Check if Own Address1 acknowledge is enabled or disabled.
  755. * @rmtoll OAR2 OA2EN LL_I2C_IsEnabledOwnAddress2
  756. * @param I2Cx I2C Instance.
  757. * @retval State of bit (1 or 0).
  758. */
  759. __STATIC_INLINE uint32_t LL_I2C_IsEnabledOwnAddress2(I2C_TypeDef *I2Cx)
  760. {
  761. return (READ_BIT(I2Cx->OAR2, I2C_OAR2_OA2EN) == (I2C_OAR2_OA2EN));
  762. }
  763. /**
  764. * @brief Configure the SDA setup, hold time and the SCL high, low period.
  765. * @note This bit can only be programmed when the I2C is disabled (PE = 0).
  766. * @rmtoll TIMINGR TIMINGR LL_I2C_SetTiming
  767. * @param I2Cx I2C Instance.
  768. * @param Timing This parameter must be a value between Min_Data=0 and Max_Data=0xFFFFFFFF.
  769. * @note This parameter is computed with the STM32CubeMX Tool.
  770. * @retval None
  771. */
  772. __STATIC_INLINE void LL_I2C_SetTiming(I2C_TypeDef *I2Cx, uint32_t Timing)
  773. {
  774. WRITE_REG(I2Cx->TIMINGR, Timing);
  775. }
  776. /**
  777. * @brief Get the Timing Prescaler setting.
  778. * @rmtoll TIMINGR PRESC LL_I2C_GetTimingPrescaler
  779. * @param I2Cx I2C Instance.
  780. * @retval Value between Min_Data=0x0 and Max_Data=0xF
  781. */
  782. __STATIC_INLINE uint32_t LL_I2C_GetTimingPrescaler(I2C_TypeDef *I2Cx)
  783. {
  784. return (uint32_t)(READ_BIT(I2Cx->TIMINGR, I2C_TIMINGR_PRESC) >> I2C_TIMINGR_PRESC_Pos);
  785. }
  786. /**
  787. * @brief Get the SCL low period setting.
  788. * @rmtoll TIMINGR SCLL LL_I2C_GetClockLowPeriod
  789. * @param I2Cx I2C Instance.
  790. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  791. */
  792. __STATIC_INLINE uint32_t LL_I2C_GetClockLowPeriod(I2C_TypeDef *I2Cx)
  793. {
  794. return (uint32_t)(READ_BIT(I2Cx->TIMINGR, I2C_TIMINGR_SCLL) >> I2C_TIMINGR_SCLL_Pos);
  795. }
  796. /**
  797. * @brief Get the SCL high period setting.
  798. * @rmtoll TIMINGR SCLH LL_I2C_GetClockHighPeriod
  799. * @param I2Cx I2C Instance.
  800. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  801. */
  802. __STATIC_INLINE uint32_t LL_I2C_GetClockHighPeriod(I2C_TypeDef *I2Cx)
  803. {
  804. return (uint32_t)(READ_BIT(I2Cx->TIMINGR, I2C_TIMINGR_SCLH) >> I2C_TIMINGR_SCLH_Pos);
  805. }
  806. /**
  807. * @brief Get the SDA hold time.
  808. * @rmtoll TIMINGR SDADEL LL_I2C_GetDataHoldTime
  809. * @param I2Cx I2C Instance.
  810. * @retval Value between Min_Data=0x0 and Max_Data=0xF
  811. */
  812. __STATIC_INLINE uint32_t LL_I2C_GetDataHoldTime(I2C_TypeDef *I2Cx)
  813. {
  814. return (uint32_t)(READ_BIT(I2Cx->TIMINGR, I2C_TIMINGR_SDADEL) >> I2C_TIMINGR_SDADEL_Pos);
  815. }
  816. /**
  817. * @brief Get the SDA setup time.
  818. * @rmtoll TIMINGR SCLDEL LL_I2C_GetDataSetupTime
  819. * @param I2Cx I2C Instance.
  820. * @retval Value between Min_Data=0x0 and Max_Data=0xF
  821. */
  822. __STATIC_INLINE uint32_t LL_I2C_GetDataSetupTime(I2C_TypeDef *I2Cx)
  823. {
  824. return (uint32_t)(READ_BIT(I2Cx->TIMINGR, I2C_TIMINGR_SCLDEL) >> I2C_TIMINGR_SCLDEL_Pos);
  825. }
  826. /**
  827. * @brief Configure peripheral mode.
  828. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  829. * SMBus feature is supported by the I2Cx Instance.
  830. * @rmtoll CR1 SMBHEN LL_I2C_SetMode\n
  831. * CR1 SMBDEN LL_I2C_SetMode
  832. * @param I2Cx I2C Instance.
  833. * @param PeripheralMode This parameter can be one of the following values:
  834. * @arg @ref LL_I2C_MODE_I2C
  835. * @arg @ref LL_I2C_MODE_SMBUS_HOST
  836. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE
  837. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE_ARP
  838. * @retval None
  839. */
  840. __STATIC_INLINE void LL_I2C_SetMode(I2C_TypeDef *I2Cx, uint32_t PeripheralMode)
  841. {
  842. MODIFY_REG(I2Cx->CR1, I2C_CR1_SMBHEN | I2C_CR1_SMBDEN, PeripheralMode);
  843. }
  844. /**
  845. * @brief Get peripheral mode.
  846. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  847. * SMBus feature is supported by the I2Cx Instance.
  848. * @rmtoll CR1 SMBHEN LL_I2C_GetMode\n
  849. * CR1 SMBDEN LL_I2C_GetMode
  850. * @param I2Cx I2C Instance.
  851. * @retval Returned value can be one of the following values:
  852. * @arg @ref LL_I2C_MODE_I2C
  853. * @arg @ref LL_I2C_MODE_SMBUS_HOST
  854. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE
  855. * @arg @ref LL_I2C_MODE_SMBUS_DEVICE_ARP
  856. */
  857. __STATIC_INLINE uint32_t LL_I2C_GetMode(I2C_TypeDef *I2Cx)
  858. {
  859. return (uint32_t)(READ_BIT(I2Cx->CR1, I2C_CR1_SMBHEN | I2C_CR1_SMBDEN));
  860. }
  861. /**
  862. * @brief Enable SMBus alert (Host or Device mode)
  863. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  864. * SMBus feature is supported by the I2Cx Instance.
  865. * @note SMBus Device mode:
  866. * - SMBus Alert pin is drived low and
  867. * Alert Response Address Header acknowledge is enabled.
  868. * SMBus Host mode:
  869. * - SMBus Alert pin management is supported.
  870. * @rmtoll CR1 ALERTEN LL_I2C_EnableSMBusAlert
  871. * @param I2Cx I2C Instance.
  872. * @retval None
  873. */
  874. __STATIC_INLINE void LL_I2C_EnableSMBusAlert(I2C_TypeDef *I2Cx)
  875. {
  876. SET_BIT(I2Cx->CR1, I2C_CR1_ALERTEN);
  877. }
  878. /**
  879. * @brief Disable SMBus alert (Host or Device mode)
  880. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  881. * SMBus feature is supported by the I2Cx Instance.
  882. * @note SMBus Device mode:
  883. * - SMBus Alert pin is not drived (can be used as a standard GPIO) and
  884. * Alert Response Address Header acknowledge is disabled.
  885. * SMBus Host mode:
  886. * - SMBus Alert pin management is not supported.
  887. * @rmtoll CR1 ALERTEN LL_I2C_DisableSMBusAlert
  888. * @param I2Cx I2C Instance.
  889. * @retval None
  890. */
  891. __STATIC_INLINE void LL_I2C_DisableSMBusAlert(I2C_TypeDef *I2Cx)
  892. {
  893. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ALERTEN);
  894. }
  895. /**
  896. * @brief Check if SMBus alert (Host or Device mode) is enabled or disabled.
  897. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  898. * SMBus feature is supported by the I2Cx Instance.
  899. * @rmtoll CR1 ALERTEN LL_I2C_IsEnabledSMBusAlert
  900. * @param I2Cx I2C Instance.
  901. * @retval State of bit (1 or 0).
  902. */
  903. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusAlert(I2C_TypeDef *I2Cx)
  904. {
  905. return (READ_BIT(I2Cx->CR1, I2C_CR1_ALERTEN) == (I2C_CR1_ALERTEN));
  906. }
  907. /**
  908. * @brief Enable SMBus Packet Error Calculation (PEC).
  909. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  910. * SMBus feature is supported by the I2Cx Instance.
  911. * @rmtoll CR1 PECEN LL_I2C_EnableSMBusPEC
  912. * @param I2Cx I2C Instance.
  913. * @retval None
  914. */
  915. __STATIC_INLINE void LL_I2C_EnableSMBusPEC(I2C_TypeDef *I2Cx)
  916. {
  917. SET_BIT(I2Cx->CR1, I2C_CR1_PECEN);
  918. }
  919. /**
  920. * @brief Disable SMBus Packet Error Calculation (PEC).
  921. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  922. * SMBus feature is supported by the I2Cx Instance.
  923. * @rmtoll CR1 PECEN LL_I2C_DisableSMBusPEC
  924. * @param I2Cx I2C Instance.
  925. * @retval None
  926. */
  927. __STATIC_INLINE void LL_I2C_DisableSMBusPEC(I2C_TypeDef *I2Cx)
  928. {
  929. CLEAR_BIT(I2Cx->CR1, I2C_CR1_PECEN);
  930. }
  931. /**
  932. * @brief Check if SMBus Packet Error Calculation (PEC) is enabled or disabled.
  933. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  934. * SMBus feature is supported by the I2Cx Instance.
  935. * @rmtoll CR1 PECEN LL_I2C_IsEnabledSMBusPEC
  936. * @param I2Cx I2C Instance.
  937. * @retval State of bit (1 or 0).
  938. */
  939. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusPEC(I2C_TypeDef *I2Cx)
  940. {
  941. return (READ_BIT(I2Cx->CR1, I2C_CR1_PECEN) == (I2C_CR1_PECEN));
  942. }
  943. /**
  944. * @brief Configure the SMBus Clock Timeout.
  945. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  946. * SMBus feature is supported by the I2Cx Instance.
  947. * @note This configuration can only be programmed when associated Timeout is disabled (TimeoutA and/orTimeoutB).
  948. * @rmtoll TIMEOUTR TIMEOUTA LL_I2C_ConfigSMBusTimeout\n
  949. * TIMEOUTR TIDLE LL_I2C_ConfigSMBusTimeout\n
  950. * TIMEOUTR TIMEOUTB LL_I2C_ConfigSMBusTimeout
  951. * @param I2Cx I2C Instance.
  952. * @param TimeoutA This parameter must be a value between Min_Data=0 and Max_Data=0xFFF.
  953. * @param TimeoutAMode This parameter can be one of the following values:
  954. * @arg @ref LL_I2C_SMBUS_TIMEOUTA_MODE_SCL_LOW
  955. * @arg @ref LL_I2C_SMBUS_TIMEOUTA_MODE_SDA_SCL_HIGH
  956. * @param TimeoutB
  957. * @retval None
  958. */
  959. __STATIC_INLINE void LL_I2C_ConfigSMBusTimeout(I2C_TypeDef *I2Cx, uint32_t TimeoutA, uint32_t TimeoutAMode,
  960. uint32_t TimeoutB)
  961. {
  962. MODIFY_REG(I2Cx->TIMEOUTR, I2C_TIMEOUTR_TIMEOUTA | I2C_TIMEOUTR_TIDLE | I2C_TIMEOUTR_TIMEOUTB,
  963. TimeoutA | TimeoutAMode | (TimeoutB << I2C_TIMEOUTR_TIMEOUTB_Pos));
  964. }
  965. /**
  966. * @brief Configure the SMBus Clock TimeoutA (SCL low timeout or SCL and SDA high timeout depends on TimeoutA mode).
  967. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  968. * SMBus feature is supported by the I2Cx Instance.
  969. * @note These bits can only be programmed when TimeoutA is disabled.
  970. * @rmtoll TIMEOUTR TIMEOUTA LL_I2C_SetSMBusTimeoutA
  971. * @param I2Cx I2C Instance.
  972. * @param TimeoutA This parameter must be a value between Min_Data=0 and Max_Data=0xFFF.
  973. * @retval None
  974. */
  975. __STATIC_INLINE void LL_I2C_SetSMBusTimeoutA(I2C_TypeDef *I2Cx, uint32_t TimeoutA)
  976. {
  977. WRITE_REG(I2Cx->TIMEOUTR, TimeoutA);
  978. }
  979. /**
  980. * @brief Get the SMBus Clock TimeoutA setting.
  981. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  982. * SMBus feature is supported by the I2Cx Instance.
  983. * @rmtoll TIMEOUTR TIMEOUTA LL_I2C_GetSMBusTimeoutA
  984. * @param I2Cx I2C Instance.
  985. * @retval Value between Min_Data=0 and Max_Data=0xFFF
  986. */
  987. __STATIC_INLINE uint32_t LL_I2C_GetSMBusTimeoutA(I2C_TypeDef *I2Cx)
  988. {
  989. return (uint32_t)(READ_BIT(I2Cx->TIMEOUTR, I2C_TIMEOUTR_TIMEOUTA));
  990. }
  991. /**
  992. * @brief Set the SMBus Clock TimeoutA mode.
  993. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  994. * SMBus feature is supported by the I2Cx Instance.
  995. * @note This bit can only be programmed when TimeoutA is disabled.
  996. * @rmtoll TIMEOUTR TIDLE LL_I2C_SetSMBusTimeoutAMode
  997. * @param I2Cx I2C Instance.
  998. * @param TimeoutAMode This parameter can be one of the following values:
  999. * @arg @ref LL_I2C_SMBUS_TIMEOUTA_MODE_SCL_LOW
  1000. * @arg @ref LL_I2C_SMBUS_TIMEOUTA_MODE_SDA_SCL_HIGH
  1001. * @retval None
  1002. */
  1003. __STATIC_INLINE void LL_I2C_SetSMBusTimeoutAMode(I2C_TypeDef *I2Cx, uint32_t TimeoutAMode)
  1004. {
  1005. WRITE_REG(I2Cx->TIMEOUTR, TimeoutAMode);
  1006. }
  1007. /**
  1008. * @brief Get the SMBus Clock TimeoutA mode.
  1009. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1010. * SMBus feature is supported by the I2Cx Instance.
  1011. * @rmtoll TIMEOUTR TIDLE LL_I2C_GetSMBusTimeoutAMode
  1012. * @param I2Cx I2C Instance.
  1013. * @retval Returned value can be one of the following values:
  1014. * @arg @ref LL_I2C_SMBUS_TIMEOUTA_MODE_SCL_LOW
  1015. * @arg @ref LL_I2C_SMBUS_TIMEOUTA_MODE_SDA_SCL_HIGH
  1016. */
  1017. __STATIC_INLINE uint32_t LL_I2C_GetSMBusTimeoutAMode(I2C_TypeDef *I2Cx)
  1018. {
  1019. return (uint32_t)(READ_BIT(I2Cx->TIMEOUTR, I2C_TIMEOUTR_TIDLE));
  1020. }
  1021. /**
  1022. * @brief Configure the SMBus Extended Cumulative Clock TimeoutB (Master or Slave mode).
  1023. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1024. * SMBus feature is supported by the I2Cx Instance.
  1025. * @note These bits can only be programmed when TimeoutB is disabled.
  1026. * @rmtoll TIMEOUTR TIMEOUTB LL_I2C_SetSMBusTimeoutB
  1027. * @param I2Cx I2C Instance.
  1028. * @param TimeoutB This parameter must be a value between Min_Data=0 and Max_Data=0xFFF.
  1029. * @retval None
  1030. */
  1031. __STATIC_INLINE void LL_I2C_SetSMBusTimeoutB(I2C_TypeDef *I2Cx, uint32_t TimeoutB)
  1032. {
  1033. WRITE_REG(I2Cx->TIMEOUTR, TimeoutB << I2C_TIMEOUTR_TIMEOUTB_Pos);
  1034. }
  1035. /**
  1036. * @brief Get the SMBus Extented Cumulative Clock TimeoutB setting.
  1037. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1038. * SMBus feature is supported by the I2Cx Instance.
  1039. * @rmtoll TIMEOUTR TIMEOUTB LL_I2C_GetSMBusTimeoutB
  1040. * @param I2Cx I2C Instance.
  1041. * @retval Value between Min_Data=0 and Max_Data=0xFFF
  1042. */
  1043. __STATIC_INLINE uint32_t LL_I2C_GetSMBusTimeoutB(I2C_TypeDef *I2Cx)
  1044. {
  1045. return (uint32_t)(READ_BIT(I2Cx->TIMEOUTR, I2C_TIMEOUTR_TIMEOUTB) >> I2C_TIMEOUTR_TIMEOUTB_Pos);
  1046. }
  1047. /**
  1048. * @brief Enable the SMBus Clock Timeout.
  1049. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1050. * SMBus feature is supported by the I2Cx Instance.
  1051. * @rmtoll TIMEOUTR TIMOUTEN LL_I2C_EnableSMBusTimeout\n
  1052. * TIMEOUTR TEXTEN LL_I2C_EnableSMBusTimeout
  1053. * @param I2Cx I2C Instance.
  1054. * @param ClockTimeout This parameter can be one of the following values:
  1055. * @arg @ref LL_I2C_SMBUS_TIMEOUTA
  1056. * @arg @ref LL_I2C_SMBUS_TIMEOUTB
  1057. * @arg @ref LL_I2C_SMBUS_ALL_TIMEOUT
  1058. * @retval None
  1059. */
  1060. __STATIC_INLINE void LL_I2C_EnableSMBusTimeout(I2C_TypeDef *I2Cx, uint32_t ClockTimeout)
  1061. {
  1062. SET_BIT(I2Cx->TIMEOUTR, ClockTimeout);
  1063. }
  1064. /**
  1065. * @brief Disable the SMBus Clock Timeout.
  1066. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1067. * SMBus feature is supported by the I2Cx Instance.
  1068. * @rmtoll TIMEOUTR TIMOUTEN LL_I2C_DisableSMBusTimeout\n
  1069. * TIMEOUTR TEXTEN LL_I2C_DisableSMBusTimeout
  1070. * @param I2Cx I2C Instance.
  1071. * @param ClockTimeout This parameter can be one of the following values:
  1072. * @arg @ref LL_I2C_SMBUS_TIMEOUTA
  1073. * @arg @ref LL_I2C_SMBUS_TIMEOUTB
  1074. * @arg @ref LL_I2C_SMBUS_ALL_TIMEOUT
  1075. * @retval None
  1076. */
  1077. __STATIC_INLINE void LL_I2C_DisableSMBusTimeout(I2C_TypeDef *I2Cx, uint32_t ClockTimeout)
  1078. {
  1079. CLEAR_BIT(I2Cx->TIMEOUTR, ClockTimeout);
  1080. }
  1081. /**
  1082. * @brief Check if the SMBus Clock Timeout is enabled or disabled.
  1083. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1084. * SMBus feature is supported by the I2Cx Instance.
  1085. * @rmtoll TIMEOUTR TIMOUTEN LL_I2C_IsEnabledSMBusTimeout\n
  1086. * TIMEOUTR TEXTEN LL_I2C_IsEnabledSMBusTimeout
  1087. * @param I2Cx I2C Instance.
  1088. * @param ClockTimeout This parameter can be one of the following values:
  1089. * @arg @ref LL_I2C_SMBUS_TIMEOUTA
  1090. * @arg @ref LL_I2C_SMBUS_TIMEOUTB
  1091. * @arg @ref LL_I2C_SMBUS_ALL_TIMEOUT
  1092. * @retval State of bit (1 or 0).
  1093. */
  1094. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusTimeout(I2C_TypeDef *I2Cx, uint32_t ClockTimeout)
  1095. {
  1096. return (READ_BIT(I2Cx->TIMEOUTR, (I2C_TIMEOUTR_TIMOUTEN | I2C_TIMEOUTR_TEXTEN)) == (ClockTimeout));
  1097. }
  1098. /**
  1099. * @}
  1100. */
  1101. /** @defgroup I2C_LL_EF_IT_Management IT_Management
  1102. * @{
  1103. */
  1104. /**
  1105. * @brief Enable TXIS interrupt.
  1106. * @rmtoll CR1 TXIE LL_I2C_EnableIT_TX
  1107. * @param I2Cx I2C Instance.
  1108. * @retval None
  1109. */
  1110. __STATIC_INLINE void LL_I2C_EnableIT_TX(I2C_TypeDef *I2Cx)
  1111. {
  1112. SET_BIT(I2Cx->CR1, I2C_CR1_TXIE);
  1113. }
  1114. /**
  1115. * @brief Disable TXIS interrupt.
  1116. * @rmtoll CR1 TXIE LL_I2C_DisableIT_TX
  1117. * @param I2Cx I2C Instance.
  1118. * @retval None
  1119. */
  1120. __STATIC_INLINE void LL_I2C_DisableIT_TX(I2C_TypeDef *I2Cx)
  1121. {
  1122. CLEAR_BIT(I2Cx->CR1, I2C_CR1_TXIE);
  1123. }
  1124. /**
  1125. * @brief Check if the TXIS Interrupt is enabled or disabled.
  1126. * @rmtoll CR1 TXIE LL_I2C_IsEnabledIT_TX
  1127. * @param I2Cx I2C Instance.
  1128. * @retval State of bit (1 or 0).
  1129. */
  1130. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_TX(I2C_TypeDef *I2Cx)
  1131. {
  1132. return (READ_BIT(I2Cx->CR1, I2C_CR1_TXIE) == (I2C_CR1_TXIE));
  1133. }
  1134. /**
  1135. * @brief Enable RXNE interrupt.
  1136. * @rmtoll CR1 RXIE LL_I2C_EnableIT_RX
  1137. * @param I2Cx I2C Instance.
  1138. * @retval None
  1139. */
  1140. __STATIC_INLINE void LL_I2C_EnableIT_RX(I2C_TypeDef *I2Cx)
  1141. {
  1142. SET_BIT(I2Cx->CR1, I2C_CR1_RXIE);
  1143. }
  1144. /**
  1145. * @brief Disable RXNE interrupt.
  1146. * @rmtoll CR1 RXIE LL_I2C_DisableIT_RX
  1147. * @param I2Cx I2C Instance.
  1148. * @retval None
  1149. */
  1150. __STATIC_INLINE void LL_I2C_DisableIT_RX(I2C_TypeDef *I2Cx)
  1151. {
  1152. CLEAR_BIT(I2Cx->CR1, I2C_CR1_RXIE);
  1153. }
  1154. /**
  1155. * @brief Check if the RXNE Interrupt is enabled or disabled.
  1156. * @rmtoll CR1 RXIE LL_I2C_IsEnabledIT_RX
  1157. * @param I2Cx I2C Instance.
  1158. * @retval State of bit (1 or 0).
  1159. */
  1160. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_RX(I2C_TypeDef *I2Cx)
  1161. {
  1162. return (READ_BIT(I2Cx->CR1, I2C_CR1_RXIE) == (I2C_CR1_RXIE));
  1163. }
  1164. /**
  1165. * @brief Enable Address match interrupt (slave mode only).
  1166. * @rmtoll CR1 ADDRIE LL_I2C_EnableIT_ADDR
  1167. * @param I2Cx I2C Instance.
  1168. * @retval None
  1169. */
  1170. __STATIC_INLINE void LL_I2C_EnableIT_ADDR(I2C_TypeDef *I2Cx)
  1171. {
  1172. SET_BIT(I2Cx->CR1, I2C_CR1_ADDRIE);
  1173. }
  1174. /**
  1175. * @brief Disable Address match interrupt (slave mode only).
  1176. * @rmtoll CR1 ADDRIE LL_I2C_DisableIT_ADDR
  1177. * @param I2Cx I2C Instance.
  1178. * @retval None
  1179. */
  1180. __STATIC_INLINE void LL_I2C_DisableIT_ADDR(I2C_TypeDef *I2Cx)
  1181. {
  1182. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ADDRIE);
  1183. }
  1184. /**
  1185. * @brief Check if Address match interrupt is enabled or disabled.
  1186. * @rmtoll CR1 ADDRIE LL_I2C_IsEnabledIT_ADDR
  1187. * @param I2Cx I2C Instance.
  1188. * @retval State of bit (1 or 0).
  1189. */
  1190. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_ADDR(I2C_TypeDef *I2Cx)
  1191. {
  1192. return (READ_BIT(I2Cx->CR1, I2C_CR1_ADDRIE) == (I2C_CR1_ADDRIE));
  1193. }
  1194. /**
  1195. * @brief Enable Not acknowledge received interrupt.
  1196. * @rmtoll CR1 NACKIE LL_I2C_EnableIT_NACK
  1197. * @param I2Cx I2C Instance.
  1198. * @retval None
  1199. */
  1200. __STATIC_INLINE void LL_I2C_EnableIT_NACK(I2C_TypeDef *I2Cx)
  1201. {
  1202. SET_BIT(I2Cx->CR1, I2C_CR1_NACKIE);
  1203. }
  1204. /**
  1205. * @brief Disable Not acknowledge received interrupt.
  1206. * @rmtoll CR1 NACKIE LL_I2C_DisableIT_NACK
  1207. * @param I2Cx I2C Instance.
  1208. * @retval None
  1209. */
  1210. __STATIC_INLINE void LL_I2C_DisableIT_NACK(I2C_TypeDef *I2Cx)
  1211. {
  1212. CLEAR_BIT(I2Cx->CR1, I2C_CR1_NACKIE);
  1213. }
  1214. /**
  1215. * @brief Check if Not acknowledge received interrupt is enabled or disabled.
  1216. * @rmtoll CR1 NACKIE LL_I2C_IsEnabledIT_NACK
  1217. * @param I2Cx I2C Instance.
  1218. * @retval State of bit (1 or 0).
  1219. */
  1220. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_NACK(I2C_TypeDef *I2Cx)
  1221. {
  1222. return (READ_BIT(I2Cx->CR1, I2C_CR1_NACKIE) == (I2C_CR1_NACKIE));
  1223. }
  1224. /**
  1225. * @brief Enable STOP detection interrupt.
  1226. * @rmtoll CR1 STOPIE LL_I2C_EnableIT_STOP
  1227. * @param I2Cx I2C Instance.
  1228. * @retval None
  1229. */
  1230. __STATIC_INLINE void LL_I2C_EnableIT_STOP(I2C_TypeDef *I2Cx)
  1231. {
  1232. SET_BIT(I2Cx->CR1, I2C_CR1_STOPIE);
  1233. }
  1234. /**
  1235. * @brief Disable STOP detection interrupt.
  1236. * @rmtoll CR1 STOPIE LL_I2C_DisableIT_STOP
  1237. * @param I2Cx I2C Instance.
  1238. * @retval None
  1239. */
  1240. __STATIC_INLINE void LL_I2C_DisableIT_STOP(I2C_TypeDef *I2Cx)
  1241. {
  1242. CLEAR_BIT(I2Cx->CR1, I2C_CR1_STOPIE);
  1243. }
  1244. /**
  1245. * @brief Check if STOP detection interrupt is enabled or disabled.
  1246. * @rmtoll CR1 STOPIE LL_I2C_IsEnabledIT_STOP
  1247. * @param I2Cx I2C Instance.
  1248. * @retval State of bit (1 or 0).
  1249. */
  1250. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_STOP(I2C_TypeDef *I2Cx)
  1251. {
  1252. return (READ_BIT(I2Cx->CR1, I2C_CR1_STOPIE) == (I2C_CR1_STOPIE));
  1253. }
  1254. /**
  1255. * @brief Enable Transfer Complete interrupt.
  1256. * @note Any of these events will generate interrupt :
  1257. * Transfer Complete (TC)
  1258. * Transfer Complete Reload (TCR)
  1259. * @rmtoll CR1 TCIE LL_I2C_EnableIT_TC
  1260. * @param I2Cx I2C Instance.
  1261. * @retval None
  1262. */
  1263. __STATIC_INLINE void LL_I2C_EnableIT_TC(I2C_TypeDef *I2Cx)
  1264. {
  1265. SET_BIT(I2Cx->CR1, I2C_CR1_TCIE);
  1266. }
  1267. /**
  1268. * @brief Disable Transfer Complete interrupt.
  1269. * @note Any of these events will generate interrupt :
  1270. * Transfer Complete (TC)
  1271. * Transfer Complete Reload (TCR)
  1272. * @rmtoll CR1 TCIE LL_I2C_DisableIT_TC
  1273. * @param I2Cx I2C Instance.
  1274. * @retval None
  1275. */
  1276. __STATIC_INLINE void LL_I2C_DisableIT_TC(I2C_TypeDef *I2Cx)
  1277. {
  1278. CLEAR_BIT(I2Cx->CR1, I2C_CR1_TCIE);
  1279. }
  1280. /**
  1281. * @brief Check if Transfer Complete interrupt is enabled or disabled.
  1282. * @rmtoll CR1 TCIE LL_I2C_IsEnabledIT_TC
  1283. * @param I2Cx I2C Instance.
  1284. * @retval State of bit (1 or 0).
  1285. */
  1286. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_TC(I2C_TypeDef *I2Cx)
  1287. {
  1288. return (READ_BIT(I2Cx->CR1, I2C_CR1_TCIE) == (I2C_CR1_TCIE));
  1289. }
  1290. /**
  1291. * @brief Enable Error interrupts.
  1292. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1293. * SMBus feature is supported by the I2Cx Instance.
  1294. * @note Any of these errors will generate interrupt :
  1295. * Arbitration Loss (ARLO)
  1296. * Bus Error detection (BERR)
  1297. * Overrun/Underrun (OVR)
  1298. * SMBus Timeout detection (TIMEOUT)
  1299. * SMBus PEC error detection (PECERR)
  1300. * SMBus Alert pin event detection (ALERT)
  1301. * @rmtoll CR1 ERRIE LL_I2C_EnableIT_ERR
  1302. * @param I2Cx I2C Instance.
  1303. * @retval None
  1304. */
  1305. __STATIC_INLINE void LL_I2C_EnableIT_ERR(I2C_TypeDef *I2Cx)
  1306. {
  1307. SET_BIT(I2Cx->CR1, I2C_CR1_ERRIE);
  1308. }
  1309. /**
  1310. * @brief Disable Error interrupts.
  1311. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1312. * SMBus feature is supported by the I2Cx Instance.
  1313. * @note Any of these errors will generate interrupt :
  1314. * Arbitration Loss (ARLO)
  1315. * Bus Error detection (BERR)
  1316. * Overrun/Underrun (OVR)
  1317. * SMBus Timeout detection (TIMEOUT)
  1318. * SMBus PEC error detection (PECERR)
  1319. * SMBus Alert pin event detection (ALERT)
  1320. * @rmtoll CR1 ERRIE LL_I2C_DisableIT_ERR
  1321. * @param I2Cx I2C Instance.
  1322. * @retval None
  1323. */
  1324. __STATIC_INLINE void LL_I2C_DisableIT_ERR(I2C_TypeDef *I2Cx)
  1325. {
  1326. CLEAR_BIT(I2Cx->CR1, I2C_CR1_ERRIE);
  1327. }
  1328. /**
  1329. * @brief Check if Error interrupts are enabled or disabled.
  1330. * @rmtoll CR1 ERRIE LL_I2C_IsEnabledIT_ERR
  1331. * @param I2Cx I2C Instance.
  1332. * @retval State of bit (1 or 0).
  1333. */
  1334. __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_ERR(I2C_TypeDef *I2Cx)
  1335. {
  1336. return (READ_BIT(I2Cx->CR1, I2C_CR1_ERRIE) == (I2C_CR1_ERRIE));
  1337. }
  1338. /**
  1339. * @}
  1340. */
  1341. /** @defgroup I2C_LL_EF_FLAG_management FLAG_management
  1342. * @{
  1343. */
  1344. /**
  1345. * @brief Indicate the status of Transmit data register empty flag.
  1346. * @note RESET: When next data is written in Transmit data register.
  1347. * SET: When Transmit data register is empty.
  1348. * @rmtoll ISR TXE LL_I2C_IsActiveFlag_TXE
  1349. * @param I2Cx I2C Instance.
  1350. * @retval State of bit (1 or 0).
  1351. */
  1352. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_TXE(I2C_TypeDef *I2Cx)
  1353. {
  1354. return (READ_BIT(I2Cx->ISR, I2C_ISR_TXE) == (I2C_ISR_TXE));
  1355. }
  1356. /**
  1357. * @brief Indicate the status of Transmit interrupt flag.
  1358. * @note RESET: When next data is written in Transmit data register.
  1359. * SET: When Transmit data register is empty.
  1360. * @rmtoll ISR TXIS LL_I2C_IsActiveFlag_TXIS
  1361. * @param I2Cx I2C Instance.
  1362. * @retval State of bit (1 or 0).
  1363. */
  1364. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_TXIS(I2C_TypeDef *I2Cx)
  1365. {
  1366. return (READ_BIT(I2Cx->ISR, I2C_ISR_TXIS) == (I2C_ISR_TXIS));
  1367. }
  1368. /**
  1369. * @brief Indicate the status of Receive data register not empty flag.
  1370. * @note RESET: When Receive data register is read.
  1371. * SET: When the received data is copied in Receive data register.
  1372. * @rmtoll ISR RXNE LL_I2C_IsActiveFlag_RXNE
  1373. * @param I2Cx I2C Instance.
  1374. * @retval State of bit (1 or 0).
  1375. */
  1376. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_RXNE(I2C_TypeDef *I2Cx)
  1377. {
  1378. return (READ_BIT(I2Cx->ISR, I2C_ISR_RXNE) == (I2C_ISR_RXNE));
  1379. }
  1380. /**
  1381. * @brief Indicate the status of Address matched flag (slave mode).
  1382. * @note RESET: Clear default value.
  1383. * SET: When the received slave address matched with one of the enabled slave address.
  1384. * @rmtoll ISR ADDR LL_I2C_IsActiveFlag_ADDR
  1385. * @param I2Cx I2C Instance.
  1386. * @retval State of bit (1 or 0).
  1387. */
  1388. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ADDR(I2C_TypeDef *I2Cx)
  1389. {
  1390. return (READ_BIT(I2Cx->ISR, I2C_ISR_ADDR) == (I2C_ISR_ADDR));
  1391. }
  1392. /**
  1393. * @brief Indicate the status of Not Acknowledge received flag.
  1394. * @note RESET: Clear default value.
  1395. * SET: When a NACK is received after a byte transmission.
  1396. * @rmtoll ISR NACKF LL_I2C_IsActiveFlag_NACK
  1397. * @param I2Cx I2C Instance.
  1398. * @retval State of bit (1 or 0).
  1399. */
  1400. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_NACK(I2C_TypeDef *I2Cx)
  1401. {
  1402. return (READ_BIT(I2Cx->ISR, I2C_ISR_NACKF) == (I2C_ISR_NACKF));
  1403. }
  1404. /**
  1405. * @brief Indicate the status of Stop detection flag.
  1406. * @note RESET: Clear default value.
  1407. * SET: When a Stop condition is detected.
  1408. * @rmtoll ISR STOPF LL_I2C_IsActiveFlag_STOP
  1409. * @param I2Cx I2C Instance.
  1410. * @retval State of bit (1 or 0).
  1411. */
  1412. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_STOP(I2C_TypeDef *I2Cx)
  1413. {
  1414. return (READ_BIT(I2Cx->ISR, I2C_ISR_STOPF) == (I2C_ISR_STOPF));
  1415. }
  1416. /**
  1417. * @brief Indicate the status of Transfer complete flag (master mode).
  1418. * @note RESET: Clear default value.
  1419. * SET: When RELOAD=0, AUTOEND=0 and NBYTES date have been transferred.
  1420. * @rmtoll ISR TC LL_I2C_IsActiveFlag_TC
  1421. * @param I2Cx I2C Instance.
  1422. * @retval State of bit (1 or 0).
  1423. */
  1424. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_TC(I2C_TypeDef *I2Cx)
  1425. {
  1426. return (READ_BIT(I2Cx->ISR, I2C_ISR_TC) == (I2C_ISR_TC));
  1427. }
  1428. /**
  1429. * @brief Indicate the status of Transfer complete flag (master mode).
  1430. * @note RESET: Clear default value.
  1431. * SET: When RELOAD=1 and NBYTES date have been transferred.
  1432. * @rmtoll ISR TCR LL_I2C_IsActiveFlag_TCR
  1433. * @param I2Cx I2C Instance.
  1434. * @retval State of bit (1 or 0).
  1435. */
  1436. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_TCR(I2C_TypeDef *I2Cx)
  1437. {
  1438. return (READ_BIT(I2Cx->ISR, I2C_ISR_TCR) == (I2C_ISR_TCR));
  1439. }
  1440. /**
  1441. * @brief Indicate the status of Bus error flag.
  1442. * @note RESET: Clear default value.
  1443. * SET: When a misplaced Start or Stop condition is detected.
  1444. * @rmtoll ISR BERR LL_I2C_IsActiveFlag_BERR
  1445. * @param I2Cx I2C Instance.
  1446. * @retval State of bit (1 or 0).
  1447. */
  1448. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BERR(I2C_TypeDef *I2Cx)
  1449. {
  1450. return (READ_BIT(I2Cx->ISR, I2C_ISR_BERR) == (I2C_ISR_BERR));
  1451. }
  1452. /**
  1453. * @brief Indicate the status of Arbitration lost flag.
  1454. * @note RESET: Clear default value.
  1455. * SET: When arbitration lost.
  1456. * @rmtoll ISR ARLO LL_I2C_IsActiveFlag_ARLO
  1457. * @param I2Cx I2C Instance.
  1458. * @retval State of bit (1 or 0).
  1459. */
  1460. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ARLO(I2C_TypeDef *I2Cx)
  1461. {
  1462. return (READ_BIT(I2Cx->ISR, I2C_ISR_ARLO) == (I2C_ISR_ARLO));
  1463. }
  1464. /**
  1465. * @brief Indicate the status of Overrun/Underrun flag (slave mode).
  1466. * @note RESET: Clear default value.
  1467. * SET: When an overrun/underrun error occurs (Clock Stretching Disabled).
  1468. * @rmtoll ISR OVR LL_I2C_IsActiveFlag_OVR
  1469. * @param I2Cx I2C Instance.
  1470. * @retval State of bit (1 or 0).
  1471. */
  1472. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_OVR(I2C_TypeDef *I2Cx)
  1473. {
  1474. return (READ_BIT(I2Cx->ISR, I2C_ISR_OVR) == (I2C_ISR_OVR));
  1475. }
  1476. /**
  1477. * @brief Indicate the status of SMBus PEC error flag in reception.
  1478. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1479. * SMBus feature is supported by the I2Cx Instance.
  1480. * @note RESET: Clear default value.
  1481. * SET: When the received PEC does not match with the PEC register content.
  1482. * @rmtoll ISR PECERR LL_I2C_IsActiveSMBusFlag_PECERR
  1483. * @param I2Cx I2C Instance.
  1484. * @retval State of bit (1 or 0).
  1485. */
  1486. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_PECERR(I2C_TypeDef *I2Cx)
  1487. {
  1488. return (READ_BIT(I2Cx->ISR, I2C_ISR_PECERR) == (I2C_ISR_PECERR));
  1489. }
  1490. /**
  1491. * @brief Indicate the status of SMBus Timeout detection flag.
  1492. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1493. * SMBus feature is supported by the I2Cx Instance.
  1494. * @note RESET: Clear default value.
  1495. * SET: When a timeout or extended clock timeout occurs.
  1496. * @rmtoll ISR TIMEOUT LL_I2C_IsActiveSMBusFlag_TIMEOUT
  1497. * @param I2Cx I2C Instance.
  1498. * @retval State of bit (1 or 0).
  1499. */
  1500. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_TIMEOUT(I2C_TypeDef *I2Cx)
  1501. {
  1502. return (READ_BIT(I2Cx->ISR, I2C_ISR_TIMEOUT) == (I2C_ISR_TIMEOUT));
  1503. }
  1504. /**
  1505. * @brief Indicate the status of SMBus alert flag.
  1506. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1507. * SMBus feature is supported by the I2Cx Instance.
  1508. * @note RESET: Clear default value.
  1509. * SET: When SMBus host configuration, SMBus alert enabled and
  1510. * a falling edge event occurs on SMBA pin.
  1511. * @rmtoll ISR ALERT LL_I2C_IsActiveSMBusFlag_ALERT
  1512. * @param I2Cx I2C Instance.
  1513. * @retval State of bit (1 or 0).
  1514. */
  1515. __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_ALERT(I2C_TypeDef *I2Cx)
  1516. {
  1517. return (READ_BIT(I2Cx->ISR, I2C_ISR_ALERT) == (I2C_ISR_ALERT));
  1518. }
  1519. /**
  1520. * @brief Indicate the status of Bus Busy flag.
  1521. * @note RESET: Clear default value.
  1522. * SET: When a Start condition is detected.
  1523. * @rmtoll ISR BUSY LL_I2C_IsActiveFlag_BUSY
  1524. * @param I2Cx I2C Instance.
  1525. * @retval State of bit (1 or 0).
  1526. */
  1527. __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BUSY(I2C_TypeDef *I2Cx)
  1528. {
  1529. return (READ_BIT(I2Cx->ISR, I2C_ISR_BUSY) == (I2C_ISR_BUSY));
  1530. }
  1531. /**
  1532. * @brief Clear Address Matched flag.
  1533. * @rmtoll ICR ADDRCF LL_I2C_ClearFlag_ADDR
  1534. * @param I2Cx I2C Instance.
  1535. * @retval None
  1536. */
  1537. __STATIC_INLINE void LL_I2C_ClearFlag_ADDR(I2C_TypeDef *I2Cx)
  1538. {
  1539. SET_BIT(I2Cx->ICR, I2C_ICR_ADDRCF);
  1540. }
  1541. /**
  1542. * @brief Clear Not Acknowledge flag.
  1543. * @rmtoll ICR NACKCF LL_I2C_ClearFlag_NACK
  1544. * @param I2Cx I2C Instance.
  1545. * @retval None
  1546. */
  1547. __STATIC_INLINE void LL_I2C_ClearFlag_NACK(I2C_TypeDef *I2Cx)
  1548. {
  1549. SET_BIT(I2Cx->ICR, I2C_ICR_NACKCF);
  1550. }
  1551. /**
  1552. * @brief Clear Stop detection flag.
  1553. * @rmtoll ICR STOPCF LL_I2C_ClearFlag_STOP
  1554. * @param I2Cx I2C Instance.
  1555. * @retval None
  1556. */
  1557. __STATIC_INLINE void LL_I2C_ClearFlag_STOP(I2C_TypeDef *I2Cx)
  1558. {
  1559. SET_BIT(I2Cx->ICR, I2C_ICR_STOPCF);
  1560. }
  1561. /**
  1562. * @brief Clear Transmit data register empty flag (TXE).
  1563. * @note This bit can be clear by software in order to flush the transmit data register (TXDR).
  1564. * @rmtoll ISR TXE LL_I2C_ClearFlag_TXE
  1565. * @param I2Cx I2C Instance.
  1566. * @retval None
  1567. */
  1568. __STATIC_INLINE void LL_I2C_ClearFlag_TXE(I2C_TypeDef *I2Cx)
  1569. {
  1570. WRITE_REG(I2Cx->ISR, I2C_ISR_TXE);
  1571. }
  1572. /**
  1573. * @brief Clear Bus error flag.
  1574. * @rmtoll ICR BERRCF LL_I2C_ClearFlag_BERR
  1575. * @param I2Cx I2C Instance.
  1576. * @retval None
  1577. */
  1578. __STATIC_INLINE void LL_I2C_ClearFlag_BERR(I2C_TypeDef *I2Cx)
  1579. {
  1580. SET_BIT(I2Cx->ICR, I2C_ICR_BERRCF);
  1581. }
  1582. /**
  1583. * @brief Clear Arbitration lost flag.
  1584. * @rmtoll ICR ARLOCF LL_I2C_ClearFlag_ARLO
  1585. * @param I2Cx I2C Instance.
  1586. * @retval None
  1587. */
  1588. __STATIC_INLINE void LL_I2C_ClearFlag_ARLO(I2C_TypeDef *I2Cx)
  1589. {
  1590. SET_BIT(I2Cx->ICR, I2C_ICR_ARLOCF);
  1591. }
  1592. /**
  1593. * @brief Clear Overrun/Underrun flag.
  1594. * @rmtoll ICR OVRCF LL_I2C_ClearFlag_OVR
  1595. * @param I2Cx I2C Instance.
  1596. * @retval None
  1597. */
  1598. __STATIC_INLINE void LL_I2C_ClearFlag_OVR(I2C_TypeDef *I2Cx)
  1599. {
  1600. SET_BIT(I2Cx->ICR, I2C_ICR_OVRCF);
  1601. }
  1602. /**
  1603. * @brief Clear SMBus PEC error flag.
  1604. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1605. * SMBus feature is supported by the I2Cx Instance.
  1606. * @rmtoll ICR PECCF LL_I2C_ClearSMBusFlag_PECERR
  1607. * @param I2Cx I2C Instance.
  1608. * @retval None
  1609. */
  1610. __STATIC_INLINE void LL_I2C_ClearSMBusFlag_PECERR(I2C_TypeDef *I2Cx)
  1611. {
  1612. SET_BIT(I2Cx->ICR, I2C_ICR_PECCF);
  1613. }
  1614. /**
  1615. * @brief Clear SMBus Timeout detection flag.
  1616. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1617. * SMBus feature is supported by the I2Cx Instance.
  1618. * @rmtoll ICR TIMOUTCF LL_I2C_ClearSMBusFlag_TIMEOUT
  1619. * @param I2Cx I2C Instance.
  1620. * @retval None
  1621. */
  1622. __STATIC_INLINE void LL_I2C_ClearSMBusFlag_TIMEOUT(I2C_TypeDef *I2Cx)
  1623. {
  1624. SET_BIT(I2Cx->ICR, I2C_ICR_TIMOUTCF);
  1625. }
  1626. /**
  1627. * @brief Clear SMBus Alert flag.
  1628. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1629. * SMBus feature is supported by the I2Cx Instance.
  1630. * @rmtoll ICR ALERTCF LL_I2C_ClearSMBusFlag_ALERT
  1631. * @param I2Cx I2C Instance.
  1632. * @retval None
  1633. */
  1634. __STATIC_INLINE void LL_I2C_ClearSMBusFlag_ALERT(I2C_TypeDef *I2Cx)
  1635. {
  1636. SET_BIT(I2Cx->ICR, I2C_ICR_ALERTCF);
  1637. }
  1638. /**
  1639. * @}
  1640. */
  1641. /** @defgroup I2C_LL_EF_Data_Management Data_Management
  1642. * @{
  1643. */
  1644. /**
  1645. * @brief Enable automatic STOP condition generation (master mode).
  1646. * @note Automatic end mode : a STOP condition is automatically sent when NBYTES data are transferred.
  1647. * This bit has no effect in slave mode or when RELOAD bit is set.
  1648. * @rmtoll CR2 AUTOEND LL_I2C_EnableAutoEndMode
  1649. * @param I2Cx I2C Instance.
  1650. * @retval None
  1651. */
  1652. __STATIC_INLINE void LL_I2C_EnableAutoEndMode(I2C_TypeDef *I2Cx)
  1653. {
  1654. SET_BIT(I2Cx->CR2, I2C_CR2_AUTOEND);
  1655. }
  1656. /**
  1657. * @brief Disable automatic STOP condition generation (master mode).
  1658. * @note Software end mode : TC flag is set when NBYTES data are transferre, stretching SCL low.
  1659. * @rmtoll CR2 AUTOEND LL_I2C_DisableAutoEndMode
  1660. * @param I2Cx I2C Instance.
  1661. * @retval None
  1662. */
  1663. __STATIC_INLINE void LL_I2C_DisableAutoEndMode(I2C_TypeDef *I2Cx)
  1664. {
  1665. CLEAR_BIT(I2Cx->CR2, I2C_CR2_AUTOEND);
  1666. }
  1667. /**
  1668. * @brief Check if automatic STOP condition is enabled or disabled.
  1669. * @rmtoll CR2 AUTOEND LL_I2C_IsEnabledAutoEndMode
  1670. * @param I2Cx I2C Instance.
  1671. * @retval State of bit (1 or 0).
  1672. */
  1673. __STATIC_INLINE uint32_t LL_I2C_IsEnabledAutoEndMode(I2C_TypeDef *I2Cx)
  1674. {
  1675. return (READ_BIT(I2Cx->CR2, I2C_CR2_AUTOEND) == (I2C_CR2_AUTOEND));
  1676. }
  1677. /**
  1678. * @brief Enable reload mode (master mode).
  1679. * @note The transfer is not completed after the NBYTES data transfer, NBYTES will be reloaded when TCR flag is set.
  1680. * @rmtoll CR2 RELOAD LL_I2C_EnableReloadMode
  1681. * @param I2Cx I2C Instance.
  1682. * @retval None
  1683. */
  1684. __STATIC_INLINE void LL_I2C_EnableReloadMode(I2C_TypeDef *I2Cx)
  1685. {
  1686. SET_BIT(I2Cx->CR2, I2C_CR2_RELOAD);
  1687. }
  1688. /**
  1689. * @brief Disable reload mode (master mode).
  1690. * @note The transfer is completed after the NBYTES data transfer(STOP or RESTART will follow).
  1691. * @rmtoll CR2 RELOAD LL_I2C_DisableReloadMode
  1692. * @param I2Cx I2C Instance.
  1693. * @retval None
  1694. */
  1695. __STATIC_INLINE void LL_I2C_DisableReloadMode(I2C_TypeDef *I2Cx)
  1696. {
  1697. CLEAR_BIT(I2Cx->CR2, I2C_CR2_RELOAD);
  1698. }
  1699. /**
  1700. * @brief Check if reload mode is enabled or disabled.
  1701. * @rmtoll CR2 RELOAD LL_I2C_IsEnabledReloadMode
  1702. * @param I2Cx I2C Instance.
  1703. * @retval State of bit (1 or 0).
  1704. */
  1705. __STATIC_INLINE uint32_t LL_I2C_IsEnabledReloadMode(I2C_TypeDef *I2Cx)
  1706. {
  1707. return (READ_BIT(I2Cx->CR2, I2C_CR2_RELOAD) == (I2C_CR2_RELOAD));
  1708. }
  1709. /**
  1710. * @brief Configure the number of bytes for transfer.
  1711. * @note Changing these bits when START bit is set is not allowed.
  1712. * @rmtoll CR2 NBYTES LL_I2C_SetTransferSize
  1713. * @param I2Cx I2C Instance.
  1714. * @param TransferSize This parameter must be a value between Min_Data=0x00 and Max_Data=0xFF.
  1715. * @retval None
  1716. */
  1717. __STATIC_INLINE void LL_I2C_SetTransferSize(I2C_TypeDef *I2Cx, uint32_t TransferSize)
  1718. {
  1719. MODIFY_REG(I2Cx->CR2, I2C_CR2_NBYTES, TransferSize << I2C_CR2_NBYTES_Pos);
  1720. }
  1721. /**
  1722. * @brief Get the number of bytes configured for transfer.
  1723. * @rmtoll CR2 NBYTES LL_I2C_GetTransferSize
  1724. * @param I2Cx I2C Instance.
  1725. * @retval Value between Min_Data=0x0 and Max_Data=0xFF
  1726. */
  1727. __STATIC_INLINE uint32_t LL_I2C_GetTransferSize(I2C_TypeDef *I2Cx)
  1728. {
  1729. return (uint32_t)(READ_BIT(I2Cx->CR2, I2C_CR2_NBYTES) >> I2C_CR2_NBYTES_Pos);
  1730. }
  1731. /**
  1732. * @brief Prepare the generation of a ACKnowledge or Non ACKnowledge condition after the address receive match code or next received byte.
  1733. * @note Usage in Slave mode only.
  1734. * @rmtoll CR2 NACK LL_I2C_AcknowledgeNextData
  1735. * @param I2Cx I2C Instance.
  1736. * @param TypeAcknowledge This parameter can be one of the following values:
  1737. * @arg @ref LL_I2C_ACK
  1738. * @arg @ref LL_I2C_NACK
  1739. * @retval None
  1740. */
  1741. __STATIC_INLINE void LL_I2C_AcknowledgeNextData(I2C_TypeDef *I2Cx, uint32_t TypeAcknowledge)
  1742. {
  1743. MODIFY_REG(I2Cx->CR2, I2C_CR2_NACK, TypeAcknowledge);
  1744. }
  1745. /**
  1746. * @brief Generate a START or RESTART condition
  1747. * @note The START bit can be set even if bus is BUSY or I2C is in slave mode.
  1748. * This action has no effect when RELOAD is set.
  1749. * @rmtoll CR2 START LL_I2C_GenerateStartCondition
  1750. * @param I2Cx I2C Instance.
  1751. * @retval None
  1752. */
  1753. __STATIC_INLINE void LL_I2C_GenerateStartCondition(I2C_TypeDef *I2Cx)
  1754. {
  1755. SET_BIT(I2Cx->CR2, I2C_CR2_START);
  1756. }
  1757. /**
  1758. * @brief Generate a STOP condition after the current byte transfer (master mode).
  1759. * @rmtoll CR2 STOP LL_I2C_GenerateStopCondition
  1760. * @param I2Cx I2C Instance.
  1761. * @retval None
  1762. */
  1763. __STATIC_INLINE void LL_I2C_GenerateStopCondition(I2C_TypeDef *I2Cx)
  1764. {
  1765. SET_BIT(I2Cx->CR2, I2C_CR2_STOP);
  1766. }
  1767. /**
  1768. * @brief Enable automatic RESTART Read request condition for 10bit address header (master mode).
  1769. * @note The master sends the complete 10bit slave address read sequence :
  1770. * Start + 2 bytes 10bit address in Write direction + Restart + first 7 bits of 10bit address in Read direction.
  1771. * @rmtoll CR2 HEAD10R LL_I2C_EnableAuto10BitRead
  1772. * @param I2Cx I2C Instance.
  1773. * @retval None
  1774. */
  1775. __STATIC_INLINE void LL_I2C_EnableAuto10BitRead(I2C_TypeDef *I2Cx)
  1776. {
  1777. CLEAR_BIT(I2Cx->CR2, I2C_CR2_HEAD10R);
  1778. }
  1779. /**
  1780. * @brief Disable automatic RESTART Read request condition for 10bit address header (master mode).
  1781. * @note The master only sends the first 7 bits of 10bit address in Read direction.
  1782. * @rmtoll CR2 HEAD10R LL_I2C_DisableAuto10BitRead
  1783. * @param I2Cx I2C Instance.
  1784. * @retval None
  1785. */
  1786. __STATIC_INLINE void LL_I2C_DisableAuto10BitRead(I2C_TypeDef *I2Cx)
  1787. {
  1788. SET_BIT(I2Cx->CR2, I2C_CR2_HEAD10R);
  1789. }
  1790. /**
  1791. * @brief Check if automatic RESTART Read request condition for 10bit address header is enabled or disabled.
  1792. * @rmtoll CR2 HEAD10R LL_I2C_IsEnabledAuto10BitRead
  1793. * @param I2Cx I2C Instance.
  1794. * @retval State of bit (1 or 0).
  1795. */
  1796. __STATIC_INLINE uint32_t LL_I2C_IsEnabledAuto10BitRead(I2C_TypeDef *I2Cx)
  1797. {
  1798. return (READ_BIT(I2Cx->CR2, I2C_CR2_HEAD10R) != (I2C_CR2_HEAD10R));
  1799. }
  1800. /**
  1801. * @brief Configure the transfer direction (master mode).
  1802. * @note Changing these bits when START bit is set is not allowed.
  1803. * @rmtoll CR2 RD_WRN LL_I2C_SetTransferRequest
  1804. * @param I2Cx I2C Instance.
  1805. * @param TransferRequest This parameter can be one of the following values:
  1806. * @arg @ref LL_I2C_REQUEST_WRITE
  1807. * @arg @ref LL_I2C_REQUEST_READ
  1808. * @retval None
  1809. */
  1810. __STATIC_INLINE void LL_I2C_SetTransferRequest(I2C_TypeDef *I2Cx, uint32_t TransferRequest)
  1811. {
  1812. MODIFY_REG(I2Cx->CR2, I2C_CR2_RD_WRN, TransferRequest);
  1813. }
  1814. /**
  1815. * @brief Get the transfer direction requested (master mode).
  1816. * @rmtoll CR2 RD_WRN LL_I2C_GetTransferRequest
  1817. * @param I2Cx I2C Instance.
  1818. * @retval Returned value can be one of the following values:
  1819. * @arg @ref LL_I2C_REQUEST_WRITE
  1820. * @arg @ref LL_I2C_REQUEST_READ
  1821. */
  1822. __STATIC_INLINE uint32_t LL_I2C_GetTransferRequest(I2C_TypeDef *I2Cx)
  1823. {
  1824. return (uint32_t)(READ_BIT(I2Cx->CR2, I2C_CR2_RD_WRN));
  1825. }
  1826. /**
  1827. * @brief Configure the slave address for transfer (master mode).
  1828. * @note Changing these bits when START bit is set is not allowed.
  1829. * @rmtoll CR2 SADD LL_I2C_SetSlaveAddr
  1830. * @param I2Cx I2C Instance.
  1831. * @param SlaveAddr This parameter must be a value between Min_Data=0x00 and Max_Data=0x3F.
  1832. * @retval None
  1833. */
  1834. __STATIC_INLINE void LL_I2C_SetSlaveAddr(I2C_TypeDef *I2Cx, uint32_t SlaveAddr)
  1835. {
  1836. MODIFY_REG(I2Cx->CR2, I2C_CR2_SADD, SlaveAddr);
  1837. }
  1838. /**
  1839. * @brief Get the slave address programmed for transfer.
  1840. * @rmtoll CR2 SADD LL_I2C_GetSlaveAddr
  1841. * @param I2Cx I2C Instance.
  1842. * @retval Value between Min_Data=0x0 and Max_Data=0x3F
  1843. */
  1844. __STATIC_INLINE uint32_t LL_I2C_GetSlaveAddr(I2C_TypeDef *I2Cx)
  1845. {
  1846. return (uint32_t)(READ_BIT(I2Cx->CR2, I2C_CR2_SADD));
  1847. }
  1848. /**
  1849. * @brief Handles I2Cx communication when starting transfer or during transfer (TC or TCR flag are set).
  1850. * @rmtoll CR2 SADD LL_I2C_HandleTransfer\n
  1851. * CR2 ADD10 LL_I2C_HandleTransfer\n
  1852. * CR2 RD_WRN LL_I2C_HandleTransfer\n
  1853. * CR2 START LL_I2C_HandleTransfer\n
  1854. * CR2 STOP LL_I2C_HandleTransfer\n
  1855. * CR2 RELOAD LL_I2C_HandleTransfer\n
  1856. * CR2 NBYTES LL_I2C_HandleTransfer\n
  1857. * CR2 AUTOEND LL_I2C_HandleTransfer\n
  1858. * CR2 HEAD10R LL_I2C_HandleTransfer
  1859. * @param I2Cx I2C Instance.
  1860. * @param SlaveAddr Specifies the slave address to be programmed.
  1861. * @param SlaveAddrSize This parameter can be one of the following values:
  1862. * @arg @ref LL_I2C_ADDRSLAVE_7BIT
  1863. * @arg @ref LL_I2C_ADDRSLAVE_10BIT
  1864. * @param TransferSize Specifies the number of bytes to be programmed.
  1865. * This parameter must be a value between Min_Data=0 and Max_Data=255.
  1866. * @param EndMode This parameter can be one of the following values:
  1867. * @arg @ref LL_I2C_MODE_RELOAD
  1868. * @arg @ref LL_I2C_MODE_AUTOEND
  1869. * @arg @ref LL_I2C_MODE_SOFTEND
  1870. * @arg @ref LL_I2C_MODE_SMBUS_RELOAD
  1871. * @arg @ref LL_I2C_MODE_SMBUS_AUTOEND_NO_PEC
  1872. * @arg @ref LL_I2C_MODE_SMBUS_SOFTEND_NO_PEC
  1873. * @arg @ref LL_I2C_MODE_SMBUS_AUTOEND_WITH_PEC
  1874. * @arg @ref LL_I2C_MODE_SMBUS_SOFTEND_WITH_PEC
  1875. * @param Request This parameter can be one of the following values:
  1876. * @arg @ref LL_I2C_GENERATE_NOSTARTSTOP
  1877. * @arg @ref LL_I2C_GENERATE_STOP
  1878. * @arg @ref LL_I2C_GENERATE_START_READ
  1879. * @arg @ref LL_I2C_GENERATE_START_WRITE
  1880. * @arg @ref LL_I2C_GENERATE_RESTART_7BIT_READ
  1881. * @arg @ref LL_I2C_GENERATE_RESTART_7BIT_WRITE
  1882. * @arg @ref LL_I2C_GENERATE_RESTART_10BIT_READ
  1883. * @arg @ref LL_I2C_GENERATE_RESTART_10BIT_WRITE
  1884. * @retval None
  1885. */
  1886. __STATIC_INLINE void LL_I2C_HandleTransfer(I2C_TypeDef *I2Cx, uint32_t SlaveAddr, uint32_t SlaveAddrSize,
  1887. uint32_t TransferSize, uint32_t EndMode, uint32_t Request)
  1888. {
  1889. MODIFY_REG(I2Cx->CR2, I2C_CR2_SADD | I2C_CR2_ADD10 | I2C_CR2_RD_WRN | I2C_CR2_START | I2C_CR2_STOP | I2C_CR2_RELOAD |
  1890. I2C_CR2_NBYTES | I2C_CR2_AUTOEND | I2C_CR2_HEAD10R,
  1891. SlaveAddr | SlaveAddrSize | TransferSize << I2C_CR2_NBYTES_Pos | EndMode | Request);
  1892. }
  1893. /**
  1894. * @brief Indicate the value of transfer direction (slave mode).
  1895. * @note RESET: Write transfer, Slave enters in receiver mode.
  1896. * SET: Read transfer, Slave enters in transmitter mode.
  1897. * @rmtoll ISR DIR LL_I2C_GetTransferDirection
  1898. * @param I2Cx I2C Instance.
  1899. * @retval Returned value can be one of the following values:
  1900. * @arg @ref LL_I2C_DIRECTION_WRITE
  1901. * @arg @ref LL_I2C_DIRECTION_READ
  1902. */
  1903. __STATIC_INLINE uint32_t LL_I2C_GetTransferDirection(I2C_TypeDef *I2Cx)
  1904. {
  1905. return (uint32_t)(READ_BIT(I2Cx->ISR, I2C_ISR_DIR));
  1906. }
  1907. /**
  1908. * @brief Return the slave matched address.
  1909. * @rmtoll ISR ADDCODE LL_I2C_GetAddressMatchCode
  1910. * @param I2Cx I2C Instance.
  1911. * @retval Value between Min_Data=0x00 and Max_Data=0x3F
  1912. */
  1913. __STATIC_INLINE uint32_t LL_I2C_GetAddressMatchCode(I2C_TypeDef *I2Cx)
  1914. {
  1915. return (uint32_t)(READ_BIT(I2Cx->ISR, I2C_ISR_ADDCODE) >> I2C_ISR_ADDCODE_Pos << 1);
  1916. }
  1917. /**
  1918. * @brief Enable internal comparison of the SMBus Packet Error byte (transmission or reception mode).
  1919. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1920. * SMBus feature is supported by the I2Cx Instance.
  1921. * @note This feature is cleared by hardware when the PEC byte is transferred, or when a STOP condition or an Address Matched is received.
  1922. * This bit has no effect when RELOAD bit is set.
  1923. * This bit has no effect in device mode when SBC bit is not set.
  1924. * @rmtoll CR2 PECBYTE LL_I2C_EnableSMBusPECCompare
  1925. * @param I2Cx I2C Instance.
  1926. * @retval None
  1927. */
  1928. __STATIC_INLINE void LL_I2C_EnableSMBusPECCompare(I2C_TypeDef *I2Cx)
  1929. {
  1930. SET_BIT(I2Cx->CR2, I2C_CR2_PECBYTE);
  1931. }
  1932. /**
  1933. * @brief Check if the SMBus Packet Error byte internal comparison is requested or not.
  1934. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1935. * SMBus feature is supported by the I2Cx Instance.
  1936. * @rmtoll CR2 PECBYTE LL_I2C_IsEnabledSMBusPECCompare
  1937. * @param I2Cx I2C Instance.
  1938. * @retval State of bit (1 or 0).
  1939. */
  1940. __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusPECCompare(I2C_TypeDef *I2Cx)
  1941. {
  1942. return (READ_BIT(I2Cx->CR2, I2C_CR2_PECBYTE) == (I2C_CR2_PECBYTE));
  1943. }
  1944. /**
  1945. * @brief Get the SMBus Packet Error byte calculated.
  1946. * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not
  1947. * SMBus feature is supported by the I2Cx Instance.
  1948. * @rmtoll PECR PEC LL_I2C_GetSMBusPEC
  1949. * @param I2Cx I2C Instance.
  1950. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  1951. */
  1952. __STATIC_INLINE uint32_t LL_I2C_GetSMBusPEC(I2C_TypeDef *I2Cx)
  1953. {
  1954. return (uint32_t)(READ_BIT(I2Cx->PECR, I2C_PECR_PEC));
  1955. }
  1956. /**
  1957. * @brief Read Receive Data register.
  1958. * @rmtoll RXDR RXDATA LL_I2C_ReceiveData8
  1959. * @param I2Cx I2C Instance.
  1960. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  1961. */
  1962. __STATIC_INLINE uint8_t LL_I2C_ReceiveData8(I2C_TypeDef *I2Cx)
  1963. {
  1964. return (uint8_t)(READ_BIT(I2Cx->RXDR, I2C_RXDR_RXDATA));
  1965. }
  1966. /**
  1967. * @brief Write in Transmit Data Register .
  1968. * @rmtoll TXDR TXDATA LL_I2C_TransmitData8
  1969. * @param I2Cx I2C Instance.
  1970. * @param Data Value between Min_Data=0x00 and Max_Data=0xFF
  1971. * @retval None
  1972. */
  1973. __STATIC_INLINE void LL_I2C_TransmitData8(I2C_TypeDef *I2Cx, uint8_t Data)
  1974. {
  1975. WRITE_REG(I2Cx->TXDR, Data);
  1976. }
  1977. /**
  1978. * @}
  1979. */
  1980. #if defined(USE_FULL_LL_DRIVER)
  1981. /** @defgroup I2C_LL_EF_Init Initialization and de-initialization functions
  1982. * @{
  1983. */
  1984. uint32_t LL_I2C_Init(I2C_TypeDef *I2Cx, LL_I2C_InitTypeDef *I2C_InitStruct);
  1985. uint32_t LL_I2C_DeInit(I2C_TypeDef *I2Cx);
  1986. void LL_I2C_StructInit(LL_I2C_InitTypeDef *I2C_InitStruct);
  1987. /**
  1988. * @}
  1989. */
  1990. #endif /* USE_FULL_LL_DRIVER */
  1991. /**
  1992. * @}
  1993. */
  1994. /**
  1995. * @}
  1996. */
  1997. #endif /* I2C1 || I2C2 || I2C3 || I2C4 */
  1998. /**
  1999. * @}
  2000. */
  2001. #ifdef __cplusplus
  2002. }
  2003. #endif
  2004. #endif /* __STM32F7xx_LL_I2C_H */
  2005. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/