STM32F103xB HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f1xx_ll_i2c.h 00004 * @author MCD Application Team 00005 * @brief Header file of I2C LL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 00010 * All rights reserved.</center></h2> 00011 * 00012 * This software component is licensed by ST under BSD 3-Clause license, 00013 * the "License"; You may not use this file except in compliance with the 00014 * License. You may obtain a copy of the License at: 00015 * opensource.org/licenses/BSD-3-Clause 00016 * 00017 ****************************************************************************** 00018 */ 00019 00020 /* Define to prevent recursive inclusion -------------------------------------*/ 00021 #ifndef __STM32F1xx_LL_I2C_H 00022 #define __STM32F1xx_LL_I2C_H 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 /* Includes ------------------------------------------------------------------*/ 00029 #include "stm32f1xx.h" 00030 00031 /** @addtogroup STM32F1xx_LL_Driver 00032 * @{ 00033 */ 00034 00035 #if defined (I2C1) || defined (I2C2) 00036 00037 /** @defgroup I2C_LL I2C 00038 * @{ 00039 */ 00040 00041 /* Private types -------------------------------------------------------------*/ 00042 /* Private variables ---------------------------------------------------------*/ 00043 00044 /* Private constants ---------------------------------------------------------*/ 00045 /** @defgroup I2C_LL_Private_Constants I2C Private Constants 00046 * @{ 00047 */ 00048 00049 /* Defines used to perform compute and check in the macros */ 00050 #define LL_I2C_MAX_SPEED_STANDARD 100000U 00051 #define LL_I2C_MAX_SPEED_FAST 400000U 00052 /** 00053 * @} 00054 */ 00055 00056 /* Private macros ------------------------------------------------------------*/ 00057 #if defined(USE_FULL_LL_DRIVER) 00058 /** @defgroup I2C_LL_Private_Macros I2C Private Macros 00059 * @{ 00060 */ 00061 /** 00062 * @} 00063 */ 00064 #endif /*USE_FULL_LL_DRIVER*/ 00065 00066 /* Exported types ------------------------------------------------------------*/ 00067 #if defined(USE_FULL_LL_DRIVER) 00068 /** @defgroup I2C_LL_ES_INIT I2C Exported Init structure 00069 * @{ 00070 */ 00071 typedef struct 00072 { 00073 uint32_t PeripheralMode; /*!< Specifies the peripheral mode. 00074 This parameter can be a value of @ref I2C_LL_EC_PERIPHERAL_MODE 00075 00076 This feature can be modified afterwards using unitary function @ref LL_I2C_SetMode(). */ 00077 00078 uint32_t ClockSpeed; /*!< Specifies the clock frequency. 00079 This parameter must be set to a value lower than 400kHz (in Hz) 00080 00081 This feature can be modified afterwards using unitary function @ref LL_I2C_SetClockPeriod() 00082 or @ref LL_I2C_SetDutyCycle() or @ref LL_I2C_SetClockSpeedMode() or @ref LL_I2C_ConfigSpeed(). */ 00083 00084 uint32_t DutyCycle; /*!< Specifies the I2C fast mode duty cycle. 00085 This parameter can be a value of @ref I2C_LL_EC_DUTYCYCLE 00086 00087 This feature can be modified afterwards using unitary function @ref LL_I2C_SetDutyCycle(). */ 00088 00089 uint32_t OwnAddress1; /*!< Specifies the device own address 1. 00090 This parameter must be a value between Min_Data = 0x00 and Max_Data = 0x3FF 00091 00092 This feature can be modified afterwards using unitary function @ref LL_I2C_SetOwnAddress1(). */ 00093 00094 uint32_t TypeAcknowledge; /*!< Specifies the ACKnowledge or Non ACKnowledge condition after the address receive match code or next received byte. 00095 This parameter can be a value of @ref I2C_LL_EC_I2C_ACKNOWLEDGE 00096 00097 This feature can be modified afterwards using unitary function @ref LL_I2C_AcknowledgeNextData(). */ 00098 00099 uint32_t OwnAddrSize; /*!< Specifies the device own address 1 size (7-bit or 10-bit). 00100 This parameter can be a value of @ref I2C_LL_EC_OWNADDRESS1 00101 00102 This feature can be modified afterwards using unitary function @ref LL_I2C_SetOwnAddress1(). */ 00103 } LL_I2C_InitTypeDef; 00104 /** 00105 * @} 00106 */ 00107 #endif /*USE_FULL_LL_DRIVER*/ 00108 00109 /* Exported constants --------------------------------------------------------*/ 00110 /** @defgroup I2C_LL_Exported_Constants I2C Exported Constants 00111 * @{ 00112 */ 00113 00114 /** @defgroup I2C_LL_EC_GET_FLAG Get Flags Defines 00115 * @brief Flags defines which can be used with LL_I2C_ReadReg function 00116 * @{ 00117 */ 00118 #define LL_I2C_SR1_SB I2C_SR1_SB /*!< Start Bit (master mode) */ 00119 #define LL_I2C_SR1_ADDR I2C_SR1_ADDR /*!< Address sent (master mode) or 00120 Address matched flag (slave mode) */ 00121 #define LL_I2C_SR1_BTF I2C_SR1_BTF /*!< Byte Transfer Finished flag */ 00122 #define LL_I2C_SR1_ADD10 I2C_SR1_ADD10 /*!< 10-bit header sent (master mode) */ 00123 #define LL_I2C_SR1_STOPF I2C_SR1_STOPF /*!< Stop detection flag (slave mode) */ 00124 #define LL_I2C_SR1_RXNE I2C_SR1_RXNE /*!< Data register not empty (receivers) */ 00125 #define LL_I2C_SR1_TXE I2C_SR1_TXE /*!< Data register empty (transmitters) */ 00126 #define LL_I2C_SR1_BERR I2C_SR1_BERR /*!< Bus error */ 00127 #define LL_I2C_SR1_ARLO I2C_SR1_ARLO /*!< Arbitration lost */ 00128 #define LL_I2C_SR1_AF I2C_SR1_AF /*!< Acknowledge failure flag */ 00129 #define LL_I2C_SR1_OVR I2C_SR1_OVR /*!< Overrun/Underrun */ 00130 #define LL_I2C_SR1_PECERR I2C_ISR_PECERR /*!< PEC Error in reception (SMBus mode) */ 00131 #define LL_I2C_SR1_TIMEOUT I2C_ISR_TIMEOUT /*!< Timeout detection flag (SMBus mode) */ 00132 #define LL_I2C_SR1_SMALERT I2C_ISR_SMALERT /*!< SMBus alert (SMBus mode) */ 00133 #define LL_I2C_SR2_MSL I2C_SR2_MSL /*!< Master/Slave flag */ 00134 #define LL_I2C_SR2_BUSY I2C_SR2_BUSY /*!< Bus busy flag */ 00135 #define LL_I2C_SR2_TRA I2C_SR2_TRA /*!< Transmitter/receiver direction */ 00136 #define LL_I2C_SR2_GENCALL I2C_SR2_GENCALL /*!< General call address (Slave mode) */ 00137 #define LL_I2C_SR2_SMBDEFAULT I2C_SR2_SMBDEFAULT /*!< SMBus Device default address (Slave mode) */ 00138 #define LL_I2C_SR2_SMBHOST I2C_SR2_SMBHOST /*!< SMBus Host address (Slave mode) */ 00139 #define LL_I2C_SR2_DUALF I2C_SR2_DUALF /*!< Dual flag (Slave mode) */ 00140 /** 00141 * @} 00142 */ 00143 00144 /** @defgroup I2C_LL_EC_IT IT Defines 00145 * @brief IT defines which can be used with LL_I2C_ReadReg and LL_I2C_WriteReg functions 00146 * @{ 00147 */ 00148 #define LL_I2C_CR2_ITEVTEN I2C_CR2_ITEVTEN /*!< Events interrupts enable */ 00149 #define LL_I2C_CR2_ITBUFEN I2C_CR2_ITBUFEN /*!< Buffer interrupts enable */ 00150 #define LL_I2C_CR2_ITERREN I2C_CR2_ITERREN /*!< Error interrupts enable */ 00151 /** 00152 * @} 00153 */ 00154 00155 /** @defgroup I2C_LL_EC_OWNADDRESS1 Own Address 1 Length 00156 * @{ 00157 */ 00158 #define LL_I2C_OWNADDRESS1_7BIT 0x00004000U /*!< Own address 1 is a 7-bit address. */ 00159 #define LL_I2C_OWNADDRESS1_10BIT (uint32_t)(I2C_OAR1_ADDMODE | 0x00004000U) /*!< Own address 1 is a 10-bit address. */ 00160 /** 00161 * @} 00162 */ 00163 00164 /** @defgroup I2C_LL_EC_DUTYCYCLE Fast Mode Duty Cycle 00165 * @{ 00166 */ 00167 #define LL_I2C_DUTYCYCLE_2 0x00000000U /*!< I2C fast mode Tlow/Thigh = 2 */ 00168 #define LL_I2C_DUTYCYCLE_16_9 I2C_CCR_DUTY /*!< I2C fast mode Tlow/Thigh = 16/9 */ 00169 /** 00170 * @} 00171 */ 00172 00173 /** @defgroup I2C_LL_EC_CLOCK_SPEED_MODE Master Clock Speed Mode 00174 * @{ 00175 */ 00176 #define LL_I2C_CLOCK_SPEED_STANDARD_MODE 0x00000000U /*!< Master clock speed range is standard mode */ 00177 #define LL_I2C_CLOCK_SPEED_FAST_MODE I2C_CCR_FS /*!< Master clock speed range is fast mode */ 00178 /** 00179 * @} 00180 */ 00181 00182 /** @defgroup I2C_LL_EC_PERIPHERAL_MODE Peripheral Mode 00183 * @{ 00184 */ 00185 #define LL_I2C_MODE_I2C 0x00000000U /*!< I2C Master or Slave mode */ 00186 #define LL_I2C_MODE_SMBUS_HOST (uint32_t)(I2C_CR1_SMBUS | I2C_CR1_SMBTYPE | I2C_CR1_ENARP) /*!< SMBus Host address acknowledge */ 00187 #define LL_I2C_MODE_SMBUS_DEVICE I2C_CR1_SMBUS /*!< SMBus Device default mode (Default address not acknowledge) */ 00188 #define LL_I2C_MODE_SMBUS_DEVICE_ARP (uint32_t)(I2C_CR1_SMBUS | I2C_CR1_ENARP) /*!< SMBus Device Default address acknowledge */ 00189 /** 00190 * @} 00191 */ 00192 00193 /** @defgroup I2C_LL_EC_I2C_ACKNOWLEDGE Acknowledge Generation 00194 * @{ 00195 */ 00196 #define LL_I2C_ACK I2C_CR1_ACK /*!< ACK is sent after current received byte. */ 00197 #define LL_I2C_NACK 0x00000000U /*!< NACK is sent after current received byte.*/ 00198 /** 00199 * @} 00200 */ 00201 00202 /** @defgroup I2C_LL_EC_DIRECTION Read Write Direction 00203 * @{ 00204 */ 00205 #define LL_I2C_DIRECTION_WRITE I2C_SR2_TRA /*!< Bus is in write transfer */ 00206 #define LL_I2C_DIRECTION_READ 0x00000000U /*!< Bus is in read transfer */ 00207 /** 00208 * @} 00209 */ 00210 00211 /** 00212 * @} 00213 */ 00214 00215 /* Exported macro ------------------------------------------------------------*/ 00216 /** @defgroup I2C_LL_Exported_Macros I2C Exported Macros 00217 * @{ 00218 */ 00219 00220 /** @defgroup I2C_LL_EM_WRITE_READ Common Write and read registers Macros 00221 * @{ 00222 */ 00223 00224 /** 00225 * @brief Write a value in I2C register 00226 * @param __INSTANCE__ I2C Instance 00227 * @param __REG__ Register to be written 00228 * @param __VALUE__ Value to be written in the register 00229 * @retval None 00230 */ 00231 #define LL_I2C_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__)) 00232 00233 /** 00234 * @brief Read a value in I2C register 00235 * @param __INSTANCE__ I2C Instance 00236 * @param __REG__ Register to be read 00237 * @retval Register value 00238 */ 00239 #define LL_I2C_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__) 00240 /** 00241 * @} 00242 */ 00243 00244 /** @defgroup I2C_LL_EM_Exported_Macros_Helper Exported_Macros_Helper 00245 * @{ 00246 */ 00247 00248 /** 00249 * @brief Convert Peripheral Clock Frequency in Mhz. 00250 * @param __PCLK__ This parameter must be a value of peripheral clock (in Hz). 00251 * @retval Value of peripheral clock (in Mhz) 00252 */ 00253 #define __LL_I2C_FREQ_HZ_TO_MHZ(__PCLK__) (uint32_t)((__PCLK__)/1000000U) 00254 00255 /** 00256 * @brief Convert Peripheral Clock Frequency in Hz. 00257 * @param __PCLK__ This parameter must be a value of peripheral clock (in Mhz). 00258 * @retval Value of peripheral clock (in Hz) 00259 */ 00260 #define __LL_I2C_FREQ_MHZ_TO_HZ(__PCLK__) (uint32_t)((__PCLK__)*1000000U) 00261 00262 /** 00263 * @brief Compute I2C Clock rising time. 00264 * @param __FREQRANGE__ This parameter must be a value of peripheral clock (in Mhz). 00265 * @param __SPEED__ This parameter must be a value lower than 400kHz (in Hz). 00266 * @retval Value between Min_Data=0x02 and Max_Data=0x3F 00267 */ 00268 #define __LL_I2C_RISE_TIME(__FREQRANGE__, __SPEED__) (uint32_t)(((__SPEED__) <= LL_I2C_MAX_SPEED_STANDARD) ? ((__FREQRANGE__) + 1U) : ((((__FREQRANGE__) * 300U) / 1000U) + 1U)) 00269 00270 /** 00271 * @brief Compute Speed clock range to a Clock Control Register (I2C_CCR_CCR) value. 00272 * @param __PCLK__ This parameter must be a value of peripheral clock (in Hz). 00273 * @param __SPEED__ This parameter must be a value lower than 400kHz (in Hz). 00274 * @param __DUTYCYCLE__ This parameter can be one of the following values: 00275 * @arg @ref LL_I2C_DUTYCYCLE_2 00276 * @arg @ref LL_I2C_DUTYCYCLE_16_9 00277 * @retval Value between Min_Data=0x004 and Max_Data=0xFFF, except in FAST DUTY mode where Min_Data=0x001. 00278 */ 00279 #define __LL_I2C_SPEED_TO_CCR(__PCLK__, __SPEED__, __DUTYCYCLE__) (uint32_t)(((__SPEED__) <= LL_I2C_MAX_SPEED_STANDARD)? \ 00280 (__LL_I2C_SPEED_STANDARD_TO_CCR((__PCLK__), (__SPEED__))) : \ 00281 (__LL_I2C_SPEED_FAST_TO_CCR((__PCLK__), (__SPEED__), (__DUTYCYCLE__)))) 00282 00283 /** 00284 * @brief Compute Speed Standard clock range to a Clock Control Register (I2C_CCR_CCR) value. 00285 * @param __PCLK__ This parameter must be a value of peripheral clock (in Hz). 00286 * @param __SPEED__ This parameter must be a value lower than 100kHz (in Hz). 00287 * @retval Value between Min_Data=0x004 and Max_Data=0xFFF. 00288 */ 00289 #define __LL_I2C_SPEED_STANDARD_TO_CCR(__PCLK__, __SPEED__) (uint32_t)(((((__PCLK__)/((__SPEED__) << 1U)) & I2C_CCR_CCR) < 4U)? 4U:((__PCLK__) / ((__SPEED__) << 1U))) 00290 00291 /** 00292 * @brief Compute Speed Fast clock range to a Clock Control Register (I2C_CCR_CCR) value. 00293 * @param __PCLK__ This parameter must be a value of peripheral clock (in Hz). 00294 * @param __SPEED__ This parameter must be a value between Min_Data=100Khz and Max_Data=400Khz (in Hz). 00295 * @param __DUTYCYCLE__ This parameter can be one of the following values: 00296 * @arg @ref LL_I2C_DUTYCYCLE_2 00297 * @arg @ref LL_I2C_DUTYCYCLE_16_9 00298 * @retval Value between Min_Data=0x001 and Max_Data=0xFFF 00299 */ 00300 #define __LL_I2C_SPEED_FAST_TO_CCR(__PCLK__, __SPEED__, __DUTYCYCLE__) (uint32_t)(((__DUTYCYCLE__) == LL_I2C_DUTYCYCLE_2)? \ 00301 (((((__PCLK__) / ((__SPEED__) * 3U)) & I2C_CCR_CCR) == 0U)? 1U:((__PCLK__) / ((__SPEED__) * 3U))) : \ 00302 (((((__PCLK__) / ((__SPEED__) * 25U)) & I2C_CCR_CCR) == 0U)? 1U:((__PCLK__) / ((__SPEED__) * 25U)))) 00303 00304 /** 00305 * @brief Get the Least significant bits of a 10-Bits address. 00306 * @param __ADDRESS__ This parameter must be a value of a 10-Bits slave address. 00307 * @retval Value between Min_Data=0x00 and Max_Data=0xFF 00308 */ 00309 #define __LL_I2C_10BIT_ADDRESS(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FF)))) 00310 00311 /** 00312 * @brief Convert a 10-Bits address to a 10-Bits header with Write direction. 00313 * @param __ADDRESS__ This parameter must be a value of a 10-Bits slave address. 00314 * @retval Value between Min_Data=0xF0 and Max_Data=0xF6 00315 */ 00316 #define __LL_I2C_10BIT_HEADER_WRITE(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300))) >> 7) | (uint16_t)(0xF0)))) 00317 00318 /** 00319 * @brief Convert a 10-Bits address to a 10-Bits header with Read direction. 00320 * @param __ADDRESS__ This parameter must be a value of a 10-Bits slave address. 00321 * @retval Value between Min_Data=0xF1 and Max_Data=0xF7 00322 */ 00323 #define __LL_I2C_10BIT_HEADER_READ(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300))) >> 7) | (uint16_t)(0xF1)))) 00324 00325 /** 00326 * @} 00327 */ 00328 00329 /** 00330 * @} 00331 */ 00332 00333 /* Exported functions --------------------------------------------------------*/ 00334 00335 /** @defgroup I2C_LL_Exported_Functions I2C Exported Functions 00336 * @{ 00337 */ 00338 00339 /** @defgroup I2C_LL_EF_Configuration Configuration 00340 * @{ 00341 */ 00342 00343 /** 00344 * @brief Enable I2C peripheral (PE = 1). 00345 * @rmtoll CR1 PE LL_I2C_Enable 00346 * @param I2Cx I2C Instance. 00347 * @retval None 00348 */ 00349 __STATIC_INLINE void LL_I2C_Enable(I2C_TypeDef *I2Cx) 00350 { 00351 SET_BIT(I2Cx->CR1, I2C_CR1_PE); 00352 } 00353 00354 /** 00355 * @brief Disable I2C peripheral (PE = 0). 00356 * @rmtoll CR1 PE LL_I2C_Disable 00357 * @param I2Cx I2C Instance. 00358 * @retval None 00359 */ 00360 __STATIC_INLINE void LL_I2C_Disable(I2C_TypeDef *I2Cx) 00361 { 00362 CLEAR_BIT(I2Cx->CR1, I2C_CR1_PE); 00363 } 00364 00365 /** 00366 * @brief Check if the I2C peripheral is enabled or disabled. 00367 * @rmtoll CR1 PE LL_I2C_IsEnabled 00368 * @param I2Cx I2C Instance. 00369 * @retval State of bit (1 or 0). 00370 */ 00371 __STATIC_INLINE uint32_t LL_I2C_IsEnabled(I2C_TypeDef *I2Cx) 00372 { 00373 return (READ_BIT(I2Cx->CR1, I2C_CR1_PE) == (I2C_CR1_PE)); 00374 } 00375 00376 00377 /** 00378 * @brief Enable DMA transmission requests. 00379 * @rmtoll CR2 DMAEN LL_I2C_EnableDMAReq_TX 00380 * @param I2Cx I2C Instance. 00381 * @retval None 00382 */ 00383 __STATIC_INLINE void LL_I2C_EnableDMAReq_TX(I2C_TypeDef *I2Cx) 00384 { 00385 SET_BIT(I2Cx->CR2, I2C_CR2_DMAEN); 00386 } 00387 00388 /** 00389 * @brief Disable DMA transmission requests. 00390 * @rmtoll CR2 DMAEN LL_I2C_DisableDMAReq_TX 00391 * @param I2Cx I2C Instance. 00392 * @retval None 00393 */ 00394 __STATIC_INLINE void LL_I2C_DisableDMAReq_TX(I2C_TypeDef *I2Cx) 00395 { 00396 CLEAR_BIT(I2Cx->CR2, I2C_CR2_DMAEN); 00397 } 00398 00399 /** 00400 * @brief Check if DMA transmission requests are enabled or disabled. 00401 * @rmtoll CR2 DMAEN LL_I2C_IsEnabledDMAReq_TX 00402 * @param I2Cx I2C Instance. 00403 * @retval State of bit (1 or 0). 00404 */ 00405 __STATIC_INLINE uint32_t LL_I2C_IsEnabledDMAReq_TX(I2C_TypeDef *I2Cx) 00406 { 00407 return (READ_BIT(I2Cx->CR2, I2C_CR2_DMAEN) == (I2C_CR2_DMAEN)); 00408 } 00409 00410 /** 00411 * @brief Enable DMA reception requests. 00412 * @rmtoll CR2 DMAEN LL_I2C_EnableDMAReq_RX 00413 * @param I2Cx I2C Instance. 00414 * @retval None 00415 */ 00416 __STATIC_INLINE void LL_I2C_EnableDMAReq_RX(I2C_TypeDef *I2Cx) 00417 { 00418 SET_BIT(I2Cx->CR2, I2C_CR2_DMAEN); 00419 } 00420 00421 /** 00422 * @brief Disable DMA reception requests. 00423 * @rmtoll CR2 DMAEN LL_I2C_DisableDMAReq_RX 00424 * @param I2Cx I2C Instance. 00425 * @retval None 00426 */ 00427 __STATIC_INLINE void LL_I2C_DisableDMAReq_RX(I2C_TypeDef *I2Cx) 00428 { 00429 CLEAR_BIT(I2Cx->CR2, I2C_CR2_DMAEN); 00430 } 00431 00432 /** 00433 * @brief Check if DMA reception requests are enabled or disabled. 00434 * @rmtoll CR2 DMAEN LL_I2C_IsEnabledDMAReq_RX 00435 * @param I2Cx I2C Instance. 00436 * @retval State of bit (1 or 0). 00437 */ 00438 __STATIC_INLINE uint32_t LL_I2C_IsEnabledDMAReq_RX(I2C_TypeDef *I2Cx) 00439 { 00440 return (READ_BIT(I2Cx->CR2, I2C_CR2_DMAEN) == (I2C_CR2_DMAEN)); 00441 } 00442 00443 /** 00444 * @brief Get the data register address used for DMA transfer. 00445 * @rmtoll DR DR LL_I2C_DMA_GetRegAddr 00446 * @param I2Cx I2C Instance. 00447 * @retval Address of data register 00448 */ 00449 __STATIC_INLINE uint32_t LL_I2C_DMA_GetRegAddr(I2C_TypeDef *I2Cx) 00450 { 00451 return (uint32_t) & (I2Cx->DR); 00452 } 00453 00454 /** 00455 * @brief Enable Clock stretching. 00456 * @note This bit can only be programmed when the I2C is disabled (PE = 0). 00457 * @rmtoll CR1 NOSTRETCH LL_I2C_EnableClockStretching 00458 * @param I2Cx I2C Instance. 00459 * @retval None 00460 */ 00461 __STATIC_INLINE void LL_I2C_EnableClockStretching(I2C_TypeDef *I2Cx) 00462 { 00463 CLEAR_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH); 00464 } 00465 00466 /** 00467 * @brief Disable Clock stretching. 00468 * @note This bit can only be programmed when the I2C is disabled (PE = 0). 00469 * @rmtoll CR1 NOSTRETCH LL_I2C_DisableClockStretching 00470 * @param I2Cx I2C Instance. 00471 * @retval None 00472 */ 00473 __STATIC_INLINE void LL_I2C_DisableClockStretching(I2C_TypeDef *I2Cx) 00474 { 00475 SET_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH); 00476 } 00477 00478 /** 00479 * @brief Check if Clock stretching is enabled or disabled. 00480 * @rmtoll CR1 NOSTRETCH LL_I2C_IsEnabledClockStretching 00481 * @param I2Cx I2C Instance. 00482 * @retval State of bit (1 or 0). 00483 */ 00484 __STATIC_INLINE uint32_t LL_I2C_IsEnabledClockStretching(I2C_TypeDef *I2Cx) 00485 { 00486 return (READ_BIT(I2Cx->CR1, I2C_CR1_NOSTRETCH) != (I2C_CR1_NOSTRETCH)); 00487 } 00488 00489 /** 00490 * @brief Enable General Call. 00491 * @note When enabled the Address 0x00 is ACKed. 00492 * @rmtoll CR1 ENGC LL_I2C_EnableGeneralCall 00493 * @param I2Cx I2C Instance. 00494 * @retval None 00495 */ 00496 __STATIC_INLINE void LL_I2C_EnableGeneralCall(I2C_TypeDef *I2Cx) 00497 { 00498 SET_BIT(I2Cx->CR1, I2C_CR1_ENGC); 00499 } 00500 00501 /** 00502 * @brief Disable General Call. 00503 * @note When disabled the Address 0x00 is NACKed. 00504 * @rmtoll CR1 ENGC LL_I2C_DisableGeneralCall 00505 * @param I2Cx I2C Instance. 00506 * @retval None 00507 */ 00508 __STATIC_INLINE void LL_I2C_DisableGeneralCall(I2C_TypeDef *I2Cx) 00509 { 00510 CLEAR_BIT(I2Cx->CR1, I2C_CR1_ENGC); 00511 } 00512 00513 /** 00514 * @brief Check if General Call is enabled or disabled. 00515 * @rmtoll CR1 ENGC LL_I2C_IsEnabledGeneralCall 00516 * @param I2Cx I2C Instance. 00517 * @retval State of bit (1 or 0). 00518 */ 00519 __STATIC_INLINE uint32_t LL_I2C_IsEnabledGeneralCall(I2C_TypeDef *I2Cx) 00520 { 00521 return (READ_BIT(I2Cx->CR1, I2C_CR1_ENGC) == (I2C_CR1_ENGC)); 00522 } 00523 00524 /** 00525 * @brief Set the Own Address1. 00526 * @rmtoll OAR1 ADD0 LL_I2C_SetOwnAddress1\n 00527 * OAR1 ADD1_7 LL_I2C_SetOwnAddress1\n 00528 * OAR1 ADD8_9 LL_I2C_SetOwnAddress1\n 00529 * OAR1 ADDMODE LL_I2C_SetOwnAddress1 00530 * @param I2Cx I2C Instance. 00531 * @param OwnAddress1 This parameter must be a value between Min_Data=0 and Max_Data=0x3FF. 00532 * @param OwnAddrSize This parameter can be one of the following values: 00533 * @arg @ref LL_I2C_OWNADDRESS1_7BIT 00534 * @arg @ref LL_I2C_OWNADDRESS1_10BIT 00535 * @retval None 00536 */ 00537 __STATIC_INLINE void LL_I2C_SetOwnAddress1(I2C_TypeDef *I2Cx, uint32_t OwnAddress1, uint32_t OwnAddrSize) 00538 { 00539 MODIFY_REG(I2Cx->OAR1, I2C_OAR1_ADD0 | I2C_OAR1_ADD1_7 | I2C_OAR1_ADD8_9 | I2C_OAR1_ADDMODE, OwnAddress1 | OwnAddrSize); 00540 } 00541 00542 /** 00543 * @brief Set the 7bits Own Address2. 00544 * @note This action has no effect if own address2 is enabled. 00545 * @rmtoll OAR2 ADD2 LL_I2C_SetOwnAddress2 00546 * @param I2Cx I2C Instance. 00547 * @param OwnAddress2 This parameter must be a value between Min_Data=0 and Max_Data=0x7F. 00548 * @retval None 00549 */ 00550 __STATIC_INLINE void LL_I2C_SetOwnAddress2(I2C_TypeDef *I2Cx, uint32_t OwnAddress2) 00551 { 00552 MODIFY_REG(I2Cx->OAR2, I2C_OAR2_ADD2, OwnAddress2); 00553 } 00554 00555 /** 00556 * @brief Enable acknowledge on Own Address2 match address. 00557 * @rmtoll OAR2 ENDUAL LL_I2C_EnableOwnAddress2 00558 * @param I2Cx I2C Instance. 00559 * @retval None 00560 */ 00561 __STATIC_INLINE void LL_I2C_EnableOwnAddress2(I2C_TypeDef *I2Cx) 00562 { 00563 SET_BIT(I2Cx->OAR2, I2C_OAR2_ENDUAL); 00564 } 00565 00566 /** 00567 * @brief Disable acknowledge on Own Address2 match address. 00568 * @rmtoll OAR2 ENDUAL LL_I2C_DisableOwnAddress2 00569 * @param I2Cx I2C Instance. 00570 * @retval None 00571 */ 00572 __STATIC_INLINE void LL_I2C_DisableOwnAddress2(I2C_TypeDef *I2Cx) 00573 { 00574 CLEAR_BIT(I2Cx->OAR2, I2C_OAR2_ENDUAL); 00575 } 00576 00577 /** 00578 * @brief Check if Own Address1 acknowledge is enabled or disabled. 00579 * @rmtoll OAR2 ENDUAL LL_I2C_IsEnabledOwnAddress2 00580 * @param I2Cx I2C Instance. 00581 * @retval State of bit (1 or 0). 00582 */ 00583 __STATIC_INLINE uint32_t LL_I2C_IsEnabledOwnAddress2(I2C_TypeDef *I2Cx) 00584 { 00585 return (READ_BIT(I2Cx->OAR2, I2C_OAR2_ENDUAL) == (I2C_OAR2_ENDUAL)); 00586 } 00587 00588 /** 00589 * @brief Configure the Peripheral clock frequency. 00590 * @rmtoll CR2 FREQ LL_I2C_SetPeriphClock 00591 * @param I2Cx I2C Instance. 00592 * @param PeriphClock Peripheral Clock (in Hz) 00593 * @retval None 00594 */ 00595 __STATIC_INLINE void LL_I2C_SetPeriphClock(I2C_TypeDef *I2Cx, uint32_t PeriphClock) 00596 { 00597 MODIFY_REG(I2Cx->CR2, I2C_CR2_FREQ, __LL_I2C_FREQ_HZ_TO_MHZ(PeriphClock)); 00598 } 00599 00600 /** 00601 * @brief Get the Peripheral clock frequency. 00602 * @rmtoll CR2 FREQ LL_I2C_GetPeriphClock 00603 * @param I2Cx I2C Instance. 00604 * @retval Value of Peripheral Clock (in Hz) 00605 */ 00606 __STATIC_INLINE uint32_t LL_I2C_GetPeriphClock(I2C_TypeDef *I2Cx) 00607 { 00608 return (uint32_t)(__LL_I2C_FREQ_MHZ_TO_HZ(READ_BIT(I2Cx->CR2, I2C_CR2_FREQ))); 00609 } 00610 00611 /** 00612 * @brief Configure the Duty cycle (Fast mode only). 00613 * @rmtoll CCR DUTY LL_I2C_SetDutyCycle 00614 * @param I2Cx I2C Instance. 00615 * @param DutyCycle This parameter can be one of the following values: 00616 * @arg @ref LL_I2C_DUTYCYCLE_2 00617 * @arg @ref LL_I2C_DUTYCYCLE_16_9 00618 * @retval None 00619 */ 00620 __STATIC_INLINE void LL_I2C_SetDutyCycle(I2C_TypeDef *I2Cx, uint32_t DutyCycle) 00621 { 00622 MODIFY_REG(I2Cx->CCR, I2C_CCR_DUTY, DutyCycle); 00623 } 00624 00625 /** 00626 * @brief Get the Duty cycle (Fast mode only). 00627 * @rmtoll CCR DUTY LL_I2C_GetDutyCycle 00628 * @param I2Cx I2C Instance. 00629 * @retval Returned value can be one of the following values: 00630 * @arg @ref LL_I2C_DUTYCYCLE_2 00631 * @arg @ref LL_I2C_DUTYCYCLE_16_9 00632 */ 00633 __STATIC_INLINE uint32_t LL_I2C_GetDutyCycle(I2C_TypeDef *I2Cx) 00634 { 00635 return (uint32_t)(READ_BIT(I2Cx->CCR, I2C_CCR_DUTY)); 00636 } 00637 00638 /** 00639 * @brief Configure the I2C master clock speed mode. 00640 * @rmtoll CCR FS LL_I2C_SetClockSpeedMode 00641 * @param I2Cx I2C Instance. 00642 * @param ClockSpeedMode This parameter can be one of the following values: 00643 * @arg @ref LL_I2C_CLOCK_SPEED_STANDARD_MODE 00644 * @arg @ref LL_I2C_CLOCK_SPEED_FAST_MODE 00645 * @retval None 00646 */ 00647 __STATIC_INLINE void LL_I2C_SetClockSpeedMode(I2C_TypeDef *I2Cx, uint32_t ClockSpeedMode) 00648 { 00649 MODIFY_REG(I2Cx->CCR, I2C_CCR_FS, ClockSpeedMode); 00650 } 00651 00652 /** 00653 * @brief Get the the I2C master speed mode. 00654 * @rmtoll CCR FS LL_I2C_GetClockSpeedMode 00655 * @param I2Cx I2C Instance. 00656 * @retval Returned value can be one of the following values: 00657 * @arg @ref LL_I2C_CLOCK_SPEED_STANDARD_MODE 00658 * @arg @ref LL_I2C_CLOCK_SPEED_FAST_MODE 00659 */ 00660 __STATIC_INLINE uint32_t LL_I2C_GetClockSpeedMode(I2C_TypeDef *I2Cx) 00661 { 00662 return (uint32_t)(READ_BIT(I2Cx->CCR, I2C_CCR_FS)); 00663 } 00664 00665 /** 00666 * @brief Configure the SCL, SDA rising time. 00667 * @note This bit can only be programmed when the I2C is disabled (PE = 0). 00668 * @rmtoll TRISE TRISE LL_I2C_SetRiseTime 00669 * @param I2Cx I2C Instance. 00670 * @param RiseTime This parameter must be a value between Min_Data=0x02 and Max_Data=0x3F. 00671 * @retval None 00672 */ 00673 __STATIC_INLINE void LL_I2C_SetRiseTime(I2C_TypeDef *I2Cx, uint32_t RiseTime) 00674 { 00675 MODIFY_REG(I2Cx->TRISE, I2C_TRISE_TRISE, RiseTime); 00676 } 00677 00678 /** 00679 * @brief Get the SCL, SDA rising time. 00680 * @rmtoll TRISE TRISE LL_I2C_GetRiseTime 00681 * @param I2Cx I2C Instance. 00682 * @retval Value between Min_Data=0x02 and Max_Data=0x3F 00683 */ 00684 __STATIC_INLINE uint32_t LL_I2C_GetRiseTime(I2C_TypeDef *I2Cx) 00685 { 00686 return (uint32_t)(READ_BIT(I2Cx->TRISE, I2C_TRISE_TRISE)); 00687 } 00688 00689 /** 00690 * @brief Configure the SCL high and low period. 00691 * @note This bit can only be programmed when the I2C is disabled (PE = 0). 00692 * @rmtoll CCR CCR LL_I2C_SetClockPeriod 00693 * @param I2Cx I2C Instance. 00694 * @param ClockPeriod This parameter must be a value between Min_Data=0x004 and Max_Data=0xFFF, except in FAST DUTY mode where Min_Data=0x001. 00695 * @retval None 00696 */ 00697 __STATIC_INLINE void LL_I2C_SetClockPeriod(I2C_TypeDef *I2Cx, uint32_t ClockPeriod) 00698 { 00699 MODIFY_REG(I2Cx->CCR, I2C_CCR_CCR, ClockPeriod); 00700 } 00701 00702 /** 00703 * @brief Get the SCL high and low period. 00704 * @rmtoll CCR CCR LL_I2C_GetClockPeriod 00705 * @param I2Cx I2C Instance. 00706 * @retval Value between Min_Data=0x004 and Max_Data=0xFFF, except in FAST DUTY mode where Min_Data=0x001. 00707 */ 00708 __STATIC_INLINE uint32_t LL_I2C_GetClockPeriod(I2C_TypeDef *I2Cx) 00709 { 00710 return (uint32_t)(READ_BIT(I2Cx->CCR, I2C_CCR_CCR)); 00711 } 00712 00713 /** 00714 * @brief Configure the SCL speed. 00715 * @note This bit can only be programmed when the I2C is disabled (PE = 0). 00716 * @rmtoll CR2 FREQ LL_I2C_ConfigSpeed\n 00717 * TRISE TRISE LL_I2C_ConfigSpeed\n 00718 * CCR FS LL_I2C_ConfigSpeed\n 00719 * CCR DUTY LL_I2C_ConfigSpeed\n 00720 * CCR CCR LL_I2C_ConfigSpeed 00721 * @param I2Cx I2C Instance. 00722 * @param PeriphClock Peripheral Clock (in Hz) 00723 * @param ClockSpeed This parameter must be a value lower than 400kHz (in Hz). 00724 * @param DutyCycle This parameter can be one of the following values: 00725 * @arg @ref LL_I2C_DUTYCYCLE_2 00726 * @arg @ref LL_I2C_DUTYCYCLE_16_9 00727 * @retval None 00728 */ 00729 __STATIC_INLINE void LL_I2C_ConfigSpeed(I2C_TypeDef *I2Cx, uint32_t PeriphClock, uint32_t ClockSpeed, 00730 uint32_t DutyCycle) 00731 { 00732 uint32_t freqrange = 0x0U; 00733 uint32_t clockconfig = 0x0U; 00734 00735 /* Compute frequency range */ 00736 freqrange = __LL_I2C_FREQ_HZ_TO_MHZ(PeriphClock); 00737 00738 /* Configure I2Cx: Frequency range register */ 00739 MODIFY_REG(I2Cx->CR2, I2C_CR2_FREQ, freqrange); 00740 00741 /* Configure I2Cx: Rise Time register */ 00742 MODIFY_REG(I2Cx->TRISE, I2C_TRISE_TRISE, __LL_I2C_RISE_TIME(freqrange, ClockSpeed)); 00743 00744 /* Configure Speed mode, Duty Cycle and Clock control register value */ 00745 if (ClockSpeed > LL_I2C_MAX_SPEED_STANDARD) 00746 { 00747 /* Set Speed mode at fast and duty cycle for Clock Speed request in fast clock range */ 00748 clockconfig = LL_I2C_CLOCK_SPEED_FAST_MODE | \ 00749 __LL_I2C_SPEED_FAST_TO_CCR(PeriphClock, ClockSpeed, DutyCycle) | \ 00750 DutyCycle; 00751 } 00752 else 00753 { 00754 /* Set Speed mode at standard for Clock Speed request in standard clock range */ 00755 clockconfig = LL_I2C_CLOCK_SPEED_STANDARD_MODE | \ 00756 __LL_I2C_SPEED_STANDARD_TO_CCR(PeriphClock, ClockSpeed); 00757 } 00758 00759 /* Configure I2Cx: Clock control register */ 00760 MODIFY_REG(I2Cx->CCR, (I2C_CCR_FS | I2C_CCR_DUTY | I2C_CCR_CCR), clockconfig); 00761 } 00762 00763 /** 00764 * @brief Configure peripheral mode. 00765 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 00766 * SMBus feature is supported by the I2Cx Instance. 00767 * @rmtoll CR1 SMBUS LL_I2C_SetMode\n 00768 * CR1 SMBTYPE LL_I2C_SetMode\n 00769 * CR1 ENARP LL_I2C_SetMode 00770 * @param I2Cx I2C Instance. 00771 * @param PeripheralMode This parameter can be one of the following values: 00772 * @arg @ref LL_I2C_MODE_I2C 00773 * @arg @ref LL_I2C_MODE_SMBUS_HOST 00774 * @arg @ref LL_I2C_MODE_SMBUS_DEVICE 00775 * @arg @ref LL_I2C_MODE_SMBUS_DEVICE_ARP 00776 * @retval None 00777 */ 00778 __STATIC_INLINE void LL_I2C_SetMode(I2C_TypeDef *I2Cx, uint32_t PeripheralMode) 00779 { 00780 MODIFY_REG(I2Cx->CR1, I2C_CR1_SMBUS | I2C_CR1_SMBTYPE | I2C_CR1_ENARP, PeripheralMode); 00781 } 00782 00783 /** 00784 * @brief Get peripheral mode. 00785 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 00786 * SMBus feature is supported by the I2Cx Instance. 00787 * @rmtoll CR1 SMBUS LL_I2C_GetMode\n 00788 * CR1 SMBTYPE LL_I2C_GetMode\n 00789 * CR1 ENARP LL_I2C_GetMode 00790 * @param I2Cx I2C Instance. 00791 * @retval Returned value can be one of the following values: 00792 * @arg @ref LL_I2C_MODE_I2C 00793 * @arg @ref LL_I2C_MODE_SMBUS_HOST 00794 * @arg @ref LL_I2C_MODE_SMBUS_DEVICE 00795 * @arg @ref LL_I2C_MODE_SMBUS_DEVICE_ARP 00796 */ 00797 __STATIC_INLINE uint32_t LL_I2C_GetMode(I2C_TypeDef *I2Cx) 00798 { 00799 return (uint32_t)(READ_BIT(I2Cx->CR1, I2C_CR1_SMBUS | I2C_CR1_SMBTYPE | I2C_CR1_ENARP)); 00800 } 00801 00802 /** 00803 * @brief Enable SMBus alert (Host or Device mode) 00804 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 00805 * SMBus feature is supported by the I2Cx Instance. 00806 * @note SMBus Device mode: 00807 * - SMBus Alert pin is drived low and 00808 * Alert Response Address Header acknowledge is enabled. 00809 * SMBus Host mode: 00810 * - SMBus Alert pin management is supported. 00811 * @rmtoll CR1 ALERT LL_I2C_EnableSMBusAlert 00812 * @param I2Cx I2C Instance. 00813 * @retval None 00814 */ 00815 __STATIC_INLINE void LL_I2C_EnableSMBusAlert(I2C_TypeDef *I2Cx) 00816 { 00817 SET_BIT(I2Cx->CR1, I2C_CR1_ALERT); 00818 } 00819 00820 /** 00821 * @brief Disable SMBus alert (Host or Device mode) 00822 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 00823 * SMBus feature is supported by the I2Cx Instance. 00824 * @note SMBus Device mode: 00825 * - SMBus Alert pin is not drived (can be used as a standard GPIO) and 00826 * Alert Response Address Header acknowledge is disabled. 00827 * SMBus Host mode: 00828 * - SMBus Alert pin management is not supported. 00829 * @rmtoll CR1 ALERT LL_I2C_DisableSMBusAlert 00830 * @param I2Cx I2C Instance. 00831 * @retval None 00832 */ 00833 __STATIC_INLINE void LL_I2C_DisableSMBusAlert(I2C_TypeDef *I2Cx) 00834 { 00835 CLEAR_BIT(I2Cx->CR1, I2C_CR1_ALERT); 00836 } 00837 00838 /** 00839 * @brief Check if SMBus alert (Host or Device mode) is enabled or disabled. 00840 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 00841 * SMBus feature is supported by the I2Cx Instance. 00842 * @rmtoll CR1 ALERT LL_I2C_IsEnabledSMBusAlert 00843 * @param I2Cx I2C Instance. 00844 * @retval State of bit (1 or 0). 00845 */ 00846 __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusAlert(I2C_TypeDef *I2Cx) 00847 { 00848 return (READ_BIT(I2Cx->CR1, I2C_CR1_ALERT) == (I2C_CR1_ALERT)); 00849 } 00850 00851 /** 00852 * @brief Enable SMBus Packet Error Calculation (PEC). 00853 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 00854 * SMBus feature is supported by the I2Cx Instance. 00855 * @rmtoll CR1 ENPEC LL_I2C_EnableSMBusPEC 00856 * @param I2Cx I2C Instance. 00857 * @retval None 00858 */ 00859 __STATIC_INLINE void LL_I2C_EnableSMBusPEC(I2C_TypeDef *I2Cx) 00860 { 00861 SET_BIT(I2Cx->CR1, I2C_CR1_ENPEC); 00862 } 00863 00864 /** 00865 * @brief Disable SMBus Packet Error Calculation (PEC). 00866 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 00867 * SMBus feature is supported by the I2Cx Instance. 00868 * @rmtoll CR1 ENPEC LL_I2C_DisableSMBusPEC 00869 * @param I2Cx I2C Instance. 00870 * @retval None 00871 */ 00872 __STATIC_INLINE void LL_I2C_DisableSMBusPEC(I2C_TypeDef *I2Cx) 00873 { 00874 CLEAR_BIT(I2Cx->CR1, I2C_CR1_ENPEC); 00875 } 00876 00877 /** 00878 * @brief Check if SMBus Packet Error Calculation (PEC) is enabled or disabled. 00879 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 00880 * SMBus feature is supported by the I2Cx Instance. 00881 * @rmtoll CR1 ENPEC LL_I2C_IsEnabledSMBusPEC 00882 * @param I2Cx I2C Instance. 00883 * @retval State of bit (1 or 0). 00884 */ 00885 __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusPEC(I2C_TypeDef *I2Cx) 00886 { 00887 return (READ_BIT(I2Cx->CR1, I2C_CR1_ENPEC) == (I2C_CR1_ENPEC)); 00888 } 00889 00890 /** 00891 * @} 00892 */ 00893 00894 /** @defgroup I2C_LL_EF_IT_Management IT_Management 00895 * @{ 00896 */ 00897 00898 /** 00899 * @brief Enable TXE interrupt. 00900 * @rmtoll CR2 ITEVTEN LL_I2C_EnableIT_TX\n 00901 * CR2 ITBUFEN LL_I2C_EnableIT_TX 00902 * @param I2Cx I2C Instance. 00903 * @retval None 00904 */ 00905 __STATIC_INLINE void LL_I2C_EnableIT_TX(I2C_TypeDef *I2Cx) 00906 { 00907 SET_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN); 00908 } 00909 00910 /** 00911 * @brief Disable TXE interrupt. 00912 * @rmtoll CR2 ITEVTEN LL_I2C_DisableIT_TX\n 00913 * CR2 ITBUFEN LL_I2C_DisableIT_TX 00914 * @param I2Cx I2C Instance. 00915 * @retval None 00916 */ 00917 __STATIC_INLINE void LL_I2C_DisableIT_TX(I2C_TypeDef *I2Cx) 00918 { 00919 CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN); 00920 } 00921 00922 /** 00923 * @brief Check if the TXE Interrupt is enabled or disabled. 00924 * @rmtoll CR2 ITEVTEN LL_I2C_IsEnabledIT_TX\n 00925 * CR2 ITBUFEN LL_I2C_IsEnabledIT_TX 00926 * @param I2Cx I2C Instance. 00927 * @retval State of bit (1 or 0). 00928 */ 00929 __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_TX(I2C_TypeDef *I2Cx) 00930 { 00931 return (READ_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN) == (I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN)); 00932 } 00933 00934 /** 00935 * @brief Enable RXNE interrupt. 00936 * @rmtoll CR2 ITEVTEN LL_I2C_EnableIT_RX\n 00937 * CR2 ITBUFEN LL_I2C_EnableIT_RX 00938 * @param I2Cx I2C Instance. 00939 * @retval None 00940 */ 00941 __STATIC_INLINE void LL_I2C_EnableIT_RX(I2C_TypeDef *I2Cx) 00942 { 00943 SET_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN); 00944 } 00945 00946 /** 00947 * @brief Disable RXNE interrupt. 00948 * @rmtoll CR2 ITEVTEN LL_I2C_DisableIT_RX\n 00949 * CR2 ITBUFEN LL_I2C_DisableIT_RX 00950 * @param I2Cx I2C Instance. 00951 * @retval None 00952 */ 00953 __STATIC_INLINE void LL_I2C_DisableIT_RX(I2C_TypeDef *I2Cx) 00954 { 00955 CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN); 00956 } 00957 00958 /** 00959 * @brief Check if the RXNE Interrupt is enabled or disabled. 00960 * @rmtoll CR2 ITEVTEN LL_I2C_IsEnabledIT_RX\n 00961 * CR2 ITBUFEN LL_I2C_IsEnabledIT_RX 00962 * @param I2Cx I2C Instance. 00963 * @retval State of bit (1 or 0). 00964 */ 00965 __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_RX(I2C_TypeDef *I2Cx) 00966 { 00967 return (READ_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN) == (I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN)); 00968 } 00969 00970 /** 00971 * @brief Enable Events interrupts. 00972 * @note Any of these events will generate interrupt : 00973 * Start Bit (SB) 00974 * Address sent, Address matched (ADDR) 00975 * 10-bit header sent (ADD10) 00976 * Stop detection (STOPF) 00977 * Byte transfer finished (BTF) 00978 * 00979 * @note Any of these events will generate interrupt if Buffer interrupts are enabled too(using unitary function @ref LL_I2C_EnableIT_BUF()) : 00980 * Receive buffer not empty (RXNE) 00981 * Transmit buffer empty (TXE) 00982 * @rmtoll CR2 ITEVTEN LL_I2C_EnableIT_EVT 00983 * @param I2Cx I2C Instance. 00984 * @retval None 00985 */ 00986 __STATIC_INLINE void LL_I2C_EnableIT_EVT(I2C_TypeDef *I2Cx) 00987 { 00988 SET_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN); 00989 } 00990 00991 /** 00992 * @brief Disable Events interrupts. 00993 * @note Any of these events will generate interrupt : 00994 * Start Bit (SB) 00995 * Address sent, Address matched (ADDR) 00996 * 10-bit header sent (ADD10) 00997 * Stop detection (STOPF) 00998 * Byte transfer finished (BTF) 00999 * Receive buffer not empty (RXNE) 01000 * Transmit buffer empty (TXE) 01001 * @rmtoll CR2 ITEVTEN LL_I2C_DisableIT_EVT 01002 * @param I2Cx I2C Instance. 01003 * @retval None 01004 */ 01005 __STATIC_INLINE void LL_I2C_DisableIT_EVT(I2C_TypeDef *I2Cx) 01006 { 01007 CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN); 01008 } 01009 01010 /** 01011 * @brief Check if Events interrupts are enabled or disabled. 01012 * @rmtoll CR2 ITEVTEN LL_I2C_IsEnabledIT_EVT 01013 * @param I2Cx I2C Instance. 01014 * @retval State of bit (1 or 0). 01015 */ 01016 __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_EVT(I2C_TypeDef *I2Cx) 01017 { 01018 return (READ_BIT(I2Cx->CR2, I2C_CR2_ITEVTEN) == (I2C_CR2_ITEVTEN)); 01019 } 01020 01021 /** 01022 * @brief Enable Buffer interrupts. 01023 * @note Any of these Buffer events will generate interrupt if Events interrupts are enabled too(using unitary function @ref LL_I2C_EnableIT_EVT()) : 01024 * Receive buffer not empty (RXNE) 01025 * Transmit buffer empty (TXE) 01026 * @rmtoll CR2 ITBUFEN LL_I2C_EnableIT_BUF 01027 * @param I2Cx I2C Instance. 01028 * @retval None 01029 */ 01030 __STATIC_INLINE void LL_I2C_EnableIT_BUF(I2C_TypeDef *I2Cx) 01031 { 01032 SET_BIT(I2Cx->CR2, I2C_CR2_ITBUFEN); 01033 } 01034 01035 /** 01036 * @brief Disable Buffer interrupts. 01037 * @note Any of these Buffer events will generate interrupt : 01038 * Receive buffer not empty (RXNE) 01039 * Transmit buffer empty (TXE) 01040 * @rmtoll CR2 ITBUFEN LL_I2C_DisableIT_BUF 01041 * @param I2Cx I2C Instance. 01042 * @retval None 01043 */ 01044 __STATIC_INLINE void LL_I2C_DisableIT_BUF(I2C_TypeDef *I2Cx) 01045 { 01046 CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITBUFEN); 01047 } 01048 01049 /** 01050 * @brief Check if Buffer interrupts are enabled or disabled. 01051 * @rmtoll CR2 ITBUFEN LL_I2C_IsEnabledIT_BUF 01052 * @param I2Cx I2C Instance. 01053 * @retval State of bit (1 or 0). 01054 */ 01055 __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_BUF(I2C_TypeDef *I2Cx) 01056 { 01057 return (READ_BIT(I2Cx->CR2, I2C_CR2_ITBUFEN) == (I2C_CR2_ITBUFEN)); 01058 } 01059 01060 /** 01061 * @brief Enable Error interrupts. 01062 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01063 * SMBus feature is supported by the I2Cx Instance. 01064 * @note Any of these errors will generate interrupt : 01065 * Bus Error detection (BERR) 01066 * Arbitration Loss (ARLO) 01067 * Acknowledge Failure(AF) 01068 * Overrun/Underrun (OVR) 01069 * SMBus Timeout detection (TIMEOUT) 01070 * SMBus PEC error detection (PECERR) 01071 * SMBus Alert pin event detection (SMBALERT) 01072 * @rmtoll CR2 ITERREN LL_I2C_EnableIT_ERR 01073 * @param I2Cx I2C Instance. 01074 * @retval None 01075 */ 01076 __STATIC_INLINE void LL_I2C_EnableIT_ERR(I2C_TypeDef *I2Cx) 01077 { 01078 SET_BIT(I2Cx->CR2, I2C_CR2_ITERREN); 01079 } 01080 01081 /** 01082 * @brief Disable Error interrupts. 01083 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01084 * SMBus feature is supported by the I2Cx Instance. 01085 * @note Any of these errors will generate interrupt : 01086 * Bus Error detection (BERR) 01087 * Arbitration Loss (ARLO) 01088 * Acknowledge Failure(AF) 01089 * Overrun/Underrun (OVR) 01090 * SMBus Timeout detection (TIMEOUT) 01091 * SMBus PEC error detection (PECERR) 01092 * SMBus Alert pin event detection (SMBALERT) 01093 * @rmtoll CR2 ITERREN LL_I2C_DisableIT_ERR 01094 * @param I2Cx I2C Instance. 01095 * @retval None 01096 */ 01097 __STATIC_INLINE void LL_I2C_DisableIT_ERR(I2C_TypeDef *I2Cx) 01098 { 01099 CLEAR_BIT(I2Cx->CR2, I2C_CR2_ITERREN); 01100 } 01101 01102 /** 01103 * @brief Check if Error interrupts are enabled or disabled. 01104 * @rmtoll CR2 ITERREN LL_I2C_IsEnabledIT_ERR 01105 * @param I2Cx I2C Instance. 01106 * @retval State of bit (1 or 0). 01107 */ 01108 __STATIC_INLINE uint32_t LL_I2C_IsEnabledIT_ERR(I2C_TypeDef *I2Cx) 01109 { 01110 return (READ_BIT(I2Cx->CR2, I2C_CR2_ITERREN) == (I2C_CR2_ITERREN)); 01111 } 01112 01113 /** 01114 * @} 01115 */ 01116 01117 /** @defgroup I2C_LL_EF_FLAG_management FLAG_management 01118 * @{ 01119 */ 01120 01121 /** 01122 * @brief Indicate the status of Transmit data register empty flag. 01123 * @note RESET: When next data is written in Transmit data register. 01124 * SET: When Transmit data register is empty. 01125 * @rmtoll SR1 TXE LL_I2C_IsActiveFlag_TXE 01126 * @param I2Cx I2C Instance. 01127 * @retval State of bit (1 or 0). 01128 */ 01129 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_TXE(I2C_TypeDef *I2Cx) 01130 { 01131 return (READ_BIT(I2Cx->SR1, I2C_SR1_TXE) == (I2C_SR1_TXE)); 01132 } 01133 01134 /** 01135 * @brief Indicate the status of Byte Transfer Finished flag. 01136 * RESET: When Data byte transfer not done. 01137 * SET: When Data byte transfer succeeded. 01138 * @rmtoll SR1 BTF LL_I2C_IsActiveFlag_BTF 01139 * @param I2Cx I2C Instance. 01140 * @retval State of bit (1 or 0). 01141 */ 01142 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BTF(I2C_TypeDef *I2Cx) 01143 { 01144 return (READ_BIT(I2Cx->SR1, I2C_SR1_BTF) == (I2C_SR1_BTF)); 01145 } 01146 01147 /** 01148 * @brief Indicate the status of Receive data register not empty flag. 01149 * @note RESET: When Receive data register is read. 01150 * SET: When the received data is copied in Receive data register. 01151 * @rmtoll SR1 RXNE LL_I2C_IsActiveFlag_RXNE 01152 * @param I2Cx I2C Instance. 01153 * @retval State of bit (1 or 0). 01154 */ 01155 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_RXNE(I2C_TypeDef *I2Cx) 01156 { 01157 return (READ_BIT(I2Cx->SR1, I2C_SR1_RXNE) == (I2C_SR1_RXNE)); 01158 } 01159 01160 /** 01161 * @brief Indicate the status of Start Bit (master mode). 01162 * @note RESET: When No Start condition. 01163 * SET: When Start condition is generated. 01164 * @rmtoll SR1 SB LL_I2C_IsActiveFlag_SB 01165 * @param I2Cx I2C Instance. 01166 * @retval State of bit (1 or 0). 01167 */ 01168 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_SB(I2C_TypeDef *I2Cx) 01169 { 01170 return (READ_BIT(I2Cx->SR1, I2C_SR1_SB) == (I2C_SR1_SB)); 01171 } 01172 01173 /** 01174 * @brief Indicate the status of Address sent (master mode) or Address matched flag (slave mode). 01175 * @note RESET: Clear default value. 01176 * SET: When the address is fully sent (master mode) or when the received slave address matched with one of the enabled slave address (slave mode). 01177 * @rmtoll SR1 ADDR LL_I2C_IsActiveFlag_ADDR 01178 * @param I2Cx I2C Instance. 01179 * @retval State of bit (1 or 0). 01180 */ 01181 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ADDR(I2C_TypeDef *I2Cx) 01182 { 01183 return (READ_BIT(I2Cx->SR1, I2C_SR1_ADDR) == (I2C_SR1_ADDR)); 01184 } 01185 01186 /** 01187 * @brief Indicate the status of 10-bit header sent (master mode). 01188 * @note RESET: When no ADD10 event occurred. 01189 * SET: When the master has sent the first address byte (header). 01190 * @rmtoll SR1 ADD10 LL_I2C_IsActiveFlag_ADD10 01191 * @param I2Cx I2C Instance. 01192 * @retval State of bit (1 or 0). 01193 */ 01194 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ADD10(I2C_TypeDef *I2Cx) 01195 { 01196 return (READ_BIT(I2Cx->SR1, I2C_SR1_ADD10) == (I2C_SR1_ADD10)); 01197 } 01198 01199 /** 01200 * @brief Indicate the status of Acknowledge failure flag. 01201 * @note RESET: No acknowledge failure. 01202 * SET: When an acknowledge failure is received after a byte transmission. 01203 * @rmtoll SR1 AF LL_I2C_IsActiveFlag_AF 01204 * @param I2Cx I2C Instance. 01205 * @retval State of bit (1 or 0). 01206 */ 01207 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_AF(I2C_TypeDef *I2Cx) 01208 { 01209 return (READ_BIT(I2Cx->SR1, I2C_SR1_AF) == (I2C_SR1_AF)); 01210 } 01211 01212 /** 01213 * @brief Indicate the status of Stop detection flag (slave mode). 01214 * @note RESET: Clear default value. 01215 * SET: When a Stop condition is detected. 01216 * @rmtoll SR1 STOPF LL_I2C_IsActiveFlag_STOP 01217 * @param I2Cx I2C Instance. 01218 * @retval State of bit (1 or 0). 01219 */ 01220 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_STOP(I2C_TypeDef *I2Cx) 01221 { 01222 return (READ_BIT(I2Cx->SR1, I2C_SR1_STOPF) == (I2C_SR1_STOPF)); 01223 } 01224 01225 /** 01226 * @brief Indicate the status of Bus error flag. 01227 * @note RESET: Clear default value. 01228 * SET: When a misplaced Start or Stop condition is detected. 01229 * @rmtoll SR1 BERR LL_I2C_IsActiveFlag_BERR 01230 * @param I2Cx I2C Instance. 01231 * @retval State of bit (1 or 0). 01232 */ 01233 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BERR(I2C_TypeDef *I2Cx) 01234 { 01235 return (READ_BIT(I2Cx->SR1, I2C_SR1_BERR) == (I2C_SR1_BERR)); 01236 } 01237 01238 /** 01239 * @brief Indicate the status of Arbitration lost flag. 01240 * @note RESET: Clear default value. 01241 * SET: When arbitration lost. 01242 * @rmtoll SR1 ARLO LL_I2C_IsActiveFlag_ARLO 01243 * @param I2Cx I2C Instance. 01244 * @retval State of bit (1 or 0). 01245 */ 01246 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_ARLO(I2C_TypeDef *I2Cx) 01247 { 01248 return (READ_BIT(I2Cx->SR1, I2C_SR1_ARLO) == (I2C_SR1_ARLO)); 01249 } 01250 01251 /** 01252 * @brief Indicate the status of Overrun/Underrun flag. 01253 * @note RESET: Clear default value. 01254 * SET: When an overrun/underrun error occurs (Clock Stretching Disabled). 01255 * @rmtoll SR1 OVR LL_I2C_IsActiveFlag_OVR 01256 * @param I2Cx I2C Instance. 01257 * @retval State of bit (1 or 0). 01258 */ 01259 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_OVR(I2C_TypeDef *I2Cx) 01260 { 01261 return (READ_BIT(I2Cx->SR1, I2C_SR1_OVR) == (I2C_SR1_OVR)); 01262 } 01263 01264 /** 01265 * @brief Indicate the status of SMBus PEC error flag in reception. 01266 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01267 * SMBus feature is supported by the I2Cx Instance. 01268 * @rmtoll SR1 PECERR LL_I2C_IsActiveSMBusFlag_PECERR 01269 * @param I2Cx I2C Instance. 01270 * @retval State of bit (1 or 0). 01271 */ 01272 __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_PECERR(I2C_TypeDef *I2Cx) 01273 { 01274 return (READ_BIT(I2Cx->SR1, I2C_SR1_PECERR) == (I2C_SR1_PECERR)); 01275 } 01276 01277 /** 01278 * @brief Indicate the status of SMBus Timeout detection flag. 01279 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01280 * SMBus feature is supported by the I2Cx Instance. 01281 * @rmtoll SR1 TIMEOUT LL_I2C_IsActiveSMBusFlag_TIMEOUT 01282 * @param I2Cx I2C Instance. 01283 * @retval State of bit (1 or 0). 01284 */ 01285 __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_TIMEOUT(I2C_TypeDef *I2Cx) 01286 { 01287 return (READ_BIT(I2Cx->SR1, I2C_SR1_TIMEOUT) == (I2C_SR1_TIMEOUT)); 01288 } 01289 01290 /** 01291 * @brief Indicate the status of SMBus alert flag. 01292 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01293 * SMBus feature is supported by the I2Cx Instance. 01294 * @rmtoll SR1 SMBALERT LL_I2C_IsActiveSMBusFlag_ALERT 01295 * @param I2Cx I2C Instance. 01296 * @retval State of bit (1 or 0). 01297 */ 01298 __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_ALERT(I2C_TypeDef *I2Cx) 01299 { 01300 return (READ_BIT(I2Cx->SR1, I2C_SR1_SMBALERT) == (I2C_SR1_SMBALERT)); 01301 } 01302 01303 /** 01304 * @brief Indicate the status of Bus Busy flag. 01305 * @note RESET: Clear default value. 01306 * SET: When a Start condition is detected. 01307 * @rmtoll SR2 BUSY LL_I2C_IsActiveFlag_BUSY 01308 * @param I2Cx I2C Instance. 01309 * @retval State of bit (1 or 0). 01310 */ 01311 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_BUSY(I2C_TypeDef *I2Cx) 01312 { 01313 return (READ_BIT(I2Cx->SR2, I2C_SR2_BUSY) == (I2C_SR2_BUSY)); 01314 } 01315 01316 /** 01317 * @brief Indicate the status of Dual flag. 01318 * @note RESET: Received address matched with OAR1. 01319 * SET: Received address matched with OAR2. 01320 * @rmtoll SR2 DUALF LL_I2C_IsActiveFlag_DUAL 01321 * @param I2Cx I2C Instance. 01322 * @retval State of bit (1 or 0). 01323 */ 01324 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_DUAL(I2C_TypeDef *I2Cx) 01325 { 01326 return (READ_BIT(I2Cx->SR2, I2C_SR2_DUALF) == (I2C_SR2_DUALF)); 01327 } 01328 01329 /** 01330 * @brief Indicate the status of SMBus Host address reception (Slave mode). 01331 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01332 * SMBus feature is supported by the I2Cx Instance. 01333 * @note RESET: No SMBus Host address 01334 * SET: SMBus Host address received. 01335 * @note This status is cleared by hardware after a STOP condition or repeated START condition. 01336 * @rmtoll SR2 SMBHOST LL_I2C_IsActiveSMBusFlag_SMBHOST 01337 * @param I2Cx I2C Instance. 01338 * @retval State of bit (1 or 0). 01339 */ 01340 __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_SMBHOST(I2C_TypeDef *I2Cx) 01341 { 01342 return (READ_BIT(I2Cx->SR2, I2C_SR2_SMBHOST) == (I2C_SR2_SMBHOST)); 01343 } 01344 01345 /** 01346 * @brief Indicate the status of SMBus Device default address reception (Slave mode). 01347 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01348 * SMBus feature is supported by the I2Cx Instance. 01349 * @note RESET: No SMBus Device default address 01350 * SET: SMBus Device default address received. 01351 * @note This status is cleared by hardware after a STOP condition or repeated START condition. 01352 * @rmtoll SR2 SMBDEFAULT LL_I2C_IsActiveSMBusFlag_SMBDEFAULT 01353 * @param I2Cx I2C Instance. 01354 * @retval State of bit (1 or 0). 01355 */ 01356 __STATIC_INLINE uint32_t LL_I2C_IsActiveSMBusFlag_SMBDEFAULT(I2C_TypeDef *I2Cx) 01357 { 01358 return (READ_BIT(I2Cx->SR2, I2C_SR2_SMBDEFAULT) == (I2C_SR2_SMBDEFAULT)); 01359 } 01360 01361 /** 01362 * @brief Indicate the status of General call address reception (Slave mode). 01363 * @note RESET: No General call address 01364 * SET: General call address received. 01365 * @note This status is cleared by hardware after a STOP condition or repeated START condition. 01366 * @rmtoll SR2 GENCALL LL_I2C_IsActiveFlag_GENCALL 01367 * @param I2Cx I2C Instance. 01368 * @retval State of bit (1 or 0). 01369 */ 01370 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_GENCALL(I2C_TypeDef *I2Cx) 01371 { 01372 return (READ_BIT(I2Cx->SR2, I2C_SR2_GENCALL) == (I2C_SR2_GENCALL)); 01373 } 01374 01375 /** 01376 * @brief Indicate the status of Master/Slave flag. 01377 * @note RESET: Slave Mode. 01378 * SET: Master Mode. 01379 * @rmtoll SR2 MSL LL_I2C_IsActiveFlag_MSL 01380 * @param I2Cx I2C Instance. 01381 * @retval State of bit (1 or 0). 01382 */ 01383 __STATIC_INLINE uint32_t LL_I2C_IsActiveFlag_MSL(I2C_TypeDef *I2Cx) 01384 { 01385 return (READ_BIT(I2Cx->SR2, I2C_SR2_MSL) == (I2C_SR2_MSL)); 01386 } 01387 01388 /** 01389 * @brief Clear Address Matched flag. 01390 * @note Clearing this flag is done by a read access to the I2Cx_SR1 01391 * register followed by a read access to the I2Cx_SR2 register. 01392 * @rmtoll SR1 ADDR LL_I2C_ClearFlag_ADDR 01393 * @param I2Cx I2C Instance. 01394 * @retval None 01395 */ 01396 __STATIC_INLINE void LL_I2C_ClearFlag_ADDR(I2C_TypeDef *I2Cx) 01397 { 01398 __IO uint32_t tmpreg; 01399 tmpreg = I2Cx->SR1; 01400 (void) tmpreg; 01401 tmpreg = I2Cx->SR2; 01402 (void) tmpreg; 01403 } 01404 01405 /** 01406 * @brief Clear Acknowledge failure flag. 01407 * @rmtoll SR1 AF LL_I2C_ClearFlag_AF 01408 * @param I2Cx I2C Instance. 01409 * @retval None 01410 */ 01411 __STATIC_INLINE void LL_I2C_ClearFlag_AF(I2C_TypeDef *I2Cx) 01412 { 01413 CLEAR_BIT(I2Cx->SR1, I2C_SR1_AF); 01414 } 01415 01416 /** 01417 * @brief Clear Stop detection flag. 01418 * @note Clearing this flag is done by a read access to the I2Cx_SR1 01419 * register followed by a write access to I2Cx_CR1 register. 01420 * @rmtoll SR1 STOPF LL_I2C_ClearFlag_STOP\n 01421 * CR1 PE LL_I2C_ClearFlag_STOP 01422 * @param I2Cx I2C Instance. 01423 * @retval None 01424 */ 01425 __STATIC_INLINE void LL_I2C_ClearFlag_STOP(I2C_TypeDef *I2Cx) 01426 { 01427 __IO uint32_t tmpreg; 01428 tmpreg = I2Cx->SR1; 01429 (void) tmpreg; 01430 SET_BIT(I2Cx->CR1, I2C_CR1_PE); 01431 } 01432 01433 /** 01434 * @brief Clear Bus error flag. 01435 * @rmtoll SR1 BERR LL_I2C_ClearFlag_BERR 01436 * @param I2Cx I2C Instance. 01437 * @retval None 01438 */ 01439 __STATIC_INLINE void LL_I2C_ClearFlag_BERR(I2C_TypeDef *I2Cx) 01440 { 01441 CLEAR_BIT(I2Cx->SR1, I2C_SR1_BERR); 01442 } 01443 01444 /** 01445 * @brief Clear Arbitration lost flag. 01446 * @rmtoll SR1 ARLO LL_I2C_ClearFlag_ARLO 01447 * @param I2Cx I2C Instance. 01448 * @retval None 01449 */ 01450 __STATIC_INLINE void LL_I2C_ClearFlag_ARLO(I2C_TypeDef *I2Cx) 01451 { 01452 CLEAR_BIT(I2Cx->SR1, I2C_SR1_ARLO); 01453 } 01454 01455 /** 01456 * @brief Clear Overrun/Underrun flag. 01457 * @rmtoll SR1 OVR LL_I2C_ClearFlag_OVR 01458 * @param I2Cx I2C Instance. 01459 * @retval None 01460 */ 01461 __STATIC_INLINE void LL_I2C_ClearFlag_OVR(I2C_TypeDef *I2Cx) 01462 { 01463 CLEAR_BIT(I2Cx->SR1, I2C_SR1_OVR); 01464 } 01465 01466 /** 01467 * @brief Clear SMBus PEC error flag. 01468 * @rmtoll SR1 PECERR LL_I2C_ClearSMBusFlag_PECERR 01469 * @param I2Cx I2C Instance. 01470 * @retval None 01471 */ 01472 __STATIC_INLINE void LL_I2C_ClearSMBusFlag_PECERR(I2C_TypeDef *I2Cx) 01473 { 01474 CLEAR_BIT(I2Cx->SR1, I2C_SR1_PECERR); 01475 } 01476 01477 /** 01478 * @brief Clear SMBus Timeout detection flag. 01479 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01480 * SMBus feature is supported by the I2Cx Instance. 01481 * @rmtoll SR1 TIMEOUT LL_I2C_ClearSMBusFlag_TIMEOUT 01482 * @param I2Cx I2C Instance. 01483 * @retval None 01484 */ 01485 __STATIC_INLINE void LL_I2C_ClearSMBusFlag_TIMEOUT(I2C_TypeDef *I2Cx) 01486 { 01487 CLEAR_BIT(I2Cx->SR1, I2C_SR1_TIMEOUT); 01488 } 01489 01490 /** 01491 * @brief Clear SMBus Alert flag. 01492 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01493 * SMBus feature is supported by the I2Cx Instance. 01494 * @rmtoll SR1 SMBALERT LL_I2C_ClearSMBusFlag_ALERT 01495 * @param I2Cx I2C Instance. 01496 * @retval None 01497 */ 01498 __STATIC_INLINE void LL_I2C_ClearSMBusFlag_ALERT(I2C_TypeDef *I2Cx) 01499 { 01500 CLEAR_BIT(I2Cx->SR1, I2C_SR1_SMBALERT); 01501 } 01502 01503 /** 01504 * @} 01505 */ 01506 01507 /** @defgroup I2C_LL_EF_Data_Management Data_Management 01508 * @{ 01509 */ 01510 01511 /** 01512 * @brief Enable Reset of I2C peripheral. 01513 * @rmtoll CR1 SWRST LL_I2C_EnableReset 01514 * @param I2Cx I2C Instance. 01515 * @retval None 01516 */ 01517 __STATIC_INLINE void LL_I2C_EnableReset(I2C_TypeDef *I2Cx) 01518 { 01519 SET_BIT(I2Cx->CR1, I2C_CR1_SWRST); 01520 } 01521 01522 /** 01523 * @brief Disable Reset of I2C peripheral. 01524 * @rmtoll CR1 SWRST LL_I2C_DisableReset 01525 * @param I2Cx I2C Instance. 01526 * @retval None 01527 */ 01528 __STATIC_INLINE void LL_I2C_DisableReset(I2C_TypeDef *I2Cx) 01529 { 01530 CLEAR_BIT(I2Cx->CR1, I2C_CR1_SWRST); 01531 } 01532 01533 /** 01534 * @brief Check if the I2C peripheral is under reset state or not. 01535 * @rmtoll CR1 SWRST LL_I2C_IsResetEnabled 01536 * @param I2Cx I2C Instance. 01537 * @retval State of bit (1 or 0). 01538 */ 01539 __STATIC_INLINE uint32_t LL_I2C_IsResetEnabled(I2C_TypeDef *I2Cx) 01540 { 01541 return (READ_BIT(I2Cx->CR1, I2C_CR1_SWRST) == (I2C_CR1_SWRST)); 01542 } 01543 01544 /** 01545 * @brief Prepare the generation of a ACKnowledge or Non ACKnowledge condition after the address receive match code or next received byte. 01546 * @note Usage in Slave or Master mode. 01547 * @rmtoll CR1 ACK LL_I2C_AcknowledgeNextData 01548 * @param I2Cx I2C Instance. 01549 * @param TypeAcknowledge This parameter can be one of the following values: 01550 * @arg @ref LL_I2C_ACK 01551 * @arg @ref LL_I2C_NACK 01552 * @retval None 01553 */ 01554 __STATIC_INLINE void LL_I2C_AcknowledgeNextData(I2C_TypeDef *I2Cx, uint32_t TypeAcknowledge) 01555 { 01556 MODIFY_REG(I2Cx->CR1, I2C_CR1_ACK, TypeAcknowledge); 01557 } 01558 01559 /** 01560 * @brief Generate a START or RESTART condition 01561 * @note The START bit can be set even if bus is BUSY or I2C is in slave mode. 01562 * This action has no effect when RELOAD is set. 01563 * @rmtoll CR1 START LL_I2C_GenerateStartCondition 01564 * @param I2Cx I2C Instance. 01565 * @retval None 01566 */ 01567 __STATIC_INLINE void LL_I2C_GenerateStartCondition(I2C_TypeDef *I2Cx) 01568 { 01569 SET_BIT(I2Cx->CR1, I2C_CR1_START); 01570 } 01571 01572 /** 01573 * @brief Generate a STOP condition after the current byte transfer (master mode). 01574 * @rmtoll CR1 STOP LL_I2C_GenerateStopCondition 01575 * @param I2Cx I2C Instance. 01576 * @retval None 01577 */ 01578 __STATIC_INLINE void LL_I2C_GenerateStopCondition(I2C_TypeDef *I2Cx) 01579 { 01580 SET_BIT(I2Cx->CR1, I2C_CR1_STOP); 01581 } 01582 01583 /** 01584 * @brief Enable bit POS (master/host mode). 01585 * @note In that case, the ACK bit controls the (N)ACK of the next byte received or the PEC bit indicates that the next byte in shift register is a PEC. 01586 * @rmtoll CR1 POS LL_I2C_EnableBitPOS 01587 * @param I2Cx I2C Instance. 01588 * @retval None 01589 */ 01590 __STATIC_INLINE void LL_I2C_EnableBitPOS(I2C_TypeDef *I2Cx) 01591 { 01592 SET_BIT(I2Cx->CR1, I2C_CR1_POS); 01593 } 01594 01595 /** 01596 * @brief Disable bit POS (master/host mode). 01597 * @note In that case, the ACK bit controls the (N)ACK of the current byte received or the PEC bit indicates that the current byte in shift register is a PEC. 01598 * @rmtoll CR1 POS LL_I2C_DisableBitPOS 01599 * @param I2Cx I2C Instance. 01600 * @retval None 01601 */ 01602 __STATIC_INLINE void LL_I2C_DisableBitPOS(I2C_TypeDef *I2Cx) 01603 { 01604 CLEAR_BIT(I2Cx->CR1, I2C_CR1_POS); 01605 } 01606 01607 /** 01608 * @brief Check if bit POS is enabled or disabled. 01609 * @rmtoll CR1 POS LL_I2C_IsEnabledBitPOS 01610 * @param I2Cx I2C Instance. 01611 * @retval State of bit (1 or 0). 01612 */ 01613 __STATIC_INLINE uint32_t LL_I2C_IsEnabledBitPOS(I2C_TypeDef *I2Cx) 01614 { 01615 return (READ_BIT(I2Cx->CR1, I2C_CR1_POS) == (I2C_CR1_POS)); 01616 } 01617 01618 /** 01619 * @brief Indicate the value of transfer direction. 01620 * @note RESET: Bus is in read transfer (peripheral point of view). 01621 * SET: Bus is in write transfer (peripheral point of view). 01622 * @rmtoll SR2 TRA LL_I2C_GetTransferDirection 01623 * @param I2Cx I2C Instance. 01624 * @retval Returned value can be one of the following values: 01625 * @arg @ref LL_I2C_DIRECTION_WRITE 01626 * @arg @ref LL_I2C_DIRECTION_READ 01627 */ 01628 __STATIC_INLINE uint32_t LL_I2C_GetTransferDirection(I2C_TypeDef *I2Cx) 01629 { 01630 return (uint32_t)(READ_BIT(I2Cx->SR2, I2C_SR2_TRA)); 01631 } 01632 01633 /** 01634 * @brief Enable DMA last transfer. 01635 * @note This action mean that next DMA EOT is the last transfer. 01636 * @rmtoll CR2 LAST LL_I2C_EnableLastDMA 01637 * @param I2Cx I2C Instance. 01638 * @retval None 01639 */ 01640 __STATIC_INLINE void LL_I2C_EnableLastDMA(I2C_TypeDef *I2Cx) 01641 { 01642 SET_BIT(I2Cx->CR2, I2C_CR2_LAST); 01643 } 01644 01645 /** 01646 * @brief Disable DMA last transfer. 01647 * @note This action mean that next DMA EOT is not the last transfer. 01648 * @rmtoll CR2 LAST LL_I2C_DisableLastDMA 01649 * @param I2Cx I2C Instance. 01650 * @retval None 01651 */ 01652 __STATIC_INLINE void LL_I2C_DisableLastDMA(I2C_TypeDef *I2Cx) 01653 { 01654 CLEAR_BIT(I2Cx->CR2, I2C_CR2_LAST); 01655 } 01656 01657 /** 01658 * @brief Check if DMA last transfer is enabled or disabled. 01659 * @rmtoll CR2 LAST LL_I2C_IsEnabledLastDMA 01660 * @param I2Cx I2C Instance. 01661 * @retval State of bit (1 or 0). 01662 */ 01663 __STATIC_INLINE uint32_t LL_I2C_IsEnabledLastDMA(I2C_TypeDef *I2Cx) 01664 { 01665 return (READ_BIT(I2Cx->CR2, I2C_CR2_LAST) == (I2C_CR2_LAST)); 01666 } 01667 01668 /** 01669 * @brief Enable transfer or internal comparison of the SMBus Packet Error byte (transmission or reception mode). 01670 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01671 * SMBus feature is supported by the I2Cx Instance. 01672 * @note This feature is cleared by hardware when the PEC byte is transferred or compared, 01673 * or by a START or STOP condition, it is also cleared by software. 01674 * @rmtoll CR1 PEC LL_I2C_EnableSMBusPECCompare 01675 * @param I2Cx I2C Instance. 01676 * @retval None 01677 */ 01678 __STATIC_INLINE void LL_I2C_EnableSMBusPECCompare(I2C_TypeDef *I2Cx) 01679 { 01680 SET_BIT(I2Cx->CR1, I2C_CR1_PEC); 01681 } 01682 01683 /** 01684 * @brief Disable transfer or internal comparison of the SMBus Packet Error byte (transmission or reception mode). 01685 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01686 * SMBus feature is supported by the I2Cx Instance. 01687 * @rmtoll CR1 PEC LL_I2C_DisableSMBusPECCompare 01688 * @param I2Cx I2C Instance. 01689 * @retval None 01690 */ 01691 __STATIC_INLINE void LL_I2C_DisableSMBusPECCompare(I2C_TypeDef *I2Cx) 01692 { 01693 CLEAR_BIT(I2Cx->CR1, I2C_CR1_PEC); 01694 } 01695 01696 /** 01697 * @brief Check if the SMBus Packet Error byte transfer or internal comparison is requested or not. 01698 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01699 * SMBus feature is supported by the I2Cx Instance. 01700 * @rmtoll CR1 PEC LL_I2C_IsEnabledSMBusPECCompare 01701 * @param I2Cx I2C Instance. 01702 * @retval State of bit (1 or 0). 01703 */ 01704 __STATIC_INLINE uint32_t LL_I2C_IsEnabledSMBusPECCompare(I2C_TypeDef *I2Cx) 01705 { 01706 return (READ_BIT(I2Cx->CR1, I2C_CR1_PEC) == (I2C_CR1_PEC)); 01707 } 01708 01709 /** 01710 * @brief Get the SMBus Packet Error byte calculated. 01711 * @note Macro @ref IS_SMBUS_ALL_INSTANCE(I2Cx) can be used to check whether or not 01712 * SMBus feature is supported by the I2Cx Instance. 01713 * @rmtoll SR2 PEC LL_I2C_GetSMBusPEC 01714 * @param I2Cx I2C Instance. 01715 * @retval Value between Min_Data=0x00 and Max_Data=0xFF 01716 */ 01717 __STATIC_INLINE uint32_t LL_I2C_GetSMBusPEC(I2C_TypeDef *I2Cx) 01718 { 01719 return (uint32_t)(READ_BIT(I2Cx->SR2, I2C_SR2_PEC) >> I2C_SR2_PEC_Pos); 01720 } 01721 01722 /** 01723 * @brief Read Receive Data register. 01724 * @rmtoll DR DR LL_I2C_ReceiveData8 01725 * @param I2Cx I2C Instance. 01726 * @retval Value between Min_Data=0x0 and Max_Data=0xFF 01727 */ 01728 __STATIC_INLINE uint8_t LL_I2C_ReceiveData8(I2C_TypeDef *I2Cx) 01729 { 01730 return (uint8_t)(READ_BIT(I2Cx->DR, I2C_DR_DR)); 01731 } 01732 01733 /** 01734 * @brief Write in Transmit Data Register . 01735 * @rmtoll DR DR LL_I2C_TransmitData8 01736 * @param I2Cx I2C Instance. 01737 * @param Data Value between Min_Data=0x0 and Max_Data=0xFF 01738 * @retval None 01739 */ 01740 __STATIC_INLINE void LL_I2C_TransmitData8(I2C_TypeDef *I2Cx, uint8_t Data) 01741 { 01742 MODIFY_REG(I2Cx->DR, I2C_DR_DR, Data); 01743 } 01744 01745 /** 01746 * @} 01747 */ 01748 01749 #if defined(USE_FULL_LL_DRIVER) 01750 /** @defgroup I2C_LL_EF_Init Initialization and de-initialization functions 01751 * @{ 01752 */ 01753 01754 uint32_t LL_I2C_Init(I2C_TypeDef *I2Cx, LL_I2C_InitTypeDef *I2C_InitStruct); 01755 uint32_t LL_I2C_DeInit(I2C_TypeDef *I2Cx); 01756 void LL_I2C_StructInit(LL_I2C_InitTypeDef *I2C_InitStruct); 01757 01758 01759 /** 01760 * @} 01761 */ 01762 #endif /* USE_FULL_LL_DRIVER */ 01763 01764 /** 01765 * @} 01766 */ 01767 01768 /** 01769 * @} 01770 */ 01771 01772 #endif /* I2C1 || I2C2 */ 01773 01774 /** 01775 * @} 01776 */ 01777 01778 #ifdef __cplusplus 01779 } 01780 #endif 01781 01782 #endif /* __STM32F1xx_LL_I2C_H */ 01783 01784 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/