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