2 ******************************************************************************
3 * @file stm32f4xx_hal_i2c.h
4 * @author MCD Application Team
7 * @brief Header file of I2C HAL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_HAL_I2C_H
40 #define __STM32F4xx_HAL_I2C_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal_def.h"
49 /** @addtogroup STM32F4xx_HAL_Driver
57 /* Exported types ------------------------------------------------------------*/
58 /** @defgroup I2C_Exported_Types I2C Exported Types
63 * @brief I2C Configuration Structure definition
67 uint32_t ClockSpeed
; /*!< Specifies the clock frequency.
68 This parameter must be set to a value lower than 400kHz */
70 uint32_t DutyCycle
; /*!< Specifies the I2C fast mode duty cycle.
71 This parameter can be a value of @ref I2C_duty_cycle_in_fast_mode */
73 uint32_t OwnAddress1
; /*!< Specifies the first device own address.
74 This parameter can be a 7-bit or 10-bit address. */
76 uint32_t AddressingMode
; /*!< Specifies if 7-bit or 10-bit addressing mode is selected.
77 This parameter can be a value of @ref I2C_addressing_mode */
79 uint32_t DualAddressMode
; /*!< Specifies if dual addressing mode is selected.
80 This parameter can be a value of @ref I2C_dual_addressing_mode */
82 uint32_t OwnAddress2
; /*!< Specifies the second device own address if dual addressing mode is selected
83 This parameter can be a 7-bit address. */
85 uint32_t GeneralCallMode
; /*!< Specifies if general call mode is selected.
86 This parameter can be a value of @ref I2C_general_call_addressing_mode */
88 uint32_t NoStretchMode
; /*!< Specifies if nostretch mode is selected.
89 This parameter can be a value of @ref I2C_nostretch_mode */
94 * @brief HAL State structure definition
95 * @note HAL I2C State value coding follow below described bitmap :
96 * b7-b6 Error information
98 * 01 : Abort (Abort user request on going)
101 * b5 IP initilisation status
102 * 0 : Reset (IP not initialized)
103 * 1 : Init done (IP initialized and ready to use. HAL I2C Init function called)
105 * x : Should be set to 0
107 * 0 : Ready or Busy (No Listen mode ongoing)
108 * 1 : Listen (IP in Address Listen Mode)
109 * b2 Intrinsic process state
111 * 1 : Busy (IP busy with some configuration or internal operations)
113 * 0 : Ready (no Rx operation ongoing)
114 * 1 : Busy (Rx operation ongoing)
116 * 0 : Ready (no Tx operation ongoing)
117 * 1 : Busy (Tx operation ongoing)
121 HAL_I2C_STATE_RESET
= 0x00U
, /*!< Peripheral is not yet Initialized */
122 HAL_I2C_STATE_READY
= 0x20U
, /*!< Peripheral Initialized and ready for use */
123 HAL_I2C_STATE_BUSY
= 0x24U
, /*!< An internal process is ongoing */
124 HAL_I2C_STATE_BUSY_TX
= 0x21U
, /*!< Data Transmission process is ongoing */
125 HAL_I2C_STATE_BUSY_RX
= 0x22U
, /*!< Data Reception process is ongoing */
126 HAL_I2C_STATE_LISTEN
= 0x28U
, /*!< Address Listen Mode is ongoing */
127 HAL_I2C_STATE_BUSY_TX_LISTEN
= 0x29U
, /*!< Address Listen Mode and Data Transmission
128 process is ongoing */
129 HAL_I2C_STATE_BUSY_RX_LISTEN
= 0x2AU
, /*!< Address Listen Mode and Data Reception
130 process is ongoing */
131 HAL_I2C_STATE_ABORT
= 0x60U
, /*!< Abort user request ongoing */
132 HAL_I2C_STATE_TIMEOUT
= 0xA0U
, /*!< Timeout state */
133 HAL_I2C_STATE_ERROR
= 0xE0U
/*!< Error */
135 }HAL_I2C_StateTypeDef
;
138 * @brief HAL Mode structure definition
139 * @note HAL I2C Mode value coding follow below described bitmap :
141 * x : Should be set to 0
144 * 1 : Memory (HAL I2C communication is in Memory Mode)
147 * 1 : Slave (HAL I2C communication is in Slave Mode)
150 * 1 : Master (HAL I2C communication is in Master Mode)
151 * b3-b2-b1-b0 (not used)
152 * xxxx : Should be set to 0000
156 HAL_I2C_MODE_NONE
= 0x00U
, /*!< No I2C communication on going */
157 HAL_I2C_MODE_MASTER
= 0x10U
, /*!< I2C communication is in Master Mode */
158 HAL_I2C_MODE_SLAVE
= 0x20U
, /*!< I2C communication is in Slave Mode */
159 HAL_I2C_MODE_MEM
= 0x40U
/*!< I2C communication is in Memory Mode */
161 }HAL_I2C_ModeTypeDef
;
164 * @brief I2C handle Structure definition
168 I2C_TypeDef
*Instance
; /*!< I2C registers base address */
170 I2C_InitTypeDef Init
; /*!< I2C communication parameters */
172 uint8_t *pBuffPtr
; /*!< Pointer to I2C transfer buffer */
174 uint16_t XferSize
; /*!< I2C transfer size */
176 __IO
uint16_t XferCount
; /*!< I2C transfer counter */
178 __IO
uint32_t XferOptions
; /*!< I2C transfer options */
180 __IO
uint32_t PreviousState
; /*!< I2C communication Previous state and mode
181 context for internal usage */
183 DMA_HandleTypeDef
*hdmatx
; /*!< I2C Tx DMA handle parameters */
185 DMA_HandleTypeDef
*hdmarx
; /*!< I2C Rx DMA handle parameters */
187 HAL_LockTypeDef Lock
; /*!< I2C locking object */
189 __IO HAL_I2C_StateTypeDef State
; /*!< I2C communication state */
191 __IO HAL_I2C_ModeTypeDef Mode
; /*!< I2C communication mode */
193 __IO
uint32_t ErrorCode
; /*!< I2C Error code */
195 __IO
uint32_t Devaddress
; /*!< I2C Target device address */
197 __IO
uint32_t Memaddress
; /*!< I2C Target memory address */
199 __IO
uint32_t MemaddSize
; /*!< I2C Target memory address size */
201 __IO
uint32_t EventCount
; /*!< I2C Event counter */
209 /* Exported constants --------------------------------------------------------*/
210 /** @defgroup I2C_Exported_Constants I2C Exported Constants
214 /** @defgroup I2C_Error_Code I2C Error Code
215 * @brief I2C Error Code
218 #define HAL_I2C_ERROR_NONE 0x00000000U /*!< No error */
219 #define HAL_I2C_ERROR_BERR 0x00000001U /*!< BERR error */
220 #define HAL_I2C_ERROR_ARLO 0x00000002U /*!< ARLO error */
221 #define HAL_I2C_ERROR_AF 0x00000004U /*!< AF error */
222 #define HAL_I2C_ERROR_OVR 0x00000008U /*!< OVR error */
223 #define HAL_I2C_ERROR_DMA 0x00000010U /*!< DMA transfer error */
224 #define HAL_I2C_ERROR_TIMEOUT 0x00000020U /*!< Timeout Error */
229 /** @defgroup I2C_duty_cycle_in_fast_mode I2C duty cycle in fast mode
232 #define I2C_DUTYCYCLE_2 0x00000000U
233 #define I2C_DUTYCYCLE_16_9 I2C_CCR_DUTY
238 /** @defgroup I2C_addressing_mode I2C addressing mode
241 #define I2C_ADDRESSINGMODE_7BIT 0x00004000U
242 #define I2C_ADDRESSINGMODE_10BIT (I2C_OAR1_ADDMODE | 0x00004000U)
247 /** @defgroup I2C_dual_addressing_mode I2C dual addressing mode
250 #define I2C_DUALADDRESS_DISABLE 0x00000000U
251 #define I2C_DUALADDRESS_ENABLE I2C_OAR2_ENDUAL
256 /** @defgroup I2C_general_call_addressing_mode I2C general call addressing mode
259 #define I2C_GENERALCALL_DISABLE 0x00000000U
260 #define I2C_GENERALCALL_ENABLE I2C_CR1_ENGC
265 /** @defgroup I2C_nostretch_mode I2C nostretch mode
268 #define I2C_NOSTRETCH_DISABLE 0x00000000U
269 #define I2C_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH
274 /** @defgroup I2C_Memory_Address_Size I2C Memory Address Size
277 #define I2C_MEMADD_SIZE_8BIT 0x00000001U
278 #define I2C_MEMADD_SIZE_16BIT 0x00000010U
283 /** @defgroup I2C_XferDirection_definition I2C XferDirection definition
286 #define I2C_DIRECTION_RECEIVE 0x00000000U
287 #define I2C_DIRECTION_TRANSMIT 0x00000001U
292 /** @defgroup I2C_XferOptions_definition I2C XferOptions definition
295 #define I2C_FIRST_FRAME 0x00000001U
296 #define I2C_NEXT_FRAME 0x00000002U
297 #define I2C_FIRST_AND_LAST_FRAME 0x00000004U
298 #define I2C_LAST_FRAME 0x00000008U
303 /** @defgroup I2C_Interrupt_configuration_definition I2C Interrupt configuration definition
306 #define I2C_IT_BUF I2C_CR2_ITBUFEN
307 #define I2C_IT_EVT I2C_CR2_ITEVTEN
308 #define I2C_IT_ERR I2C_CR2_ITERREN
313 /** @defgroup I2C_Flag_definition I2C Flag definition
316 #define I2C_FLAG_SMBALERT 0x00018000U
317 #define I2C_FLAG_TIMEOUT 0x00014000U
318 #define I2C_FLAG_PECERR 0x00011000U
319 #define I2C_FLAG_OVR 0x00010800U
320 #define I2C_FLAG_AF 0x00010400U
321 #define I2C_FLAG_ARLO 0x00010200U
322 #define I2C_FLAG_BERR 0x00010100U
323 #define I2C_FLAG_TXE 0x00010080U
324 #define I2C_FLAG_RXNE 0x00010040U
325 #define I2C_FLAG_STOPF 0x00010010U
326 #define I2C_FLAG_ADD10 0x00010008U
327 #define I2C_FLAG_BTF 0x00010004U
328 #define I2C_FLAG_ADDR 0x00010002U
329 #define I2C_FLAG_SB 0x00010001U
330 #define I2C_FLAG_DUALF 0x00100080U
331 #define I2C_FLAG_SMBHOST 0x00100040U
332 #define I2C_FLAG_SMBDEFAULT 0x00100020U
333 #define I2C_FLAG_GENCALL 0x00100010U
334 #define I2C_FLAG_TRA 0x00100004U
335 #define I2C_FLAG_BUSY 0x00100002U
336 #define I2C_FLAG_MSL 0x00100001U
345 /* Exported macro ------------------------------------------------------------*/
346 /** @defgroup I2C_Exported_Macros I2C Exported Macros
350 /** @brief Reset I2C handle state
351 * @param __HANDLE__: specifies the I2C Handle.
352 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
355 #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET)
357 /** @brief Enable or disable the specified I2C interrupts.
358 * @param __HANDLE__: specifies the I2C Handle.
359 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
360 * @param __INTERRUPT__: specifies the interrupt source to enable or disable.
361 * This parameter can be one of the following values:
362 * @arg I2C_IT_BUF: Buffer interrupt enable
363 * @arg I2C_IT_EVT: Event interrupt enable
364 * @arg I2C_IT_ERR: Error interrupt enable
367 #define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__))
368 #define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 &= (~(__INTERRUPT__)))
370 /** @brief Checks if the specified I2C interrupt source is enabled or disabled.
371 * @param __HANDLE__: specifies the I2C Handle.
372 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
373 * @param __INTERRUPT__: specifies the I2C interrupt source to check.
374 * This parameter can be one of the following values:
375 * @arg I2C_IT_BUF: Buffer interrupt enable
376 * @arg I2C_IT_EVT: Event interrupt enable
377 * @arg I2C_IT_ERR: Error interrupt enable
378 * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
380 #define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
382 /** @brief Checks whether the specified I2C flag is set or not.
383 * @param __HANDLE__: specifies the I2C Handle.
384 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
385 * @param __FLAG__: specifies the flag to check.
386 * This parameter can be one of the following values:
387 * @arg I2C_FLAG_SMBALERT: SMBus Alert flag
388 * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
389 * @arg I2C_FLAG_PECERR: PEC error in reception flag
390 * @arg I2C_FLAG_OVR: Overrun/Underrun flag
391 * @arg I2C_FLAG_AF: Acknowledge failure flag
392 * @arg I2C_FLAG_ARLO: Arbitration lost flag
393 * @arg I2C_FLAG_BERR: Bus error flag
394 * @arg I2C_FLAG_TXE: Data register empty flag
395 * @arg I2C_FLAG_RXNE: Data register not empty flag
396 * @arg I2C_FLAG_STOPF: Stop detection flag
397 * @arg I2C_FLAG_ADD10: 10-bit header sent flag
398 * @arg I2C_FLAG_BTF: Byte transfer finished flag
399 * @arg I2C_FLAG_ADDR: Address sent flag
400 * Address matched flag
401 * @arg I2C_FLAG_SB: Start bit flag
402 * @arg I2C_FLAG_DUALF: Dual flag
403 * @arg I2C_FLAG_SMBHOST: SMBus host header
404 * @arg I2C_FLAG_SMBDEFAULT: SMBus default header
405 * @arg I2C_FLAG_GENCALL: General call header flag
406 * @arg I2C_FLAG_TRA: Transmitter/Receiver flag
407 * @arg I2C_FLAG_BUSY: Bus busy flag
408 * @arg I2C_FLAG_MSL: Master/Slave flag
409 * @retval The new state of __FLAG__ (TRUE or FALSE).
411 #define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16U)) == 0x01U)?((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)): \
412 ((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)))
414 /** @brief Clears the I2C pending flags which are cleared by writing 0 in a specific bit.
415 * @param __HANDLE__: specifies the I2C Handle.
416 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
417 * @param __FLAG__: specifies the flag to clear.
418 * This parameter can be any combination of the following values:
419 * @arg I2C_FLAG_SMBALERT: SMBus Alert flag
420 * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
421 * @arg I2C_FLAG_PECERR: PEC error in reception flag
422 * @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
423 * @arg I2C_FLAG_AF: Acknowledge failure flag
424 * @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
425 * @arg I2C_FLAG_BERR: Bus error flag
428 #define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR1 = ~((__FLAG__) & I2C_FLAG_MASK))
430 /** @brief Clears the I2C ADDR pending flag.
431 * @param __HANDLE__: specifies the I2C Handle.
432 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
435 #define __HAL_I2C_CLEAR_ADDRFLAG(__HANDLE__) \
437 __IO uint32_t tmpreg = 0x00U; \
438 tmpreg = (__HANDLE__)->Instance->SR1; \
439 tmpreg = (__HANDLE__)->Instance->SR2; \
443 /** @brief Clears the I2C STOPF pending flag.
444 * @param __HANDLE__: specifies the I2C Handle.
445 * This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral.
448 #define __HAL_I2C_CLEAR_STOPFLAG(__HANDLE__) \
450 __IO uint32_t tmpreg = 0x00U; \
451 tmpreg = (__HANDLE__)->Instance->SR1; \
452 (__HANDLE__)->Instance->CR1 |= I2C_CR1_PE; \
456 /** @brief Enable the I2C peripheral.
457 * @param __HANDLE__: specifies the I2C Handle.
458 * This parameter can be I2Cx where x: 1 or 2 to select the I2C peripheral.
461 #define __HAL_I2C_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= I2C_CR1_PE)
463 /** @brief Disable the I2C peripheral.
464 * @param __HANDLE__: specifies the I2C Handle.
465 * This parameter can be I2Cx where x: 1 or 2 to select the I2C peripheral.
468 #define __HAL_I2C_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~I2C_CR1_PE)
474 /* Include I2C HAL Extension module */
475 #include "stm32f4xx_hal_i2c_ex.h"
477 /* Exported functions --------------------------------------------------------*/
478 /** @addtogroup I2C_Exported_Functions
482 /** @addtogroup I2C_Exported_Functions_Group1
485 /* Initialization/de-initialization functions **********************************/
486 HAL_StatusTypeDef
HAL_I2C_Init(I2C_HandleTypeDef
*hi2c
);
487 HAL_StatusTypeDef
HAL_I2C_DeInit (I2C_HandleTypeDef
*hi2c
);
488 void HAL_I2C_MspInit(I2C_HandleTypeDef
*hi2c
);
489 void HAL_I2C_MspDeInit(I2C_HandleTypeDef
*hi2c
);
494 /** @addtogroup I2C_Exported_Functions_Group2
497 /* I/O operation functions *****************************************************/
498 /******* Blocking mode: Polling */
499 HAL_StatusTypeDef
HAL_I2C_Master_Transmit(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
);
500 HAL_StatusTypeDef
HAL_I2C_Master_Receive(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
);
501 HAL_StatusTypeDef
HAL_I2C_Slave_Transmit(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
);
502 HAL_StatusTypeDef
HAL_I2C_Slave_Receive(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
);
503 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
);
504 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
);
505 HAL_StatusTypeDef
HAL_I2C_IsDeviceReady(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint32_t Trials
, uint32_t Timeout
);
507 /******* Non-Blocking mode: Interrupt */
508 HAL_StatusTypeDef
HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
);
509 HAL_StatusTypeDef
HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
);
510 HAL_StatusTypeDef
HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
);
511 HAL_StatusTypeDef
HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
);
512 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
);
513 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
);
515 HAL_StatusTypeDef
HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
, uint32_t XferOptions
);
516 HAL_StatusTypeDef
HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
, uint32_t XferOptions
);
517 HAL_StatusTypeDef
HAL_I2C_Slave_Sequential_Transmit_IT(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
, uint32_t XferOptions
);
518 HAL_StatusTypeDef
HAL_I2C_Slave_Sequential_Receive_IT(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
, uint32_t XferOptions
);
519 HAL_StatusTypeDef
HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
);
520 HAL_StatusTypeDef
HAL_I2C_EnableListen_IT(I2C_HandleTypeDef
*hi2c
);
521 HAL_StatusTypeDef
HAL_I2C_DisableListen_IT(I2C_HandleTypeDef
*hi2c
);
523 /******* Non-Blocking mode: DMA */
524 HAL_StatusTypeDef
HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
);
525 HAL_StatusTypeDef
HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
);
526 HAL_StatusTypeDef
HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
);
527 HAL_StatusTypeDef
HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
);
528 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
);
529 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
);
531 /******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
532 void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef
*hi2c
);
533 void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef
*hi2c
);
534 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef
*hi2c
);
535 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef
*hi2c
);
536 void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef
*hi2c
);
537 void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef
*hi2c
);
538 void HAL_I2C_AddrCallback(I2C_HandleTypeDef
*hi2c
, uint8_t TransferDirection
, uint16_t AddrMatchCode
);
539 void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef
*hi2c
);
540 void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef
*hi2c
);
541 void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef
*hi2c
);
542 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef
*hi2c
);
543 void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef
*hi2c
);
548 /** @addtogroup I2C_Exported_Functions_Group3
551 /* Peripheral State, Mode and Errors functions *********************************/
552 HAL_I2C_StateTypeDef
HAL_I2C_GetState(I2C_HandleTypeDef
*hi2c
);
553 HAL_I2C_ModeTypeDef
HAL_I2C_GetMode(I2C_HandleTypeDef
*hi2c
);
554 uint32_t HAL_I2C_GetError(I2C_HandleTypeDef
*hi2c
);
563 /* Private types -------------------------------------------------------------*/
564 /* Private variables ---------------------------------------------------------*/
565 /* Private constants ---------------------------------------------------------*/
566 /** @defgroup I2C_Private_Constants I2C Private Constants
569 #define I2C_FLAG_MASK 0x0000FFFFU
574 /* Private macros ------------------------------------------------------------*/
575 /** @defgroup I2C_Private_Macros I2C Private Macros
579 #define I2C_FREQRANGE(__PCLK__) ((__PCLK__)/1000000U)
580 #define I2C_RISE_TIME(__FREQRANGE__, __SPEED__) (((__SPEED__) <= 100000U) ? ((__FREQRANGE__) + 1U) : ((((__FREQRANGE__) * 300U) / 1000U) + 1U))
581 #define I2C_SPEED_STANDARD(__PCLK__, __SPEED__) (((((__PCLK__)/((__SPEED__) << 1U)) & I2C_CCR_CCR) < 4U)? 4U:((__PCLK__) / ((__SPEED__) << 1U)))
582 #define I2C_SPEED_FAST(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__DUTYCYCLE__) == I2C_DUTYCYCLE_2)? ((__PCLK__) / ((__SPEED__) * 3U)) : (((__PCLK__) / ((__SPEED__) * 25U)) | I2C_DUTYCYCLE_16_9))
583 #define I2C_SPEED(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__SPEED__) <= 100000U)? (I2C_SPEED_STANDARD((__PCLK__), (__SPEED__))) : \
584 ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__)) & I2C_CCR_CCR) == 0U)? 1U : \
585 ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__))) | I2C_CCR_FS))
587 #define I2C_7BIT_ADD_WRITE(__ADDRESS__) ((uint8_t)((__ADDRESS__) & (~I2C_OAR1_ADD0)))
588 #define I2C_7BIT_ADD_READ(__ADDRESS__) ((uint8_t)((__ADDRESS__) | I2C_OAR1_ADD0))
590 #define I2C_10BIT_ADDRESS(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)0x00FF)))
591 #define I2C_10BIT_HEADER_WRITE(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0x0300)) >> 7) | (uint16_t)0x00F0)))
592 #define I2C_10BIT_HEADER_READ(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0x0300)) >> 7) | (uint16_t)(0x00F1))))
594 #define I2C_MEM_ADD_MSB(__ADDRESS__) ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0xFF00)) >> 8)))
595 #define I2C_MEM_ADD_LSB(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)0x00FF)))
597 /** @defgroup I2C_IS_RTC_Definitions I2C Private macros to check input parameters
600 #define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DUTYCYCLE_2) || \
601 ((CYCLE) == I2C_DUTYCYCLE_16_9))
602 #define IS_I2C_ADDRESSING_MODE(ADDRESS) (((ADDRESS) == I2C_ADDRESSINGMODE_7BIT) || \
603 ((ADDRESS) == I2C_ADDRESSINGMODE_10BIT))
604 #define IS_I2C_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == I2C_DUALADDRESS_DISABLE) || \
605 ((ADDRESS) == I2C_DUALADDRESS_ENABLE))
606 #define IS_I2C_GENERAL_CALL(CALL) (((CALL) == I2C_GENERALCALL_DISABLE) || \
607 ((CALL) == I2C_GENERALCALL_ENABLE))
608 #define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLE) || \
609 ((STRETCH) == I2C_NOSTRETCH_ENABLE))
610 #define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \
611 ((SIZE) == I2C_MEMADD_SIZE_16BIT))
612 #define IS_I2C_CLOCK_SPEED(SPEED) (((SPEED) > 0U) && ((SPEED) <= 400000U))
613 #define IS_I2C_OWN_ADDRESS1(ADDRESS1) (((ADDRESS1) & 0xFFFFFC00U) == 0U)
614 #define IS_I2C_OWN_ADDRESS2(ADDRESS2) (((ADDRESS2) & 0xFFFFFF01U) == 0U)
615 #define IS_I2C_TRANSFER_OPTIONS_REQUEST(REQUEST) (((REQUEST) == I2C_FIRST_FRAME) || \
616 ((REQUEST) == I2C_NEXT_FRAME) || \
617 ((REQUEST) == I2C_FIRST_AND_LAST_FRAME) || \
618 ((REQUEST) == I2C_LAST_FRAME))
627 /* Private functions ---------------------------------------------------------*/
628 /** @defgroup I2C_Private_Functions I2C Private Functions
649 #endif /* __STM32F4xx_HAL_I2C_H */
651 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/