STM32F439xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_hal_i2c.h 00004 * @author MCD Application Team 00005 * @brief Header file of I2C HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 00036 /* Define to prevent recursive inclusion -------------------------------------*/ 00037 #ifndef __STM32F4xx_HAL_I2C_H 00038 #define __STM32F4xx_HAL_I2C_H 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00044 /* Includes ------------------------------------------------------------------*/ 00045 #include "stm32f4xx_hal_def.h" 00046 00047 /** @addtogroup STM32F4xx_HAL_Driver 00048 * @{ 00049 */ 00050 00051 /** @addtogroup I2C 00052 * @{ 00053 */ 00054 00055 /* Exported types ------------------------------------------------------------*/ 00056 /** @defgroup I2C_Exported_Types I2C Exported Types 00057 * @{ 00058 */ 00059 00060 /** 00061 * @brief I2C Configuration Structure definition 00062 */ 00063 typedef struct 00064 { 00065 uint32_t ClockSpeed; /*!< Specifies the clock frequency. 00066 This parameter must be set to a value lower than 400kHz */ 00067 00068 uint32_t DutyCycle; /*!< Specifies the I2C fast mode duty cycle. 00069 This parameter can be a value of @ref I2C_duty_cycle_in_fast_mode */ 00070 00071 uint32_t OwnAddress1; /*!< Specifies the first device own address. 00072 This parameter can be a 7-bit or 10-bit address. */ 00073 00074 uint32_t AddressingMode; /*!< Specifies if 7-bit or 10-bit addressing mode is selected. 00075 This parameter can be a value of @ref I2C_addressing_mode */ 00076 00077 uint32_t DualAddressMode; /*!< Specifies if dual addressing mode is selected. 00078 This parameter can be a value of @ref I2C_dual_addressing_mode */ 00079 00080 uint32_t OwnAddress2; /*!< Specifies the second device own address if dual addressing mode is selected 00081 This parameter can be a 7-bit address. */ 00082 00083 uint32_t GeneralCallMode; /*!< Specifies if general call mode is selected. 00084 This parameter can be a value of @ref I2C_general_call_addressing_mode */ 00085 00086 uint32_t NoStretchMode; /*!< Specifies if nostretch mode is selected. 00087 This parameter can be a value of @ref I2C_nostretch_mode */ 00088 00089 }I2C_InitTypeDef; 00090 00091 /** 00092 * @brief HAL State structure definition 00093 * @note HAL I2C State value coding follow below described bitmap : 00094 * b7-b6 Error information 00095 * 00 : No Error 00096 * 01 : Abort (Abort user request on going) 00097 * 10 : Timeout 00098 * 11 : Error 00099 * b5 IP initilisation status 00100 * 0 : Reset (IP not initialized) 00101 * 1 : Init done (IP initialized and ready to use. HAL I2C Init function called) 00102 * b4 (not used) 00103 * x : Should be set to 0 00104 * b3 00105 * 0 : Ready or Busy (No Listen mode ongoing) 00106 * 1 : Listen (IP in Address Listen Mode) 00107 * b2 Intrinsic process state 00108 * 0 : Ready 00109 * 1 : Busy (IP busy with some configuration or internal operations) 00110 * b1 Rx state 00111 * 0 : Ready (no Rx operation ongoing) 00112 * 1 : Busy (Rx operation ongoing) 00113 * b0 Tx state 00114 * 0 : Ready (no Tx operation ongoing) 00115 * 1 : Busy (Tx operation ongoing) 00116 */ 00117 typedef enum 00118 { 00119 HAL_I2C_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized */ 00120 HAL_I2C_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use */ 00121 HAL_I2C_STATE_BUSY = 0x24U, /*!< An internal process is ongoing */ 00122 HAL_I2C_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing */ 00123 HAL_I2C_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */ 00124 HAL_I2C_STATE_LISTEN = 0x28U, /*!< Address Listen Mode is ongoing */ 00125 HAL_I2C_STATE_BUSY_TX_LISTEN = 0x29U, /*!< Address Listen Mode and Data Transmission 00126 process is ongoing */ 00127 HAL_I2C_STATE_BUSY_RX_LISTEN = 0x2AU, /*!< Address Listen Mode and Data Reception 00128 process is ongoing */ 00129 HAL_I2C_STATE_ABORT = 0x60U, /*!< Abort user request ongoing */ 00130 HAL_I2C_STATE_TIMEOUT = 0xA0U, /*!< Timeout state */ 00131 HAL_I2C_STATE_ERROR = 0xE0U /*!< Error */ 00132 00133 }HAL_I2C_StateTypeDef; 00134 00135 /** 00136 * @brief HAL Mode structure definition 00137 * @note HAL I2C Mode value coding follow below described bitmap : 00138 * b7 (not used) 00139 * x : Should be set to 0 00140 * b6 00141 * 0 : None 00142 * 1 : Memory (HAL I2C communication is in Memory Mode) 00143 * b5 00144 * 0 : None 00145 * 1 : Slave (HAL I2C communication is in Slave Mode) 00146 * b4 00147 * 0 : None 00148 * 1 : Master (HAL I2C communication is in Master Mode) 00149 * b3-b2-b1-b0 (not used) 00150 * xxxx : Should be set to 0000 00151 */ 00152 typedef enum 00153 { 00154 HAL_I2C_MODE_NONE = 0x00U, /*!< No I2C communication on going */ 00155 HAL_I2C_MODE_MASTER = 0x10U, /*!< I2C communication is in Master Mode */ 00156 HAL_I2C_MODE_SLAVE = 0x20U, /*!< I2C communication is in Slave Mode */ 00157 HAL_I2C_MODE_MEM = 0x40U /*!< I2C communication is in Memory Mode */ 00158 00159 }HAL_I2C_ModeTypeDef; 00160 00161 /** 00162 * @brief I2C handle Structure definition 00163 */ 00164 typedef struct 00165 { 00166 I2C_TypeDef *Instance; /*!< I2C registers base address */ 00167 00168 I2C_InitTypeDef Init; /*!< I2C communication parameters */ 00169 00170 uint8_t *pBuffPtr; /*!< Pointer to I2C transfer buffer */ 00171 00172 uint16_t XferSize; /*!< I2C transfer size */ 00173 00174 __IO uint16_t XferCount; /*!< I2C transfer counter */ 00175 00176 __IO uint32_t XferOptions; /*!< I2C transfer options */ 00177 00178 __IO uint32_t PreviousState; /*!< I2C communication Previous state and mode 00179 context for internal usage */ 00180 00181 DMA_HandleTypeDef *hdmatx; /*!< I2C Tx DMA handle parameters */ 00182 00183 DMA_HandleTypeDef *hdmarx; /*!< I2C Rx DMA handle parameters */ 00184 00185 HAL_LockTypeDef Lock; /*!< I2C locking object */ 00186 00187 __IO HAL_I2C_StateTypeDef State; /*!< I2C communication state */ 00188 00189 __IO HAL_I2C_ModeTypeDef Mode; /*!< I2C communication mode */ 00190 00191 __IO uint32_t ErrorCode; /*!< I2C Error code */ 00192 00193 __IO uint32_t Devaddress; /*!< I2C Target device address */ 00194 00195 __IO uint32_t Memaddress; /*!< I2C Target memory address */ 00196 00197 __IO uint32_t MemaddSize; /*!< I2C Target memory address size */ 00198 00199 __IO uint32_t EventCount; /*!< I2C Event counter */ 00200 00201 }I2C_HandleTypeDef; 00202 00203 /** 00204 * @} 00205 */ 00206 00207 /* Exported constants --------------------------------------------------------*/ 00208 /** @defgroup I2C_Exported_Constants I2C Exported Constants 00209 * @{ 00210 */ 00211 00212 /** @defgroup I2C_Error_Code I2C Error Code 00213 * @brief I2C Error Code 00214 * @{ 00215 */ 00216 #define HAL_I2C_ERROR_NONE 0x00000000U /*!< No error */ 00217 #define HAL_I2C_ERROR_BERR 0x00000001U /*!< BERR error */ 00218 #define HAL_I2C_ERROR_ARLO 0x00000002U /*!< ARLO error */ 00219 #define HAL_I2C_ERROR_AF 0x00000004U /*!< AF error */ 00220 #define HAL_I2C_ERROR_OVR 0x00000008U /*!< OVR error */ 00221 #define HAL_I2C_ERROR_DMA 0x00000010U /*!< DMA transfer error */ 00222 #define HAL_I2C_ERROR_TIMEOUT 0x00000020U /*!< Timeout Error */ 00223 /** 00224 * @} 00225 */ 00226 00227 /** @defgroup I2C_duty_cycle_in_fast_mode I2C duty cycle in fast mode 00228 * @{ 00229 */ 00230 #define I2C_DUTYCYCLE_2 0x00000000U 00231 #define I2C_DUTYCYCLE_16_9 I2C_CCR_DUTY 00232 /** 00233 * @} 00234 */ 00235 00236 /** @defgroup I2C_addressing_mode I2C addressing mode 00237 * @{ 00238 */ 00239 #define I2C_ADDRESSINGMODE_7BIT 0x00004000U 00240 #define I2C_ADDRESSINGMODE_10BIT (I2C_OAR1_ADDMODE | 0x00004000U) 00241 /** 00242 * @} 00243 */ 00244 00245 /** @defgroup I2C_dual_addressing_mode I2C dual addressing mode 00246 * @{ 00247 */ 00248 #define I2C_DUALADDRESS_DISABLE 0x00000000U 00249 #define I2C_DUALADDRESS_ENABLE I2C_OAR2_ENDUAL 00250 /** 00251 * @} 00252 */ 00253 00254 /** @defgroup I2C_general_call_addressing_mode I2C general call addressing mode 00255 * @{ 00256 */ 00257 #define I2C_GENERALCALL_DISABLE 0x00000000U 00258 #define I2C_GENERALCALL_ENABLE I2C_CR1_ENGC 00259 /** 00260 * @} 00261 */ 00262 00263 /** @defgroup I2C_nostretch_mode I2C nostretch mode 00264 * @{ 00265 */ 00266 #define I2C_NOSTRETCH_DISABLE 0x00000000U 00267 #define I2C_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH 00268 /** 00269 * @} 00270 */ 00271 00272 /** @defgroup I2C_Memory_Address_Size I2C Memory Address Size 00273 * @{ 00274 */ 00275 #define I2C_MEMADD_SIZE_8BIT 0x00000001U 00276 #define I2C_MEMADD_SIZE_16BIT 0x00000010U 00277 /** 00278 * @} 00279 */ 00280 00281 /** @defgroup I2C_XferDirection_definition I2C XferDirection definition 00282 * @{ 00283 */ 00284 #define I2C_DIRECTION_RECEIVE 0x00000000U 00285 #define I2C_DIRECTION_TRANSMIT 0x00000001U 00286 /** 00287 * @} 00288 */ 00289 00290 /** @defgroup I2C_XferOptions_definition I2C XferOptions definition 00291 * @{ 00292 */ 00293 #define I2C_FIRST_FRAME 0x00000001U 00294 #define I2C_NEXT_FRAME 0x00000002U 00295 #define I2C_FIRST_AND_LAST_FRAME 0x00000004U 00296 #define I2C_LAST_FRAME 0x00000008U 00297 /** 00298 * @} 00299 */ 00300 00301 /** @defgroup I2C_Interrupt_configuration_definition I2C Interrupt configuration definition 00302 * @{ 00303 */ 00304 #define I2C_IT_BUF I2C_CR2_ITBUFEN 00305 #define I2C_IT_EVT I2C_CR2_ITEVTEN 00306 #define I2C_IT_ERR I2C_CR2_ITERREN 00307 /** 00308 * @} 00309 */ 00310 00311 /** @defgroup I2C_Flag_definition I2C Flag definition 00312 * @{ 00313 */ 00314 #define I2C_FLAG_SMBALERT 0x00018000U 00315 #define I2C_FLAG_TIMEOUT 0x00014000U 00316 #define I2C_FLAG_PECERR 0x00011000U 00317 #define I2C_FLAG_OVR 0x00010800U 00318 #define I2C_FLAG_AF 0x00010400U 00319 #define I2C_FLAG_ARLO 0x00010200U 00320 #define I2C_FLAG_BERR 0x00010100U 00321 #define I2C_FLAG_TXE 0x00010080U 00322 #define I2C_FLAG_RXNE 0x00010040U 00323 #define I2C_FLAG_STOPF 0x00010010U 00324 #define I2C_FLAG_ADD10 0x00010008U 00325 #define I2C_FLAG_BTF 0x00010004U 00326 #define I2C_FLAG_ADDR 0x00010002U 00327 #define I2C_FLAG_SB 0x00010001U 00328 #define I2C_FLAG_DUALF 0x00100080U 00329 #define I2C_FLAG_SMBHOST 0x00100040U 00330 #define I2C_FLAG_SMBDEFAULT 0x00100020U 00331 #define I2C_FLAG_GENCALL 0x00100010U 00332 #define I2C_FLAG_TRA 0x00100004U 00333 #define I2C_FLAG_BUSY 0x00100002U 00334 #define I2C_FLAG_MSL 0x00100001U 00335 /** 00336 * @} 00337 */ 00338 00339 /** 00340 * @} 00341 */ 00342 00343 /* Exported macro ------------------------------------------------------------*/ 00344 /** @defgroup I2C_Exported_Macros I2C Exported Macros 00345 * @{ 00346 */ 00347 00348 /** @brief Reset I2C handle state 00349 * @param __HANDLE__ specifies the I2C Handle. 00350 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral. 00351 * @retval None 00352 */ 00353 #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET) 00354 00355 /** @brief Enable or disable the specified I2C interrupts. 00356 * @param __HANDLE__ specifies the I2C Handle. 00357 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral. 00358 * @param __INTERRUPT__ specifies the interrupt source to enable or disable. 00359 * This parameter can be one of the following values: 00360 * @arg I2C_IT_BUF: Buffer interrupt enable 00361 * @arg I2C_IT_EVT: Event interrupt enable 00362 * @arg I2C_IT_ERR: Error interrupt enable 00363 * @retval None 00364 */ 00365 #define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__)) 00366 #define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 &= (~(__INTERRUPT__))) 00367 00368 /** @brief Checks if the specified I2C interrupt source is enabled or disabled. 00369 * @param __HANDLE__ specifies the I2C Handle. 00370 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral. 00371 * @param __INTERRUPT__ specifies the I2C interrupt source to check. 00372 * This parameter can be one of the following values: 00373 * @arg I2C_IT_BUF: Buffer interrupt enable 00374 * @arg I2C_IT_EVT: Event interrupt enable 00375 * @arg I2C_IT_ERR: Error interrupt enable 00376 * @retval The new state of __INTERRUPT__ (TRUE or FALSE). 00377 */ 00378 #define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) 00379 00380 /** @brief Checks whether the specified I2C flag is set or not. 00381 * @param __HANDLE__ specifies the I2C Handle. 00382 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral. 00383 * @param __FLAG__ specifies the flag to check. 00384 * This parameter can be one of the following values: 00385 * @arg I2C_FLAG_SMBALERT: SMBus Alert flag 00386 * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag 00387 * @arg I2C_FLAG_PECERR: PEC error in reception flag 00388 * @arg I2C_FLAG_OVR: Overrun/Underrun flag 00389 * @arg I2C_FLAG_AF: Acknowledge failure flag 00390 * @arg I2C_FLAG_ARLO: Arbitration lost flag 00391 * @arg I2C_FLAG_BERR: Bus error flag 00392 * @arg I2C_FLAG_TXE: Data register empty flag 00393 * @arg I2C_FLAG_RXNE: Data register not empty flag 00394 * @arg I2C_FLAG_STOPF: Stop detection flag 00395 * @arg I2C_FLAG_ADD10: 10-bit header sent flag 00396 * @arg I2C_FLAG_BTF: Byte transfer finished flag 00397 * @arg I2C_FLAG_ADDR: Address sent flag 00398 * Address matched flag 00399 * @arg I2C_FLAG_SB: Start bit flag 00400 * @arg I2C_FLAG_DUALF: Dual flag 00401 * @arg I2C_FLAG_SMBHOST: SMBus host header 00402 * @arg I2C_FLAG_SMBDEFAULT: SMBus default header 00403 * @arg I2C_FLAG_GENCALL: General call header flag 00404 * @arg I2C_FLAG_TRA: Transmitter/Receiver flag 00405 * @arg I2C_FLAG_BUSY: Bus busy flag 00406 * @arg I2C_FLAG_MSL: Master/Slave flag 00407 * @retval The new state of __FLAG__ (TRUE or FALSE). 00408 */ 00409 #define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16U)) == 0x01U)?((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)): \ 00410 ((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK))) 00411 00412 /** @brief Clears the I2C pending flags which are cleared by writing 0 in a specific bit. 00413 * @param __HANDLE__ specifies the I2C Handle. 00414 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral. 00415 * @param __FLAG__ specifies the flag to clear. 00416 * This parameter can be any combination of the following values: 00417 * @arg I2C_FLAG_SMBALERT: SMBus Alert flag 00418 * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag 00419 * @arg I2C_FLAG_PECERR: PEC error in reception flag 00420 * @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode) 00421 * @arg I2C_FLAG_AF: Acknowledge failure flag 00422 * @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode) 00423 * @arg I2C_FLAG_BERR: Bus error flag 00424 * @retval None 00425 */ 00426 #define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR1 = ~((__FLAG__) & I2C_FLAG_MASK)) 00427 00428 /** @brief Clears the I2C ADDR pending flag. 00429 * @param __HANDLE__ specifies the I2C Handle. 00430 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral. 00431 * @retval None 00432 */ 00433 #define __HAL_I2C_CLEAR_ADDRFLAG(__HANDLE__) \ 00434 do{ \ 00435 __IO uint32_t tmpreg = 0x00U; \ 00436 tmpreg = (__HANDLE__)->Instance->SR1; \ 00437 tmpreg = (__HANDLE__)->Instance->SR2; \ 00438 UNUSED(tmpreg); \ 00439 } while(0) 00440 00441 /** @brief Clears the I2C STOPF pending flag. 00442 * @param __HANDLE__ specifies the I2C Handle. 00443 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral. 00444 * @retval None 00445 */ 00446 #define __HAL_I2C_CLEAR_STOPFLAG(__HANDLE__) \ 00447 do{ \ 00448 __IO uint32_t tmpreg = 0x00U; \ 00449 tmpreg = (__HANDLE__)->Instance->SR1; \ 00450 (__HANDLE__)->Instance->CR1 |= I2C_CR1_PE; \ 00451 UNUSED(tmpreg); \ 00452 } while(0) 00453 00454 /** @brief Enable the I2C peripheral. 00455 * @param __HANDLE__ specifies the I2C Handle. 00456 * This parameter can be I2Cx where x: 1 or 2 to select the I2C peripheral. 00457 * @retval None 00458 */ 00459 #define __HAL_I2C_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= I2C_CR1_PE) 00460 00461 /** @brief Disable the I2C peripheral. 00462 * @param __HANDLE__ specifies the I2C Handle. 00463 * This parameter can be I2Cx where x: 1 or 2 to select the I2C peripheral. 00464 * @retval None 00465 */ 00466 #define __HAL_I2C_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~I2C_CR1_PE) 00467 00468 /** 00469 * @} 00470 */ 00471 00472 /* Include I2C HAL Extension module */ 00473 #include "stm32f4xx_hal_i2c_ex.h" 00474 00475 /* Exported functions --------------------------------------------------------*/ 00476 /** @addtogroup I2C_Exported_Functions 00477 * @{ 00478 */ 00479 00480 /** @addtogroup I2C_Exported_Functions_Group1 00481 * @{ 00482 */ 00483 /* Initialization/de-initialization functions **********************************/ 00484 HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c); 00485 HAL_StatusTypeDef HAL_I2C_DeInit (I2C_HandleTypeDef *hi2c); 00486 void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c); 00487 void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c); 00488 /** 00489 * @} 00490 */ 00491 00492 /** @addtogroup I2C_Exported_Functions_Group2 00493 * @{ 00494 */ 00495 /* I/O operation functions *****************************************************/ 00496 /******* Blocking mode: Polling */ 00497 HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout); 00498 HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout); 00499 HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout); 00500 HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout); 00501 HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout); 00502 HAL_StatusTypeDef HAL_I2C_Mem_Read(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout); 00503 HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout); 00504 00505 /******* Non-Blocking mode: Interrupt */ 00506 HAL_StatusTypeDef HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); 00507 HAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); 00508 HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); 00509 HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); 00510 HAL_StatusTypeDef HAL_I2C_Mem_Write_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); 00511 HAL_StatusTypeDef HAL_I2C_Mem_Read_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); 00512 00513 HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions); 00514 HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions); 00515 HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions); 00516 HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions); 00517 HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress); 00518 HAL_StatusTypeDef HAL_I2C_EnableListen_IT(I2C_HandleTypeDef *hi2c); 00519 HAL_StatusTypeDef HAL_I2C_DisableListen_IT(I2C_HandleTypeDef *hi2c); 00520 00521 /******* Non-Blocking mode: DMA */ 00522 HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); 00523 HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); 00524 HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); 00525 HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); 00526 HAL_StatusTypeDef HAL_I2C_Mem_Write_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); 00527 HAL_StatusTypeDef HAL_I2C_Mem_Read_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); 00528 00529 /******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */ 00530 void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c); 00531 void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c); 00532 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c); 00533 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c); 00534 void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c); 00535 void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c); 00536 void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode); 00537 void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c); 00538 void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c); 00539 void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c); 00540 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c); 00541 void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c); 00542 /** 00543 * @} 00544 */ 00545 00546 /** @addtogroup I2C_Exported_Functions_Group3 00547 * @{ 00548 */ 00549 /* Peripheral State, Mode and Errors functions *********************************/ 00550 HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c); 00551 HAL_I2C_ModeTypeDef HAL_I2C_GetMode(I2C_HandleTypeDef *hi2c); 00552 uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c); 00553 00554 /** 00555 * @} 00556 */ 00557 00558 /** 00559 * @} 00560 */ 00561 /* Private types -------------------------------------------------------------*/ 00562 /* Private variables ---------------------------------------------------------*/ 00563 /* Private constants ---------------------------------------------------------*/ 00564 /** @defgroup I2C_Private_Constants I2C Private Constants 00565 * @{ 00566 */ 00567 #define I2C_FLAG_MASK 0x0000FFFFU 00568 /** 00569 * @} 00570 */ 00571 00572 /* Private macros ------------------------------------------------------------*/ 00573 /** @defgroup I2C_Private_Macros I2C Private Macros 00574 * @{ 00575 */ 00576 00577 #define I2C_FREQRANGE(__PCLK__) ((__PCLK__)/1000000U) 00578 #define I2C_RISE_TIME(__FREQRANGE__, __SPEED__) (((__SPEED__) <= 100000U) ? ((__FREQRANGE__) + 1U) : ((((__FREQRANGE__) * 300U) / 1000U) + 1U)) 00579 #define I2C_SPEED_STANDARD(__PCLK__, __SPEED__) (((((__PCLK__)/((__SPEED__) << 1U)) & I2C_CCR_CCR) < 4U)? 4U:((__PCLK__) / ((__SPEED__) << 1U))) 00580 #define I2C_SPEED_FAST(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__DUTYCYCLE__) == I2C_DUTYCYCLE_2)? ((__PCLK__) / ((__SPEED__) * 3U)) : (((__PCLK__) / ((__SPEED__) * 25U)) | I2C_DUTYCYCLE_16_9)) 00581 #define I2C_SPEED(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__SPEED__) <= 100000U)? (I2C_SPEED_STANDARD((__PCLK__), (__SPEED__))) : \ 00582 ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__)) & I2C_CCR_CCR) == 0U)? 1U : \ 00583 ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__))) | I2C_CCR_FS)) 00584 00585 #define I2C_7BIT_ADD_WRITE(__ADDRESS__) ((uint8_t)((__ADDRESS__) & (~I2C_OAR1_ADD0))) 00586 #define I2C_7BIT_ADD_READ(__ADDRESS__) ((uint8_t)((__ADDRESS__) | I2C_OAR1_ADD0)) 00587 00588 #define I2C_10BIT_ADDRESS(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)0x00FF))) 00589 #define I2C_10BIT_HEADER_WRITE(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0x0300)) >> 7) | (uint16_t)0x00F0))) 00590 #define I2C_10BIT_HEADER_READ(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0x0300)) >> 7) | (uint16_t)(0x00F1)))) 00591 00592 #define I2C_MEM_ADD_MSB(__ADDRESS__) ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0xFF00)) >> 8))) 00593 #define I2C_MEM_ADD_LSB(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)0x00FF))) 00594 00595 /** @defgroup I2C_IS_RTC_Definitions I2C Private macros to check input parameters 00596 * @{ 00597 */ 00598 #define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DUTYCYCLE_2) || \ 00599 ((CYCLE) == I2C_DUTYCYCLE_16_9)) 00600 #define IS_I2C_ADDRESSING_MODE(ADDRESS) (((ADDRESS) == I2C_ADDRESSINGMODE_7BIT) || \ 00601 ((ADDRESS) == I2C_ADDRESSINGMODE_10BIT)) 00602 #define IS_I2C_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == I2C_DUALADDRESS_DISABLE) || \ 00603 ((ADDRESS) == I2C_DUALADDRESS_ENABLE)) 00604 #define IS_I2C_GENERAL_CALL(CALL) (((CALL) == I2C_GENERALCALL_DISABLE) || \ 00605 ((CALL) == I2C_GENERALCALL_ENABLE)) 00606 #define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLE) || \ 00607 ((STRETCH) == I2C_NOSTRETCH_ENABLE)) 00608 #define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \ 00609 ((SIZE) == I2C_MEMADD_SIZE_16BIT)) 00610 #define IS_I2C_CLOCK_SPEED(SPEED) (((SPEED) > 0U) && ((SPEED) <= 400000U)) 00611 #define IS_I2C_OWN_ADDRESS1(ADDRESS1) (((ADDRESS1) & 0xFFFFFC00U) == 0U) 00612 #define IS_I2C_OWN_ADDRESS2(ADDRESS2) (((ADDRESS2) & 0xFFFFFF01U) == 0U) 00613 #define IS_I2C_TRANSFER_OPTIONS_REQUEST(REQUEST) (((REQUEST) == I2C_FIRST_FRAME) || \ 00614 ((REQUEST) == I2C_NEXT_FRAME) || \ 00615 ((REQUEST) == I2C_FIRST_AND_LAST_FRAME) || \ 00616 ((REQUEST) == I2C_LAST_FRAME)) 00617 /** 00618 * @} 00619 */ 00620 00621 /** 00622 * @} 00623 */ 00624 00625 /* Private functions ---------------------------------------------------------*/ 00626 /** @defgroup I2C_Private_Functions I2C Private Functions 00627 * @{ 00628 */ 00629 00630 /** 00631 * @} 00632 */ 00633 00634 /** 00635 * @} 00636 */ 00637 00638 /** 00639 * @} 00640 */ 00641 00642 #ifdef __cplusplus 00643 } 00644 #endif 00645 00646 00647 #endif /* __STM32F4xx_HAL_I2C_H */ 00648 00649 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/