2 ******************************************************************************
3 * @file stm32f4xx_hal_i2c.c
4 * @author MCD Application Team
7 * @brief I2C HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the Inter Integrated Circuit (I2C) peripheral:
10 * + Initialization and de-initialization functions
11 * + IO operation functions
12 * + Peripheral Control functions
13 * + Peripheral State functions
16 ==============================================================================
17 ##### How to use this driver #####
18 ==============================================================================
20 The I2C HAL driver can be used as follows:
22 (#) Declare a I2C_HandleTypeDef handle structure, for example:
23 I2C_HandleTypeDef hi2c;
25 (#)Initialize the I2C low level resources by implement the HAL_I2C_MspInit() API:
26 (##) Enable the I2Cx interface clock
27 (##) I2C pins configuration
28 (+++) Enable the clock for the I2C GPIOs
29 (+++) Configure I2C pins as alternate function open-drain
30 (##) NVIC configuration if you need to use interrupt process
31 (+++) Configure the I2Cx interrupt priority
32 (+++) Enable the NVIC I2C IRQ Channel
33 (##) DMA Configuration if you need to use DMA process
34 (+++) Declare a DMA_HandleTypeDef handle structure for the transmit or receive stream
35 (+++) Enable the DMAx interface clock using
36 (+++) Configure the DMA handle parameters
37 (+++) Configure the DMA Tx or Rx Stream
38 (+++) Associate the initilalized DMA handle to the hi2c DMA Tx or Rx handle
39 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on
40 the DMA Tx or Rx Stream
42 (#) Configure the Communication Speed, Duty cycle, Addressing mode, Own Address1,
43 Dual Addressing mode, Own Address2, General call and Nostretch mode in the hi2c Init structure.
45 (#) Initialize the I2C registers by calling the HAL_I2C_Init(), configures also the low level Hardware
46 (GPIO, CLOCK, NVIC...etc) by calling the customed HAL_I2C_MspInit(&hi2c) API.
48 (#) To check if target device is ready for communication, use the function HAL_I2C_IsDeviceReady()
50 (#) For I2C IO and IO MEM operations, three operation modes are available within this driver :
52 *** Polling mode IO operation ***
53 =================================
55 (+) Transmit in master mode an amount of data in blocking mode using HAL_I2C_Master_Transmit()
56 (+) Receive in master mode an amount of data in blocking mode using HAL_I2C_Master_Receive()
57 (+) Transmit in slave mode an amount of data in blocking mode using HAL_I2C_Slave_Transmit()
58 (+) Receive in slave mode an amount of data in blocking mode using HAL_I2C_Slave_Receive()
60 *** Polling mode IO MEM operation ***
61 =====================================
63 (+) Write an amount of data in blocking mode to a specific memory address using HAL_I2C_Mem_Write()
64 (+) Read an amount of data in blocking mode from a specific memory address using HAL_I2C_Mem_Read()
67 *** Interrupt mode IO operation ***
68 ===================================
70 (+) Transmit in master mode an amount of data in non blocking mode using HAL_I2C_Master_Transmit_IT()
71 (+) At transmission end of transfer HAL_I2C_MasterTxCpltCallback is executed and user can
72 add his own code by customization of function pointer HAL_I2C_MasterTxCpltCallback
73 (+) Receive in master mode an amount of data in non blocking mode using HAL_I2C_Master_Receive_IT()
74 (+) At reception end of transfer HAL_I2C_MasterRxCpltCallback is executed and user can
75 add his own code by customization of function pointer HAL_I2C_MasterRxCpltCallback
76 (+) Transmit in slave mode an amount of data in non blocking mode using HAL_I2C_Slave_Transmit_IT()
77 (+) At transmission end of transfer HAL_I2C_SlaveTxCpltCallback is executed and user can
78 add his own code by customization of function pointer HAL_I2C_SlaveTxCpltCallback
79 (+) Receive in slave mode an amount of data in non blocking mode using HAL_I2C_Slave_Receive_IT()
80 (+) At reception end of transfer HAL_I2C_SlaveRxCpltCallback is executed and user can
81 add his own code by customization of function pointer HAL_I2C_SlaveRxCpltCallback
82 (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can
83 add his own code by customization of function pointer HAL_I2C_ErrorCallback
85 *** Interrupt mode IO MEM operation ***
86 =======================================
88 (+) Write an amount of data in no-blocking mode with Interrupt to a specific memory address using
89 HAL_I2C_Mem_Write_IT()
90 (+) At MEM end of write transfer HAL_I2C_MemTxCpltCallback is executed and user can
91 add his own code by customization of function pointer HAL_I2C_MemTxCpltCallback
92 (+) Read an amount of data in no-blocking mode with Interrupt from a specific memory address using
94 (+) At MEM end of read transfer HAL_I2C_MemRxCpltCallback is executed and user can
95 add his own code by customization of function pointer HAL_I2C_MemRxCpltCallback
96 (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can
97 add his own code by customization of function pointer HAL_I2C_ErrorCallback
99 *** DMA mode IO operation ***
100 ==============================
102 (+) Transmit in master mode an amount of data in non blocking mode (DMA) using
103 HAL_I2C_Master_Transmit_DMA()
104 (+) At transmission end of transfer HAL_I2C_MasterTxCpltCallback is executed and user can
105 add his own code by customization of function pointer HAL_I2C_MasterTxCpltCallback
106 (+) Receive in master mode an amount of data in non blocking mode (DMA) using
107 HAL_I2C_Master_Receive_DMA()
108 (+) At reception end of transfer HAL_I2C_MasterRxCpltCallback is executed and user can
109 add his own code by customization of function pointer HAL_I2C_MasterRxCpltCallback
110 (+) Transmit in slave mode an amount of data in non blocking mode (DMA) using
111 HAL_I2C_Slave_Transmit_DMA()
112 (+) At transmission end of transfer HAL_I2C_SlaveTxCpltCallback is executed and user can
113 add his own code by customization of function pointer HAL_I2C_SlaveTxCpltCallback
114 (+) Receive in slave mode an amount of data in non blocking mode (DMA) using
115 HAL_I2C_Slave_Receive_DMA()
116 (+) At reception end of transfer HAL_I2C_SlaveRxCpltCallback is executed and user can
117 add his own code by customization of function pointer HAL_I2C_SlaveRxCpltCallback
118 (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can
119 add his own code by customization of function pointer HAL_I2C_ErrorCallback
121 *** DMA mode IO MEM operation ***
122 =================================
124 (+) Write an amount of data in no-blocking mode with DMA to a specific memory address using
125 HAL_I2C_Mem_Write_DMA()
126 (+) At MEM end of write transfer HAL_I2C_MemTxCpltCallback is executed and user can
127 add his own code by customization of function pointer HAL_I2C_MemTxCpltCallback
128 (+) Read an amount of data in no-blocking mode with DMA from a specific memory address using
129 HAL_I2C_Mem_Read_DMA()
130 (+) At MEM end of read transfer HAL_I2C_MemRxCpltCallback is executed and user can
131 add his own code by customization of function pointer HAL_I2C_MemRxCpltCallback
132 (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can
133 add his own code by customization of function pointer HAL_I2C_ErrorCallback
136 *** I2C HAL driver macros list ***
137 ==================================
139 Below the list of most used macros in I2C HAL driver.
141 (+) __HAL_I2C_ENABLE: Enable the I2C peripheral
142 (+) __HAL_I2C_DISABLE: Disable the I2C peripheral
143 (+) __HAL_I2C_GET_FLAG : Checks whether the specified I2C flag is set or not
144 (+) __HAL_I2C_CLEAR_FLAG : Clear the specified I2C pending flag
145 (+) __HAL_I2C_ENABLE_IT: Enable the specified I2C interrupt
146 (+) __HAL_I2C_DISABLE_IT: Disable the specified I2C interrupt
149 (@) You can refer to the I2C HAL driver header file for more useful macros
153 ******************************************************************************
156 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
158 * Redistribution and use in source and binary forms, with or without modification,
159 * are permitted provided that the following conditions are met:
160 * 1. Redistributions of source code must retain the above copyright notice,
161 * this list of conditions and the following disclaimer.
162 * 2. Redistributions in binary form must reproduce the above copyright notice,
163 * this list of conditions and the following disclaimer in the documentation
164 * and/or other materials provided with the distribution.
165 * 3. Neither the name of STMicroelectronics nor the names of its contributors
166 * may be used to endorse or promote products derived from this software
167 * without specific prior written permission.
169 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
170 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
172 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
173 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
174 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
175 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
176 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
177 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
178 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
180 ******************************************************************************
183 /* Includes ------------------------------------------------------------------*/
184 #include "stm32f4xx_hal.h"
186 /** @addtogroup STM32F4xx_HAL_Driver
191 * @brief I2C HAL module driver
195 #ifdef HAL_I2C_MODULE_ENABLED
197 /* Private typedef -----------------------------------------------------------*/
198 /* Private define ------------------------------------------------------------*/
199 #define I2C_TIMEOUT_FLAG ((uint32_t)35) /* 35 ms */
200 #define I2C_TIMEOUT_ADDR_SLAVE ((uint32_t)10000) /* 10 s */
202 /* Private macro -------------------------------------------------------------*/
203 /* Private variables ---------------------------------------------------------*/
204 /* Private function prototypes -----------------------------------------------*/
205 static void I2C_DMAMasterTransmitCplt(DMA_HandleTypeDef
*hdma
);
206 static void I2C_DMAMasterReceiveCplt(DMA_HandleTypeDef
*hdma
);
207 static void I2C_DMASlaveTransmitCplt(DMA_HandleTypeDef
*hdma
);
208 static void I2C_DMASlaveReceiveCplt(DMA_HandleTypeDef
*hdma
);
209 static void I2C_DMAMemTransmitCplt(DMA_HandleTypeDef
*hdma
);
210 static void I2C_DMAMemReceiveCplt(DMA_HandleTypeDef
*hdma
);
211 static void I2C_DMAError(DMA_HandleTypeDef
*hdma
);
213 static HAL_StatusTypeDef
I2C_MasterRequestWrite(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint32_t Timeout
);
214 static HAL_StatusTypeDef
I2C_MasterRequestRead(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint32_t Timeout
);
215 static HAL_StatusTypeDef
I2C_RequestMemoryWrite(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint16_t MemAddress
, uint16_t MemAddSize
, uint32_t Timeout
);
216 static HAL_StatusTypeDef
I2C_RequestMemoryRead(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint16_t MemAddress
, uint16_t MemAddSize
, uint32_t Timeout
);
217 static HAL_StatusTypeDef
I2C_WaitOnFlagUntilTimeout(I2C_HandleTypeDef
*hi2c
, uint32_t Flag
, FlagStatus Status
, uint32_t Timeout
);
218 static HAL_StatusTypeDef
I2C_WaitOnMasterAddressFlagUntilTimeout(I2C_HandleTypeDef
*hi2c
, uint32_t Flag
, uint32_t Timeout
);
220 static HAL_StatusTypeDef
I2C_MasterTransmit_TXE(I2C_HandleTypeDef
*hi2c
);
221 static HAL_StatusTypeDef
I2C_MasterTransmit_BTF(I2C_HandleTypeDef
*hi2c
);
222 static HAL_StatusTypeDef
I2C_MasterReceive_RXNE(I2C_HandleTypeDef
*hi2c
);
223 static HAL_StatusTypeDef
I2C_MasterReceive_BTF(I2C_HandleTypeDef
*hi2c
);
225 static HAL_StatusTypeDef
I2C_SlaveTransmit_TXE(I2C_HandleTypeDef
*hi2c
);
226 static HAL_StatusTypeDef
I2C_SlaveTransmit_BTF(I2C_HandleTypeDef
*hi2c
);
227 static HAL_StatusTypeDef
I2C_SlaveReceive_RXNE(I2C_HandleTypeDef
*hi2c
);
228 static HAL_StatusTypeDef
I2C_SlaveReceive_BTF(I2C_HandleTypeDef
*hi2c
);
229 static HAL_StatusTypeDef
I2C_Slave_ADDR(I2C_HandleTypeDef
*hi2c
);
230 static HAL_StatusTypeDef
I2C_Slave_STOPF(I2C_HandleTypeDef
*hi2c
);
231 static HAL_StatusTypeDef
I2C_Slave_AF(I2C_HandleTypeDef
*hi2c
);
233 /* Private functions ---------------------------------------------------------*/
235 /** @defgroup I2C_Private_Functions
239 /** @defgroup I2C_Group1 Initialization and de-initialization functions
240 * @brief Initialization and Configuration functions
243 ===============================================================================
244 ##### Initialization and de-initialization functions #####
245 ===============================================================================
246 [..] This subsection provides a set of functions allowing to initialize and
247 de-initialiaze the I2Cx peripheral:
249 (+) User must Implement HAL_I2C_MspInit() function in which he configures
250 all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC).
252 (+) Call the function HAL_I2C_Init() to configure the selected device with
253 the selected configuration:
254 (++) Communication Speed
258 (++) Dual Addressing mode
260 (++) General call mode
263 (+) Call the function HAL_I2C_DeInit() to restore the default configuration
264 of the selected I2Cx periperal.
271 * @brief Initializes the I2C according to the specified parameters
272 * in the I2C_InitTypeDef and create the associated handle.
273 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
274 * the configuration information for I2C module
277 HAL_StatusTypeDef
HAL_I2C_Init(I2C_HandleTypeDef
*hi2c
)
279 uint32_t freqrange
= 0;
282 /* Check the I2C handle allocation */
288 /* Check the parameters */
289 assert_param(IS_I2C_ALL_INSTANCE(hi2c
->Instance
));
290 assert_param(IS_I2C_CLOCK_SPEED(hi2c
->Init
.ClockSpeed
));
291 assert_param(IS_I2C_DUTY_CYCLE(hi2c
->Init
.DutyCycle
));
292 assert_param(IS_I2C_OWN_ADDRESS1(hi2c
->Init
.OwnAddress1
));
293 assert_param(IS_I2C_ADDRESSING_MODE(hi2c
->Init
.AddressingMode
));
294 assert_param(IS_I2C_DUAL_ADDRESS(hi2c
->Init
.DualAddressMode
));
295 assert_param(IS_I2C_OWN_ADDRESS2(hi2c
->Init
.OwnAddress2
));
296 assert_param(IS_I2C_GENERAL_CALL(hi2c
->Init
.GeneralCallMode
));
297 assert_param(IS_I2C_NO_STRETCH(hi2c
->Init
.NoStretchMode
));
299 if(hi2c
->State
== HAL_I2C_STATE_RESET
)
301 /* Init the low level hardware : GPIO, CLOCK, NVIC */
302 HAL_I2C_MspInit(hi2c
);
305 hi2c
->State
= HAL_I2C_STATE_BUSY
;
307 /* Disble the selected I2C peripheral */
308 __HAL_I2C_DISABLE(hi2c
);
310 /* Get PCLK1 frequency */
311 pclk1
= HAL_RCC_GetPCLK1Freq();
313 /* Calculate frequency range */
314 freqrange
= __HAL_I2C_FREQRANGE(pclk1
);
316 /*---------------------------- I2Cx CR2 Configuration ----------------------*/
317 /* Configure I2Cx: Frequency range */
318 hi2c
->Instance
->CR2
= freqrange
;
320 /*---------------------------- I2Cx TRISE Configuration --------------------*/
321 /* Configure I2Cx: Rise Time */
322 hi2c
->Instance
->TRISE
= __HAL_I2C_RISE_TIME(freqrange
, hi2c
->Init
.ClockSpeed
);
324 /*---------------------------- I2Cx CCR Configuration ----------------------*/
325 /* Configure I2Cx: Speed */
326 hi2c
->Instance
->CCR
= __HAL_I2C_SPEED(pclk1
, hi2c
->Init
.ClockSpeed
, hi2c
->Init
.DutyCycle
);
328 /*---------------------------- I2Cx CR1 Configuration ----------------------*/
329 /* Configure I2Cx: Generalcall and NoStretch mode */
330 hi2c
->Instance
->CR1
= (hi2c
->Init
.GeneralCallMode
| hi2c
->Init
.NoStretchMode
);
332 /*---------------------------- I2Cx OAR1 Configuration ---------------------*/
333 /* Configure I2Cx: Own Address1 and addressing mode */
334 hi2c
->Instance
->OAR1
= (hi2c
->Init
.AddressingMode
| hi2c
->Init
.OwnAddress1
);
336 /*---------------------------- I2Cx OAR2 Configuration ---------------------*/
337 /* Configure I2Cx: Dual mode and Own Address2 */
338 hi2c
->Instance
->OAR2
= (hi2c
->Init
.DualAddressMode
| hi2c
->Init
.OwnAddress2
);
340 /* Enable the selected I2C peripheral */
341 __HAL_I2C_ENABLE(hi2c
);
343 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
344 hi2c
->State
= HAL_I2C_STATE_READY
;
350 * @brief DeInitializes the I2C peripheral.
351 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
352 * the configuration information for I2C module
355 HAL_StatusTypeDef
HAL_I2C_DeInit(I2C_HandleTypeDef
*hi2c
)
357 /* Check the I2C handle allocation */
363 /* Check the parameters */
364 assert_param(IS_I2C_ALL_INSTANCE(hi2c
->Instance
));
366 hi2c
->State
= HAL_I2C_STATE_BUSY
;
368 /* Disable the I2C Peripheral Clock */
369 __HAL_I2C_DISABLE(hi2c
);
371 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
372 HAL_I2C_MspDeInit(hi2c
);
374 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
376 hi2c
->State
= HAL_I2C_STATE_RESET
;
385 * @brief I2C MSP Init.
386 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
387 * the configuration information for I2C module
390 __weak
void HAL_I2C_MspInit(I2C_HandleTypeDef
*hi2c
)
392 /* NOTE : This function Should not be modified, when the callback is needed,
393 the HAL_I2C_MspInit could be implemented in the user file
398 * @brief I2C MSP DeInit
399 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
400 * the configuration information for I2C module
403 __weak
void HAL_I2C_MspDeInit(I2C_HandleTypeDef
*hi2c
)
405 /* NOTE : This function Should not be modified, when the callback is needed,
406 the HAL_I2C_MspDeInit could be implemented in the user file
414 /** @defgroup I2C_Group2 IO operation functions
415 * @brief Data transfers functions
418 ===============================================================================
419 ##### IO operation functions #####
420 ===============================================================================
422 This subsection provides a set of functions allowing to manage the I2C data
425 (#) There are two modes of transfer:
426 (++) Blocking mode : The communication is performed in the polling mode.
427 The status of all data processing is returned by the same function
428 after finishing transfer.
429 (++) No-Blocking mode : The communication is performed using Interrupts
430 or DMA. These functions return the status of the transfer startup.
431 The end of the data processing will be indicated through the
432 dedicated I2C IRQ when using Interrupt mode or the DMA IRQ when
435 (#) Blocking mode functions are :
436 (++) HAL_I2C_Master_Transmit()
437 (++) HAL_I2C_Master_Receive()
438 (++) HAL_I2C_Slave_Transmit()
439 (++) HAL_I2C_Slave_Receive()
440 (++) HAL_I2C_Mem_Write()
441 (++) HAL_I2C_Mem_Read()
442 (++) HAL_I2C_IsDeviceReady()
444 (#) No-Blocking mode functions with Interrupt are :
445 (++) HAL_I2C_Master_Transmit_IT()
446 (++) HAL_I2C_Master_Receive_IT()
447 (++) HAL_I2C_Slave_Transmit_IT()
448 (++) HAL_I2C_Slave_Receive_IT()
449 (++) HAL_I2C_Mem_Write_IT()
450 (++) HAL_I2C_Mem_Read_IT()
452 (#) No-Blocking mode functions with DMA are :
453 (++) HAL_I2C_Master_Transmit_DMA()
454 (++) HAL_I2C_Master_Receive_DMA()
455 (++) HAL_I2C_Slave_Transmit_DMA()
456 (++) HAL_I2C_Slave_Receive_DMA()
457 (++) HAL_I2C_Mem_Write_DMA()
458 (++) HAL_I2C_Mem_Read_DMA()
460 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
461 (++) HAL_I2C_MemTxCpltCallback()
462 (++) HAL_I2C_MemRxCpltCallback()
463 (++) HAL_I2C_MasterTxCpltCallback()
464 (++) HAL_I2C_MasterRxCpltCallback()
465 (++) HAL_I2C_SlaveTxCpltCallback()
466 (++) HAL_I2C_SlaveRxCpltCallback()
467 (++) HAL_I2C_ErrorCallback()
474 * @brief Transmits in master mode an amount of data in blocking mode.
475 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
476 * the configuration information for I2C module
477 * @param DevAddress: Target device address
478 * @param pData: Pointer to data buffer
479 * @param Size: Amount of data to be sent
480 * @param Timeout: Timeout duration
483 HAL_StatusTypeDef
HAL_I2C_Master_Transmit(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
)
485 if(hi2c
->State
== HAL_I2C_STATE_READY
)
487 if((pData
== HAL_NULL
) || (Size
== 0))
492 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
500 hi2c
->State
= HAL_I2C_STATE_BUSY_TX
;
501 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
503 /* Send Slave Address */
504 if(I2C_MasterRequestWrite(hi2c
, DevAddress
, Timeout
) != HAL_OK
)
506 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
508 /* Process Unlocked */
514 /* Process Unlocked */
520 /* Clear ADDR flag */
521 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
525 /* Wait until TXE flag is set */
526 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_TXE
, RESET
, Timeout
) != HAL_OK
)
531 /* Write data to DR */
532 hi2c
->Instance
->DR
= (*pData
++);
535 if((__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BTF
) == SET
) && (Size
!= 0))
537 /* Write data to DR */
538 hi2c
->Instance
->DR
= (*pData
++);
543 /* Wait until TXE flag is set */
544 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_TXE
, RESET
, Timeout
) != HAL_OK
)
550 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
552 /* Wait until BUSY flag is reset */
553 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, Timeout
) != HAL_OK
)
558 hi2c
->State
= HAL_I2C_STATE_READY
;
560 /* Process Unlocked */
572 * @brief Receives in master mode an amount of data in blocking mode.
573 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
574 * the configuration information for I2C module
575 * @param DevAddress: Target device address
576 * @param pData: Pointer to data buffer
577 * @param Size: Amount of data to be sent
578 * @param Timeout: Timeout duration
581 HAL_StatusTypeDef
HAL_I2C_Master_Receive(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
)
583 if(hi2c
->State
== HAL_I2C_STATE_READY
)
585 if((pData
== HAL_NULL
) || (Size
== 0))
590 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
598 hi2c
->State
= HAL_I2C_STATE_BUSY_RX
;
599 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
601 /* Send Slave Address */
602 if(I2C_MasterRequestRead(hi2c
, DevAddress
, Timeout
) != HAL_OK
)
604 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
606 /* Process Unlocked */
612 /* Process Unlocked */
620 /* Disable Acknowledge */
621 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
623 /* Clear ADDR flag */
624 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
627 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
631 /* Disable Acknowledge */
632 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
635 hi2c
->Instance
->CR1
|= I2C_CR1_POS
;
637 /* Clear ADDR flag */
638 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
642 /* Enable Acknowledge */
643 hi2c
->Instance
->CR1
|= I2C_CR1_ACK
;
645 /* Clear ADDR flag */
646 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
656 /* Wait until RXNE flag is set */
657 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_RXNE
, RESET
, Timeout
) != HAL_OK
)
662 /* Read data from DR */
663 (*pData
++) = hi2c
->Instance
->DR
;
669 /* Wait until BTF flag is set */
670 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BTF
, RESET
, Timeout
) != HAL_OK
)
676 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
678 /* Read data from DR */
679 (*pData
++) = hi2c
->Instance
->DR
;
682 /* Read data from DR */
683 (*pData
++) = hi2c
->Instance
->DR
;
689 /* Wait until BTF flag is set */
690 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BTF
, RESET
, Timeout
) != HAL_OK
)
695 /* Disable Acknowledge */
696 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
698 /* Read data from DR */
699 (*pData
++) = hi2c
->Instance
->DR
;
702 /* Wait until BTF flag is set */
703 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BTF
, RESET
, Timeout
) != HAL_OK
)
709 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
711 /* Read data from DR */
712 (*pData
++) = hi2c
->Instance
->DR
;
715 /* Read data from DR */
716 (*pData
++) = hi2c
->Instance
->DR
;
722 /* Wait until RXNE flag is set */
723 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_RXNE
, RESET
, Timeout
) != HAL_OK
)
728 /* Read data from DR */
729 (*pData
++) = hi2c
->Instance
->DR
;
732 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BTF
) == SET
)
734 /* Read data from DR */
735 (*pData
++) = hi2c
->Instance
->DR
;
742 hi2c
->Instance
->CR1
&= ~I2C_CR1_POS
;
744 /* Wait until BUSY flag is reset */
745 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, Timeout
) != HAL_OK
)
750 hi2c
->State
= HAL_I2C_STATE_READY
;
752 /* Process Unlocked */
764 * @brief Transmits in slave mode an amount of data in blocking mode.
765 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
766 * the configuration information for I2C module
767 * @param pData: Pointer to data buffer
768 * @param Size: Amount of data to be sent
769 * @param Timeout: Timeout duration
772 HAL_StatusTypeDef
HAL_I2C_Slave_Transmit(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
)
774 if(hi2c
->State
== HAL_I2C_STATE_READY
)
776 if((pData
== HAL_NULL
) || (Size
== 0))
781 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
789 hi2c
->State
= HAL_I2C_STATE_BUSY_TX
;
790 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
792 /* Enable Address Acknowledge */
793 hi2c
->Instance
->CR1
|= I2C_CR1_ACK
;
795 /* Wait until ADDR flag is set */
796 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_ADDR
, RESET
, Timeout
) != HAL_OK
)
801 /* Clear ADDR flag */
802 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
804 /* If 10bit addressing mode is selected */
805 if(hi2c
->Init
.AddressingMode
== I2C_ADDRESSINGMODE_10BIT
)
807 /* Wait until ADDR flag is set */
808 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_ADDR
, RESET
, Timeout
) != HAL_OK
)
813 /* Clear ADDR flag */
814 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
819 /* Wait until TXE flag is set */
820 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_TXE
, RESET
, Timeout
) != HAL_OK
)
825 /* Write data to DR */
826 hi2c
->Instance
->DR
= (*pData
++);
829 if((__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BTF
) == SET
) && (Size
!= 0))
831 /* Write data to DR */
832 hi2c
->Instance
->DR
= (*pData
++);
837 /* Wait until AF flag is set */
838 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_AF
, RESET
, Timeout
) != HAL_OK
)
844 __HAL_I2C_CLEAR_FLAG(hi2c
, I2C_FLAG_AF
);
846 /* Disable Address Acknowledge */
847 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
849 /* Wait until BUSY flag is reset */
850 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, Timeout
) != HAL_OK
)
855 hi2c
->State
= HAL_I2C_STATE_READY
;
857 /* Process Unlocked */
869 * @brief Receive in slave mode an amount of data in blocking mode
870 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
871 * the configuration information for I2C module
872 * @param pData: Pointer to data buffer
873 * @param Size: Amount of data to be sent
874 * @param Timeout: Timeout duration
877 HAL_StatusTypeDef
HAL_I2C_Slave_Receive(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
)
879 if(hi2c
->State
== HAL_I2C_STATE_READY
)
881 if((pData
== HAL_NULL
) || (Size
== 0))
886 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
894 hi2c
->State
= HAL_I2C_STATE_BUSY_RX
;
895 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
897 /* Enable Address Acknowledge */
898 hi2c
->Instance
->CR1
|= I2C_CR1_ACK
;
900 /* Wait until ADDR flag is set */
901 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_ADDR
, RESET
, Timeout
) != HAL_OK
)
906 /* Clear ADDR flag */
907 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
911 /* Wait until RXNE flag is set */
912 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_RXNE
, RESET
, Timeout
) != HAL_OK
)
917 /* Read data from DR */
918 (*pData
++) = hi2c
->Instance
->DR
;
921 if((__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BTF
) == SET
) && (Size
!= 0))
923 /* Read data from DR */
924 (*pData
++) = hi2c
->Instance
->DR
;
929 /* Wait until STOP flag is set */
930 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_STOPF
, RESET
, Timeout
) != HAL_OK
)
935 /* Clear STOP flag */
936 __HAL_I2C_CLEAR_STOPFLAG(hi2c
);
938 /* Disable Address Acknowledge */
939 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
941 /* Wait until BUSY flag is reset */
942 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, Timeout
) != HAL_OK
)
947 hi2c
->State
= HAL_I2C_STATE_READY
;
949 /* Process Unlocked */
961 * @brief Transmit in master mode an amount of data in no-blocking mode with Interrupt
962 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
963 * the configuration information for I2C module
964 * @param DevAddress: Target device address
965 * @param pData: Pointer to data buffer
966 * @param Size: Amount of data to be sent
969 HAL_StatusTypeDef
HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
)
971 if(hi2c
->State
== HAL_I2C_STATE_READY
)
973 if((pData
== HAL_NULL
) || (Size
== 0))
978 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
986 hi2c
->State
= HAL_I2C_STATE_BUSY_TX
;
987 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
989 hi2c
->pBuffPtr
= pData
;
990 hi2c
->XferSize
= Size
;
991 hi2c
->XferCount
= Size
;
993 /* Send Slave Address */
994 if(I2C_MasterRequestWrite(hi2c
, DevAddress
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
996 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
998 /* Process Unlocked */
1004 /* Process Unlocked */
1010 /* Clear ADDR flag */
1011 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1013 /* Process Unlocked */
1016 /* Note : The I2C interrupts must be enabled after unlocking current process
1017 to avoid the risk of I2C interrupt handle execution before current
1020 /* Enable EVT, BUF and ERR interrupt */
1021 __HAL_I2C_ENABLE_IT(hi2c
, I2C_IT_EVT
| I2C_IT_BUF
| I2C_IT_ERR
);
1032 * @brief Receive in master mode an amount of data in no-blocking mode with Interrupt
1033 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
1034 * the configuration information for I2C module
1035 * @param DevAddress: Target device address
1036 * @param pData: Pointer to data buffer
1037 * @param Size: Amount of data to be sent
1038 * @retval HAL status
1040 HAL_StatusTypeDef
HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
)
1042 if(hi2c
->State
== HAL_I2C_STATE_READY
)
1044 if((pData
== HAL_NULL
) || (Size
== 0))
1049 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
1054 /* Process Locked */
1057 hi2c
->State
= HAL_I2C_STATE_BUSY_RX
;
1058 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
1060 hi2c
->pBuffPtr
= pData
;
1061 hi2c
->XferSize
= Size
;
1062 hi2c
->XferCount
= Size
;
1064 /* Send Slave Address */
1065 if(I2C_MasterRequestRead(hi2c
, DevAddress
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
1067 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
1069 /* Process Unlocked */
1075 /* Process Unlocked */
1081 if(hi2c
->XferCount
== 1)
1083 /* Disable Acknowledge */
1084 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
1086 /* Clear ADDR flag */
1087 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1090 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
1092 else if(hi2c
->XferCount
== 2)
1094 /* Disable Acknowledge */
1095 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
1098 hi2c
->Instance
->CR1
|= I2C_CR1_POS
;
1100 /* Clear ADDR flag */
1101 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1105 /* Enable Acknowledge */
1106 hi2c
->Instance
->CR1
|= I2C_CR1_ACK
;
1108 /* Clear ADDR flag */
1109 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1112 /* Process Unlocked */
1115 /* Note : The I2C interrupts must be enabled after unlocking current process
1116 to avoid the risk of I2C interrupt handle execution before current
1119 /* Enable EVT, BUF and ERR interrupt */
1120 __HAL_I2C_ENABLE_IT(hi2c
, I2C_IT_EVT
| I2C_IT_BUF
| I2C_IT_ERR
);
1131 * @brief Transmit in slave mode an amount of data in no-blocking mode with Interrupt
1132 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
1133 * the configuration information for I2C module
1134 * @param pData: Pointer to data buffer
1135 * @param Size: Amount of data to be sent
1136 * @retval HAL status
1138 HAL_StatusTypeDef
HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
)
1140 if(hi2c
->State
== HAL_I2C_STATE_READY
)
1142 if((pData
== HAL_NULL
) || (Size
== 0))
1147 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
1152 /* Process Locked */
1155 hi2c
->State
= HAL_I2C_STATE_BUSY_TX
;
1156 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
1158 hi2c
->pBuffPtr
= pData
;
1159 hi2c
->XferSize
= Size
;
1160 hi2c
->XferCount
= Size
;
1162 /* Enable Address Acknowledge */
1163 hi2c
->Instance
->CR1
|= I2C_CR1_ACK
;
1165 /* Process Unlocked */
1168 /* Note : The I2C interrupts must be enabled after unlocking current process
1169 to avoid the risk of I2C interrupt handle execution before current
1172 /* Enable EVT, BUF and ERR interrupt */
1173 __HAL_I2C_ENABLE_IT(hi2c
, I2C_IT_EVT
| I2C_IT_BUF
| I2C_IT_ERR
);
1184 * @brief Receive in slave mode an amount of data in no-blocking mode with Interrupt
1185 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
1186 * the configuration information for I2C module
1187 * @param pData: Pointer to data buffer
1188 * @param Size: Amount of data to be sent
1189 * @retval HAL status
1191 HAL_StatusTypeDef
HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
)
1193 if(hi2c
->State
== HAL_I2C_STATE_READY
)
1195 if((pData
== HAL_NULL
) || (Size
== 0))
1200 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
1205 /* Process Locked */
1208 hi2c
->State
= HAL_I2C_STATE_BUSY_RX
;
1209 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
1211 hi2c
->pBuffPtr
= pData
;
1212 hi2c
->XferSize
= Size
;
1213 hi2c
->XferCount
= Size
;
1215 /* Enable Address Acknowledge */
1216 hi2c
->Instance
->CR1
|= I2C_CR1_ACK
;
1218 /* Process Unlocked */
1221 /* Note : The I2C interrupts must be enabled after unlocking current process
1222 to avoid the risk of I2C interrupt handle execution before current
1225 /* Enable EVT, BUF and ERR interrupt */
1226 __HAL_I2C_ENABLE_IT(hi2c
, I2C_IT_EVT
| I2C_IT_BUF
| I2C_IT_ERR
);
1237 * @brief Transmit in master mode an amount of data in no-blocking mode with DMA
1238 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
1239 * the configuration information for I2C module
1240 * @param DevAddress: Target device address
1241 * @param pData: Pointer to data buffer
1242 * @param Size: Amount of data to be sent
1243 * @retval HAL status
1245 HAL_StatusTypeDef
HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
)
1247 if(hi2c
->State
== HAL_I2C_STATE_READY
)
1249 if((pData
== HAL_NULL
) || (Size
== 0))
1254 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
1259 /* Process Locked */
1262 hi2c
->State
= HAL_I2C_STATE_BUSY_TX
;
1263 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
1265 hi2c
->pBuffPtr
= pData
;
1266 hi2c
->XferSize
= Size
;
1267 hi2c
->XferCount
= Size
;
1269 /* Set the I2C DMA transfert complete callback */
1270 hi2c
->hdmatx
->XferCpltCallback
= I2C_DMAMasterTransmitCplt
;
1272 /* Set the DMA error callback */
1273 hi2c
->hdmatx
->XferErrorCallback
= I2C_DMAError
;
1275 /* Enable the DMA Stream */
1276 HAL_DMA_Start_IT(hi2c
->hdmatx
, (uint32_t)pData
, (uint32_t)&hi2c
->Instance
->DR
, Size
);
1278 /* Send Slave Address */
1279 if(I2C_MasterRequestWrite(hi2c
, DevAddress
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
1281 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
1283 /* Process Unlocked */
1289 /* Process Unlocked */
1295 /* Enable DMA Request */
1296 hi2c
->Instance
->CR2
|= I2C_CR2_DMAEN
;
1298 /* Clear ADDR flag */
1299 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1301 /* Process Unlocked */
1313 * @brief Receive in master mode an amount of data in no-blocking mode with DMA
1314 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
1315 * the configuration information for I2C module
1316 * @param DevAddress: Target device address
1317 * @param pData: Pointer to data buffer
1318 * @param Size: Amount of data to be sent
1319 * @retval HAL status
1321 HAL_StatusTypeDef
HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint8_t *pData
, uint16_t Size
)
1323 if(hi2c
->State
== HAL_I2C_STATE_READY
)
1325 if((pData
== HAL_NULL
) || (Size
== 0))
1330 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
1335 /* Process Locked */
1338 hi2c
->State
= HAL_I2C_STATE_BUSY_RX
;
1339 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
1341 hi2c
->pBuffPtr
= pData
;
1342 hi2c
->XferSize
= Size
;
1343 hi2c
->XferCount
= Size
;
1345 /* Set the I2C DMA transfert complete callback */
1346 hi2c
->hdmarx
->XferCpltCallback
= I2C_DMAMasterReceiveCplt
;
1348 /* Set the DMA error callback */
1349 hi2c
->hdmarx
->XferErrorCallback
= I2C_DMAError
;
1351 /* Enable the DMA Stream */
1352 HAL_DMA_Start_IT(hi2c
->hdmarx
, (uint32_t)&hi2c
->Instance
->DR
, (uint32_t)pData
, Size
);
1354 /* Send Slave Address */
1355 if(I2C_MasterRequestRead(hi2c
, DevAddress
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
1357 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
1359 /* Process Unlocked */
1365 /* Process Unlocked */
1373 /* Disable Acknowledge */
1374 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
1378 /* Enable Last DMA bit */
1379 hi2c
->Instance
->CR2
|= I2C_CR2_LAST
;
1382 /* Enable DMA Request */
1383 hi2c
->Instance
->CR2
|= I2C_CR2_DMAEN
;
1385 /* Clear ADDR flag */
1386 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1388 /* Process Unlocked */
1400 * @brief Transmit in slave mode an amount of data in no-blocking mode with DMA
1401 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
1402 * the configuration information for I2C module
1403 * @param pData: Pointer to data buffer
1404 * @param Size: Amount of data to be sent
1405 * @retval HAL status
1407 HAL_StatusTypeDef
HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
)
1409 if(hi2c
->State
== HAL_I2C_STATE_READY
)
1411 if((pData
== HAL_NULL
) || (Size
== 0))
1416 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
1421 /* Process Locked */
1424 hi2c
->State
= HAL_I2C_STATE_BUSY_TX
;
1425 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
1427 hi2c
->pBuffPtr
= pData
;
1428 hi2c
->XferSize
= Size
;
1429 hi2c
->XferCount
= Size
;
1431 /* Set the I2C DMA transfert complete callback */
1432 hi2c
->hdmatx
->XferCpltCallback
= I2C_DMASlaveTransmitCplt
;
1434 /* Set the DMA error callback */
1435 hi2c
->hdmatx
->XferErrorCallback
= I2C_DMAError
;
1437 /* Enable the DMA Stream */
1438 HAL_DMA_Start_IT(hi2c
->hdmatx
, (uint32_t)pData
, (uint32_t)&hi2c
->Instance
->DR
, Size
);
1440 /* Enable DMA Request */
1441 hi2c
->Instance
->CR2
|= I2C_CR2_DMAEN
;
1443 /* Enable Address Acknowledge */
1444 hi2c
->Instance
->CR1
|= I2C_CR1_ACK
;
1446 /* Wait until ADDR flag is set */
1447 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_ADDR
, RESET
, I2C_TIMEOUT_ADDR_SLAVE
) != HAL_OK
)
1452 /* If 7bit addressing mode is selected */
1453 if(hi2c
->Init
.AddressingMode
== I2C_ADDRESSINGMODE_7BIT
)
1455 /* Clear ADDR flag */
1456 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1460 /* Clear ADDR flag */
1461 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1463 /* Wait until ADDR flag is set */
1464 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_ADDR
, RESET
, I2C_TIMEOUT_ADDR_SLAVE
) != HAL_OK
)
1469 /* Clear ADDR flag */
1470 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1473 /* Process Unlocked */
1485 * @brief Receive in slave mode an amount of data in no-blocking mode with DMA
1486 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
1487 * the configuration information for I2C module
1488 * @param pData: Pointer to data buffer
1489 * @param Size: Amount of data to be sent
1490 * @retval HAL status
1492 HAL_StatusTypeDef
HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef
*hi2c
, uint8_t *pData
, uint16_t Size
)
1494 if(hi2c
->State
== HAL_I2C_STATE_READY
)
1496 if((pData
== HAL_NULL
) || (Size
== 0))
1501 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
1506 /* Process Locked */
1509 hi2c
->State
= HAL_I2C_STATE_BUSY_RX
;
1510 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
1512 hi2c
->pBuffPtr
= pData
;
1513 hi2c
->XferSize
= Size
;
1514 hi2c
->XferCount
= Size
;
1516 /* Set the I2C DMA transfert complete callback */
1517 hi2c
->hdmarx
->XferCpltCallback
= I2C_DMASlaveReceiveCplt
;
1519 /* Set the DMA error callback */
1520 hi2c
->hdmarx
->XferErrorCallback
= I2C_DMAError
;
1522 /* Enable the DMA Stream */
1523 HAL_DMA_Start_IT(hi2c
->hdmarx
, (uint32_t)&hi2c
->Instance
->DR
, (uint32_t)pData
, Size
);
1525 /* Enable DMA Request */
1526 hi2c
->Instance
->CR2
|= I2C_CR2_DMAEN
;
1528 /* Enable Address Acknowledge */
1529 hi2c
->Instance
->CR1
|= I2C_CR1_ACK
;
1531 /* Wait until ADDR flag is set */
1532 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_ADDR
, RESET
, I2C_TIMEOUT_ADDR_SLAVE
) != HAL_OK
)
1537 /* Clear ADDR flag */
1538 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1540 /* Process Unlocked */
1551 * @brief Write an amount of data in blocking mode to a specific memory address
1552 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
1553 * the configuration information for I2C module
1554 * @param DevAddress: Target device address
1555 * @param MemAddress: Internal memory address
1556 * @param MemAddSize: Size of internal memory address
1557 * @param pData: Pointer to data buffer
1558 * @param Size: Amount of data to be sent
1559 * @param Timeout: Timeout duration
1560 * @retval HAL status
1562 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
)
1564 /* Check the parameters */
1565 assert_param(IS_I2C_MEMADD_SIZE(MemAddSize
));
1567 if(hi2c
->State
== HAL_I2C_STATE_READY
)
1569 if((pData
== HAL_NULL
) || (Size
== 0))
1574 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
1579 /* Process Locked */
1582 hi2c
->State
= HAL_I2C_STATE_MEM_BUSY_TX
;
1583 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
1585 /* Send Slave Address and Memory Address */
1586 if(I2C_RequestMemoryWrite(hi2c
, DevAddress
, MemAddress
, MemAddSize
, Timeout
) != HAL_OK
)
1588 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
1590 /* Process Unlocked */
1596 /* Process Unlocked */
1604 /* Wait until TXE flag is set */
1605 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_TXE
, RESET
, Timeout
) != HAL_OK
)
1610 /* Write data to DR */
1611 hi2c
->Instance
->DR
= (*pData
++);
1614 if((__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BTF
) == SET
) && (Size
!= 0))
1616 /* Write data to DR */
1617 hi2c
->Instance
->DR
= (*pData
++);
1622 /* Wait until TXE flag is set */
1623 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_TXE
, RESET
, Timeout
) != HAL_OK
)
1629 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
1631 /* Wait until BUSY flag is reset */
1632 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, Timeout
) != HAL_OK
)
1637 hi2c
->State
= HAL_I2C_STATE_READY
;
1639 /* Process Unlocked */
1651 * @brief Read an amount of data in blocking mode from a specific memory address
1652 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
1653 * the configuration information for I2C module
1654 * @param DevAddress: Target device address
1655 * @param MemAddress: Internal memory address
1656 * @param MemAddSize: Size of internal memory address
1657 * @param pData: Pointer to data buffer
1658 * @param Size: Amount of data to be sent
1659 * @param Timeout: Timeout duration
1660 * @retval HAL status
1662 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
)
1664 /* Check the parameters */
1665 assert_param(IS_I2C_MEMADD_SIZE(MemAddSize
));
1667 if(hi2c
->State
== HAL_I2C_STATE_READY
)
1669 if((pData
== HAL_NULL
) || (Size
== 0))
1674 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
1679 /* Process Locked */
1682 hi2c
->State
= HAL_I2C_STATE_MEM_BUSY_RX
;
1683 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
1685 /* Send Slave Address and Memory Address */
1686 if(I2C_RequestMemoryRead(hi2c
, DevAddress
, MemAddress
, MemAddSize
, Timeout
) != HAL_OK
)
1688 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
1690 /* Process Unlocked */
1696 /* Process Unlocked */
1704 /* Disable Acknowledge */
1705 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
1707 /* Clear ADDR flag */
1708 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1711 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
1715 /* Disable Acknowledge */
1716 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
1719 hi2c
->Instance
->CR1
|= I2C_CR1_POS
;
1721 /* Clear ADDR flag */
1722 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1726 /* Clear ADDR flag */
1727 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1737 /* Wait until RXNE flag is set */
1738 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_RXNE
, RESET
, Timeout
) != HAL_OK
)
1743 /* Read data from DR */
1744 (*pData
++) = hi2c
->Instance
->DR
;
1750 /* Wait until BTF flag is set */
1751 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BTF
, RESET
, Timeout
) != HAL_OK
)
1757 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
1759 /* Read data from DR */
1760 (*pData
++) = hi2c
->Instance
->DR
;
1763 /* Read data from DR */
1764 (*pData
++) = hi2c
->Instance
->DR
;
1770 /* Wait until BTF flag is set */
1771 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BTF
, RESET
, Timeout
) != HAL_OK
)
1776 /* Disable Acknowledge */
1777 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
1779 /* Read data from DR */
1780 (*pData
++) = hi2c
->Instance
->DR
;
1783 /* Wait until BTF flag is set */
1784 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BTF
, RESET
, Timeout
) != HAL_OK
)
1790 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
1792 /* Read data from DR */
1793 (*pData
++) = hi2c
->Instance
->DR
;
1796 /* Read data from DR */
1797 (*pData
++) = hi2c
->Instance
->DR
;
1803 /* Wait until RXNE flag is set */
1804 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_RXNE
, RESET
, Timeout
) != HAL_OK
)
1809 /* Read data from DR */
1810 (*pData
++) = hi2c
->Instance
->DR
;
1813 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BTF
) == SET
)
1815 /* Read data from DR */
1816 (*pData
++) = hi2c
->Instance
->DR
;
1823 hi2c
->Instance
->CR1
&= ~I2C_CR1_POS
;
1825 /* Wait until BUSY flag is reset */
1826 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, Timeout
) != HAL_OK
)
1831 hi2c
->State
= HAL_I2C_STATE_READY
;
1833 /* Process Unlocked */
1844 * @brief Write an amount of data in no-blocking mode with Interrupt to a specific memory address
1845 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
1846 * the configuration information for I2C module
1847 * @param DevAddress: Target device address
1848 * @param MemAddress: Internal memory address
1849 * @param MemAddSize: Size of internal memory address
1850 * @param pData: Pointer to data buffer
1851 * @param Size: Amount of data to be sent
1852 * @retval HAL status
1854 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
)
1856 /* Check the parameters */
1857 assert_param(IS_I2C_MEMADD_SIZE(MemAddSize
));
1859 if(hi2c
->State
== HAL_I2C_STATE_READY
)
1861 if((pData
== HAL_NULL
) || (Size
== 0))
1866 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
1871 /* Process Locked */
1874 hi2c
->State
= HAL_I2C_STATE_MEM_BUSY_TX
;
1875 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
1877 hi2c
->pBuffPtr
= pData
;
1878 hi2c
->XferSize
= Size
;
1879 hi2c
->XferCount
= Size
;
1881 /* Send Slave Address and Memory Address */
1882 if(I2C_RequestMemoryWrite(hi2c
, DevAddress
, MemAddress
, MemAddSize
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
1884 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
1886 /* Process Unlocked */
1892 /* Process Unlocked */
1898 /* Process Unlocked */
1901 /* Note : The I2C interrupts must be enabled after unlocking current process
1902 to avoid the risk of I2C interrupt handle execution before current
1905 /* Enable EVT, BUF and ERR interrupt */
1906 __HAL_I2C_ENABLE_IT(hi2c
, I2C_IT_EVT
| I2C_IT_BUF
| I2C_IT_ERR
);
1917 * @brief Read an amount of data in no-blocking mode with Interrupt from a specific memory address
1918 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
1919 * the configuration information for I2C module
1920 * @param DevAddress: Target device address
1921 * @param MemAddress: Internal memory address
1922 * @param MemAddSize: Size of internal memory address
1923 * @param pData: Pointer to data buffer
1924 * @param Size: Amount of data to be sent
1925 * @retval HAL status
1927 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
)
1929 /* Check the parameters */
1930 assert_param(IS_I2C_MEMADD_SIZE(MemAddSize
));
1932 if(hi2c
->State
== HAL_I2C_STATE_READY
)
1934 if((pData
== HAL_NULL
) || (Size
== 0))
1939 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
1944 /* Process Locked */
1947 hi2c
->State
= HAL_I2C_STATE_MEM_BUSY_RX
;
1948 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
1950 hi2c
->pBuffPtr
= pData
;
1951 hi2c
->XferSize
= Size
;
1952 hi2c
->XferCount
= Size
;
1954 /* Send Slave Address and Memory Address */
1955 if(I2C_RequestMemoryRead(hi2c
, DevAddress
, MemAddress
, MemAddSize
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
1957 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
1959 /* Process Unlocked */
1965 /* Process Unlocked */
1971 if(hi2c
->XferCount
== 1)
1973 /* Disable Acknowledge */
1974 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
1976 /* Clear ADDR flag */
1977 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1980 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
1982 else if(hi2c
->XferCount
== 2)
1984 /* Disable Acknowledge */
1985 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
1988 hi2c
->Instance
->CR1
|= I2C_CR1_POS
;
1990 /* Clear ADDR flag */
1991 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
1995 /* Enable Acknowledge */
1996 hi2c
->Instance
->CR1
|= I2C_CR1_ACK
;
1998 /* Clear ADDR flag */
1999 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
2002 /* Process Unlocked */
2005 /* Note : The I2C interrupts must be enabled after unlocking current process
2006 to avoid the risk of I2C interrupt handle execution before current
2009 /* Enable EVT, BUF and ERR interrupt */
2010 __HAL_I2C_ENABLE_IT(hi2c
, I2C_IT_EVT
| I2C_IT_BUF
| I2C_IT_ERR
);
2020 * @brief Write an amount of data in no-blocking mode with DMA to a specific memory address
2021 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2022 * the configuration information for I2C module
2023 * @param DevAddress: Target device address
2024 * @param MemAddress: Internal memory address
2025 * @param MemAddSize: Size of internal memory address
2026 * @param pData: Pointer to data buffer
2027 * @param Size: Amount of data to be sent
2028 * @retval HAL status
2030 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
)
2032 /* Check the parameters */
2033 assert_param(IS_I2C_MEMADD_SIZE(MemAddSize
));
2035 if(hi2c
->State
== HAL_I2C_STATE_READY
)
2037 if((pData
== HAL_NULL
) || (Size
== 0))
2042 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
2047 /* Process Locked */
2050 hi2c
->State
= HAL_I2C_STATE_MEM_BUSY_TX
;
2051 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
2053 hi2c
->pBuffPtr
= pData
;
2054 hi2c
->XferSize
= Size
;
2055 hi2c
->XferCount
= Size
;
2057 /* Set the I2C DMA transfert complete callback */
2058 hi2c
->hdmatx
->XferCpltCallback
= I2C_DMAMemTransmitCplt
;
2060 /* Set the DMA error callback */
2061 hi2c
->hdmatx
->XferErrorCallback
= I2C_DMAError
;
2063 /* Enable the DMA Stream */
2064 HAL_DMA_Start_IT(hi2c
->hdmatx
, (uint32_t)pData
, (uint32_t)&hi2c
->Instance
->DR
, Size
);
2066 /* Send Slave Address and Memory Address */
2067 if(I2C_RequestMemoryWrite(hi2c
, DevAddress
, MemAddress
, MemAddSize
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
2069 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
2071 /* Process Unlocked */
2077 /* Process Unlocked */
2083 /* Enable DMA Request */
2084 hi2c
->Instance
->CR2
|= I2C_CR2_DMAEN
;
2086 /* Process Unlocked */
2098 * @brief Reads an amount of data in no-blocking mode with DMA from a specific memory address.
2099 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2100 * the configuration information for I2C module
2101 * @param DevAddress: Target device address
2102 * @param MemAddress: Internal memory address
2103 * @param MemAddSize: Size of internal memory address
2104 * @param pData: Pointer to data buffer
2105 * @param Size: Amount of data to be read
2106 * @retval HAL status
2108 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
)
2110 /* Check the parameters */
2111 assert_param(IS_I2C_MEMADD_SIZE(MemAddSize
));
2113 if(hi2c
->State
== HAL_I2C_STATE_READY
)
2115 if((pData
== HAL_NULL
) || (Size
== 0))
2120 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
2125 /* Process Locked */
2128 hi2c
->State
= HAL_I2C_STATE_MEM_BUSY_RX
;
2129 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
2131 hi2c
->pBuffPtr
= pData
;
2132 hi2c
->XferSize
= Size
;
2133 hi2c
->XferCount
= Size
;
2135 /* Set the I2C DMA transfert complete callback */
2136 hi2c
->hdmarx
->XferCpltCallback
= I2C_DMAMemReceiveCplt
;
2138 /* Set the DMA error callback */
2139 hi2c
->hdmarx
->XferErrorCallback
= I2C_DMAError
;
2141 /* Enable the DMA Stream */
2142 HAL_DMA_Start_IT(hi2c
->hdmarx
, (uint32_t)&hi2c
->Instance
->DR
, (uint32_t)pData
, Size
);
2144 /* Send Slave Address and Memory Address */
2145 if(I2C_RequestMemoryRead(hi2c
, DevAddress
, MemAddress
, MemAddSize
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
2147 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
2149 /* Process Unlocked */
2155 /* Process Unlocked */
2163 /* Disable Acknowledge */
2164 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
2168 /* Enable Last DMA bit */
2169 hi2c
->Instance
->CR2
|= I2C_CR2_LAST
;
2172 /* Enable DMA Request */
2173 hi2c
->Instance
->CR2
|= I2C_CR2_DMAEN
;
2175 /* Clear ADDR flag */
2176 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
2178 /* Process Unlocked */
2190 * @brief Checks if target device is ready for communication.
2191 * @note This function is used with Memory devices
2192 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2193 * the configuration information for I2C module
2194 * @param DevAddress: Target device address
2195 * @param Trials: Number of trials
2196 * @param Timeout: Timeout duration
2197 * @retval HAL status
2199 HAL_StatusTypeDef
HAL_I2C_IsDeviceReady(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint32_t Trials
, uint32_t Timeout
)
2201 uint32_t tickstart
= 0, tmp1
= 0, tmp2
= 0, tmp3
= 0, I2C_Trials
= 1;
2203 if(hi2c
->State
== HAL_I2C_STATE_READY
)
2205 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BUSY
) == SET
)
2210 /* Process Locked */
2213 hi2c
->State
= HAL_I2C_STATE_BUSY
;
2214 hi2c
->ErrorCode
= HAL_I2C_ERROR_NONE
;
2218 /* Generate Start */
2219 hi2c
->Instance
->CR1
|= I2C_CR1_START
;
2221 /* Wait until SB flag is set */
2222 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_SB
, RESET
, Timeout
) != HAL_OK
)
2227 /* Send slave address */
2228 hi2c
->Instance
->DR
= __HAL_I2C_7BIT_ADD_WRITE(DevAddress
);
2230 /* Wait until ADDR or AF flag are set */
2232 tickstart
= HAL_GetTick();
2234 tmp1
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_ADDR
);
2235 tmp2
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_AF
);
2237 while((tmp1
== RESET
) && (tmp2
== RESET
) && (tmp3
!= HAL_I2C_STATE_TIMEOUT
))
2239 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
2241 hi2c
->State
= HAL_I2C_STATE_TIMEOUT
;
2243 tmp1
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_ADDR
);
2244 tmp2
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_AF
);
2248 hi2c
->State
= HAL_I2C_STATE_READY
;
2250 /* Check if the ADDR flag has been set */
2251 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_ADDR
) == SET
)
2254 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
2256 /* Clear ADDR Flag */
2257 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
2259 /* Wait until BUSY flag is reset */
2260 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, Timeout
) != HAL_OK
)
2265 hi2c
->State
= HAL_I2C_STATE_READY
;
2267 /* Process Unlocked */
2275 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
2278 __HAL_I2C_CLEAR_FLAG(hi2c
, I2C_FLAG_AF
);
2280 /* Wait until BUSY flag is reset */
2281 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, Timeout
) != HAL_OK
)
2286 }while(I2C_Trials
++ < Trials
);
2288 hi2c
->State
= HAL_I2C_STATE_READY
;
2290 /* Process Unlocked */
2302 * @brief This function handles I2C event interrupt request.
2303 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2304 * the configuration information for I2C module
2305 * @retval HAL status
2307 void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef
*hi2c
)
2309 uint32_t tmp1
= 0, tmp2
= 0, tmp3
= 0, tmp4
= 0;
2310 /* Master mode selected */
2311 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_MSL
) == SET
)
2313 /* I2C in mode Transmitter -----------------------------------------------*/
2314 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_TRA
) == SET
)
2316 tmp1
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_TXE
);
2317 tmp2
= __HAL_I2C_GET_IT_SOURCE(hi2c
, I2C_IT_BUF
);
2318 tmp3
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BTF
);
2319 tmp4
= __HAL_I2C_GET_IT_SOURCE(hi2c
, I2C_IT_EVT
);
2320 /* TXE set and BTF reset -----------------------------------------------*/
2321 if((tmp1
== SET
) && (tmp2
== SET
) && (tmp3
== RESET
))
2323 I2C_MasterTransmit_TXE(hi2c
);
2325 /* BTF set -------------------------------------------------------------*/
2326 else if((tmp3
== SET
) && (tmp4
== SET
))
2328 I2C_MasterTransmit_BTF(hi2c
);
2331 /* I2C in mode Receiver --------------------------------------------------*/
2334 tmp1
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_RXNE
);
2335 tmp2
= __HAL_I2C_GET_IT_SOURCE(hi2c
, I2C_IT_BUF
);
2336 tmp3
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BTF
);
2337 tmp4
= __HAL_I2C_GET_IT_SOURCE(hi2c
, I2C_IT_EVT
);
2338 /* RXNE set and BTF reset -----------------------------------------------*/
2339 if((tmp1
== SET
) && (tmp2
== SET
) && (tmp3
== RESET
))
2341 I2C_MasterReceive_RXNE(hi2c
);
2343 /* BTF set -------------------------------------------------------------*/
2344 else if((tmp3
== SET
) && (tmp4
== SET
))
2346 I2C_MasterReceive_BTF(hi2c
);
2350 /* Slave mode selected */
2353 tmp1
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_ADDR
);
2354 tmp2
= __HAL_I2C_GET_IT_SOURCE(hi2c
, (I2C_IT_EVT
));
2355 tmp3
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_STOPF
);
2356 tmp4
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_TRA
);
2357 /* ADDR set --------------------------------------------------------------*/
2358 if((tmp1
== SET
) && (tmp2
== SET
))
2360 I2C_Slave_ADDR(hi2c
);
2362 /* STOPF set --------------------------------------------------------------*/
2363 else if((tmp3
== SET
) && (tmp2
== SET
))
2365 I2C_Slave_STOPF(hi2c
);
2367 /* I2C in mode Transmitter -----------------------------------------------*/
2368 else if(tmp4
== SET
)
2370 tmp1
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_TXE
);
2371 tmp2
= __HAL_I2C_GET_IT_SOURCE(hi2c
, I2C_IT_BUF
);
2372 tmp3
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BTF
);
2373 tmp4
= __HAL_I2C_GET_IT_SOURCE(hi2c
, I2C_IT_EVT
);
2374 /* TXE set and BTF reset -----------------------------------------------*/
2375 if((tmp1
== SET
) && (tmp2
== SET
) && (tmp3
== RESET
))
2377 I2C_SlaveTransmit_TXE(hi2c
);
2379 /* BTF set -------------------------------------------------------------*/
2380 else if((tmp3
== SET
) && (tmp4
== SET
))
2382 I2C_SlaveTransmit_BTF(hi2c
);
2385 /* I2C in mode Receiver --------------------------------------------------*/
2388 tmp1
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_RXNE
);
2389 tmp2
= __HAL_I2C_GET_IT_SOURCE(hi2c
, I2C_IT_BUF
);
2390 tmp3
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BTF
);
2391 tmp4
= __HAL_I2C_GET_IT_SOURCE(hi2c
, I2C_IT_EVT
);
2392 /* RXNE set and BTF reset ----------------------------------------------*/
2393 if((tmp1
== SET
) && (tmp2
== SET
) && (tmp3
== RESET
))
2395 I2C_SlaveReceive_RXNE(hi2c
);
2397 /* BTF set -------------------------------------------------------------*/
2398 else if((tmp3
== SET
) && (tmp4
== SET
))
2400 I2C_SlaveReceive_BTF(hi2c
);
2407 * @brief This function handles I2C error interrupt request.
2408 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2409 * the configuration information for I2C module
2410 * @retval HAL status
2412 void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef
*hi2c
)
2414 uint32_t tmp1
= 0, tmp2
= 0, tmp3
= 0;
2416 tmp1
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_BERR
);
2417 tmp2
= __HAL_I2C_GET_IT_SOURCE(hi2c
, I2C_IT_ERR
);
2418 /* I2C Bus error interrupt occurred ----------------------------------------*/
2419 if((tmp1
== SET
) && (tmp2
== SET
))
2421 hi2c
->ErrorCode
|= HAL_I2C_ERROR_BERR
;
2423 /* Clear BERR flag */
2424 __HAL_I2C_CLEAR_FLAG(hi2c
, I2C_FLAG_BERR
);
2427 tmp1
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_ARLO
);
2428 tmp2
= __HAL_I2C_GET_IT_SOURCE(hi2c
, I2C_IT_ERR
);
2429 /* I2C Arbitration Loss error interrupt occurred ---------------------------*/
2430 if((tmp1
== SET
) && (tmp2
== SET
))
2432 hi2c
->ErrorCode
|= HAL_I2C_ERROR_ARLO
;
2434 /* Clear ARLO flag */
2435 __HAL_I2C_CLEAR_FLAG(hi2c
, I2C_FLAG_ARLO
);
2438 tmp1
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_AF
);
2439 tmp2
= __HAL_I2C_GET_IT_SOURCE(hi2c
, I2C_IT_ERR
);
2440 /* I2C Acknowledge failure error interrupt occurred ------------------------*/
2441 if((tmp1
== SET
) && (tmp2
== SET
))
2443 tmp1
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_MSL
);
2444 tmp2
= hi2c
->XferCount
;
2446 if((tmp1
== RESET
) && (tmp2
== 0) && (tmp3
== HAL_I2C_STATE_BUSY_TX
))
2452 hi2c
->ErrorCode
|= HAL_I2C_ERROR_AF
;
2454 __HAL_I2C_CLEAR_FLAG(hi2c
, I2C_FLAG_AF
);
2458 tmp1
= __HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_OVR
);
2459 tmp2
= __HAL_I2C_GET_IT_SOURCE(hi2c
, I2C_IT_ERR
);
2460 /* I2C Over-Run/Under-Run interrupt occurred -------------------------------*/
2461 if((tmp1
== SET
) && (tmp2
== SET
))
2463 hi2c
->ErrorCode
|= HAL_I2C_ERROR_OVR
;
2464 /* Clear OVR flag */
2465 __HAL_I2C_CLEAR_FLAG(hi2c
, I2C_FLAG_OVR
);
2468 if(hi2c
->ErrorCode
!= HAL_I2C_ERROR_NONE
)
2470 hi2c
->State
= HAL_I2C_STATE_READY
;
2472 HAL_I2C_ErrorCallback(hi2c
);
2477 * @brief Master Tx Transfer completed callbacks.
2478 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2479 * the configuration information for I2C module
2482 __weak
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef
*hi2c
)
2484 /* NOTE : This function Should not be modified, when the callback is needed,
2485 the HAL_I2C_TxCpltCallback could be implemented in the user file
2490 * @brief Master Rx Transfer completed callbacks.
2491 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2492 * the configuration information for I2C module
2495 __weak
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef
*hi2c
)
2497 /* NOTE : This function Should not be modified, when the callback is needed,
2498 the HAL_I2C_TxCpltCallback could be implemented in the user file
2502 /** @brief Slave Tx Transfer completed callbacks.
2503 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2504 * the configuration information for I2C module
2507 __weak
void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef
*hi2c
)
2509 /* NOTE : This function Should not be modified, when the callback is needed,
2510 the HAL_I2C_TxCpltCallback could be implemented in the user file
2515 * @brief Slave Rx Transfer completed callbacks.
2516 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2517 * the configuration information for I2C module
2520 __weak
void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef
*hi2c
)
2522 /* NOTE : This function Should not be modified, when the callback is needed,
2523 the HAL_I2C_TxCpltCallback could be implemented in the user file
2528 * @brief Memory Tx Transfer completed callbacks.
2529 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2530 * the configuration information for I2C module
2533 __weak
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef
*hi2c
)
2535 /* NOTE : This function Should not be modified, when the callback is needed,
2536 the HAL_I2C_TxCpltCallback could be implemented in the user file
2541 * @brief Memory Rx Transfer completed callbacks.
2542 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2543 * the configuration information for I2C module
2546 __weak
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef
*hi2c
)
2548 /* NOTE : This function Should not be modified, when the callback is needed,
2549 the HAL_I2C_TxCpltCallback could be implemented in the user file
2554 * @brief I2C error callbacks.
2555 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2556 * the configuration information for I2C module
2559 __weak
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef
*hi2c
)
2561 /* NOTE : This function Should not be modified, when the callback is needed,
2562 the HAL_I2C_ErrorCallback could be implemented in the user file
2570 /** @defgroup I2C_Group3 Peripheral State and Errors functions
2571 * @brief Peripheral State and Errors functions
2574 ===============================================================================
2575 ##### Peripheral State and Errors functions #####
2576 ===============================================================================
2578 This subsection permits to get in run-time the status of the peripheral
2586 * @brief Returns the I2C state.
2587 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2588 * the configuration information for I2C module
2591 HAL_I2C_StateTypeDef
HAL_I2C_GetState(I2C_HandleTypeDef
*hi2c
)
2597 * @brief Return the I2C error code
2598 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
2599 * the configuration information for the specified I2C.
2600 * @retval I2C Error Code
2602 uint32_t HAL_I2C_GetError(I2C_HandleTypeDef
*hi2c
)
2604 return hi2c
->ErrorCode
;
2612 * @brief Handle TXE flag for Master
2613 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2614 * the configuration information for I2C module
2615 * @retval HAL status
2617 static HAL_StatusTypeDef
I2C_MasterTransmit_TXE(I2C_HandleTypeDef
*hi2c
)
2619 /* Write data to DR */
2620 hi2c
->Instance
->DR
= (*hi2c
->pBuffPtr
++);
2623 if(hi2c
->XferCount
== 0)
2625 /* Disable BUF interrupt */
2626 __HAL_I2C_DISABLE_IT(hi2c
, I2C_IT_BUF
);
2633 * @brief Handle BTF flag for Master transmitter
2634 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2635 * the configuration information for I2C module
2636 * @retval HAL status
2638 static HAL_StatusTypeDef
I2C_MasterTransmit_BTF(I2C_HandleTypeDef
*hi2c
)
2640 if(hi2c
->XferCount
!= 0)
2642 /* Write data to DR */
2643 hi2c
->Instance
->DR
= (*hi2c
->pBuffPtr
++);
2648 /* Disable EVT, BUF and ERR interrupt */
2649 __HAL_I2C_DISABLE_IT(hi2c
, I2C_IT_EVT
| I2C_IT_BUF
| I2C_IT_ERR
);
2652 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
2654 /* Wait until BUSY flag is reset */
2655 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
2660 if(hi2c
->State
== HAL_I2C_STATE_MEM_BUSY_TX
)
2662 hi2c
->State
= HAL_I2C_STATE_READY
;
2664 HAL_I2C_MemTxCpltCallback(hi2c
);
2668 hi2c
->State
= HAL_I2C_STATE_READY
;
2670 HAL_I2C_MasterTxCpltCallback(hi2c
);
2677 * @brief Handle RXNE flag for Master
2678 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2679 * the configuration information for I2C module
2680 * @retval HAL status
2682 static HAL_StatusTypeDef
I2C_MasterReceive_RXNE(I2C_HandleTypeDef
*hi2c
)
2686 tmp
= hi2c
->XferCount
;
2689 /* Read data from DR */
2690 (*hi2c
->pBuffPtr
++) = hi2c
->Instance
->DR
;
2693 else if((tmp
== 2) || (tmp
== 3))
2695 /* Disable BUF interrupt */
2696 __HAL_I2C_DISABLE_IT(hi2c
, I2C_IT_BUF
);
2700 /* Disable EVT, BUF and ERR interrupt */
2701 __HAL_I2C_DISABLE_IT(hi2c
, I2C_IT_EVT
| I2C_IT_BUF
| I2C_IT_ERR
);
2703 /* Read data from DR */
2704 (*hi2c
->pBuffPtr
++) = hi2c
->Instance
->DR
;
2707 /* Wait until BUSY flag is reset */
2708 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
2713 if(hi2c
->State
== HAL_I2C_STATE_MEM_BUSY_RX
)
2715 hi2c
->State
= HAL_I2C_STATE_READY
;
2717 HAL_I2C_MemRxCpltCallback(hi2c
);
2721 hi2c
->State
= HAL_I2C_STATE_READY
;
2723 HAL_I2C_MasterRxCpltCallback(hi2c
);
2730 * @brief Handle BTF flag for Master receiver
2731 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2732 * the configuration information for I2C module
2733 * @retval HAL status
2735 static HAL_StatusTypeDef
I2C_MasterReceive_BTF(I2C_HandleTypeDef
*hi2c
)
2737 if(hi2c
->XferCount
== 3)
2739 /* Disable Acknowledge */
2740 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
2742 /* Read data from DR */
2743 (*hi2c
->pBuffPtr
++) = hi2c
->Instance
->DR
;
2746 else if(hi2c
->XferCount
== 2)
2749 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
2751 /* Read data from DR */
2752 (*hi2c
->pBuffPtr
++) = hi2c
->Instance
->DR
;
2755 /* Read data from DR */
2756 (*hi2c
->pBuffPtr
++) = hi2c
->Instance
->DR
;
2759 /* Disable EVT and ERR interrupt */
2760 __HAL_I2C_DISABLE_IT(hi2c
, I2C_IT_EVT
| I2C_IT_ERR
);
2762 /* Wait until BUSY flag is reset */
2763 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
2768 if(hi2c
->State
== HAL_I2C_STATE_MEM_BUSY_RX
)
2770 hi2c
->State
= HAL_I2C_STATE_READY
;
2772 HAL_I2C_MemRxCpltCallback(hi2c
);
2776 hi2c
->State
= HAL_I2C_STATE_READY
;
2778 HAL_I2C_MasterRxCpltCallback(hi2c
);
2783 /* Read data from DR */
2784 (*hi2c
->pBuffPtr
++) = hi2c
->Instance
->DR
;
2791 * @brief Handle TXE flag for Slave
2792 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2793 * the configuration information for I2C module
2794 * @retval HAL status
2796 static HAL_StatusTypeDef
I2C_SlaveTransmit_TXE(I2C_HandleTypeDef
*hi2c
)
2798 if(hi2c
->XferCount
!= 0)
2800 /* Write data to DR */
2801 hi2c
->Instance
->DR
= (*hi2c
->pBuffPtr
++);
2808 * @brief Handle BTF flag for Slave transmitter
2809 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2810 * the configuration information for I2C module
2811 * @retval HAL status
2813 static HAL_StatusTypeDef
I2C_SlaveTransmit_BTF(I2C_HandleTypeDef
*hi2c
)
2815 if(hi2c
->XferCount
!= 0)
2817 /* Write data to DR */
2818 hi2c
->Instance
->DR
= (*hi2c
->pBuffPtr
++);
2825 * @brief Handle RXNE flag for Slave
2826 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2827 * the configuration information for I2C module
2828 * @retval HAL status
2830 static HAL_StatusTypeDef
I2C_SlaveReceive_RXNE(I2C_HandleTypeDef
*hi2c
)
2832 if(hi2c
->XferCount
!= 0)
2834 /* Read data from DR */
2835 (*hi2c
->pBuffPtr
++) = hi2c
->Instance
->DR
;
2842 * @brief Handle BTF flag for Slave receiver
2843 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2844 * the configuration information for I2C module
2845 * @retval HAL status
2847 static HAL_StatusTypeDef
I2C_SlaveReceive_BTF(I2C_HandleTypeDef
*hi2c
)
2849 if(hi2c
->XferCount
!= 0)
2851 /* Read data from DR */
2852 (*hi2c
->pBuffPtr
++) = hi2c
->Instance
->DR
;
2859 * @brief Handle ADD flag for Slave
2860 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2861 * the configuration information for I2C module
2862 * @retval HAL status
2864 static HAL_StatusTypeDef
I2C_Slave_ADDR(I2C_HandleTypeDef
*hi2c
)
2866 /* Clear ADDR flag */
2867 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
2873 * @brief Handle STOPF flag for Slave
2874 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2875 * the configuration information for I2C module
2876 * @retval HAL status
2878 static HAL_StatusTypeDef
I2C_Slave_STOPF(I2C_HandleTypeDef
*hi2c
)
2880 /* Disable EVT, BUF and ERR interrupt */
2881 __HAL_I2C_DISABLE_IT(hi2c
, I2C_IT_EVT
| I2C_IT_BUF
| I2C_IT_ERR
);
2883 /* Clear STOPF flag */
2884 __HAL_I2C_CLEAR_STOPFLAG(hi2c
);
2886 /* Disable Acknowledge */
2887 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
2889 /* Wait until BUSY flag is reset */
2890 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
2895 hi2c
->State
= HAL_I2C_STATE_READY
;
2897 HAL_I2C_SlaveRxCpltCallback(hi2c
);
2903 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2904 * the configuration information for I2C module
2905 * @retval HAL status
2907 static HAL_StatusTypeDef
I2C_Slave_AF(I2C_HandleTypeDef
*hi2c
)
2909 /* Disable EVT, BUF and ERR interrupt */
2910 __HAL_I2C_DISABLE_IT(hi2c
, I2C_IT_EVT
| I2C_IT_BUF
| I2C_IT_ERR
);
2913 __HAL_I2C_CLEAR_FLAG(hi2c
, I2C_FLAG_AF
);
2915 /* Disable Acknowledge */
2916 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
2918 /* Wait until BUSY flag is reset */
2919 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
2924 hi2c
->State
= HAL_I2C_STATE_READY
;
2926 HAL_I2C_SlaveTxCpltCallback(hi2c
);
2932 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2933 * the configuration information for I2C module
2934 * @param DevAddress: Target device address
2935 * @retval HAL status
2937 static HAL_StatusTypeDef
I2C_MasterRequestWrite(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint32_t Timeout
)
2939 /* Generate Start */
2940 hi2c
->Instance
->CR1
|= I2C_CR1_START
;
2942 /* Wait until SB flag is set */
2943 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_SB
, RESET
, Timeout
) != HAL_OK
)
2948 if(hi2c
->Init
.AddressingMode
== I2C_ADDRESSINGMODE_7BIT
)
2950 /* Send slave address */
2951 hi2c
->Instance
->DR
= __HAL_I2C_7BIT_ADD_WRITE(DevAddress
);
2955 /* Send header of slave address */
2956 hi2c
->Instance
->DR
= __HAL_I2C_10BIT_HEADER_WRITE(DevAddress
);
2958 /* Wait until ADD10 flag is set */
2959 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c
, I2C_FLAG_ADD10
, Timeout
) != HAL_OK
)
2961 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
2971 /* Send slave address */
2972 hi2c
->Instance
->DR
= __HAL_I2C_10BIT_ADDRESS(DevAddress
);
2975 /* Wait until ADDR flag is set */
2976 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c
, I2C_FLAG_ADDR
, Timeout
) != HAL_OK
)
2978 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
2992 * @brief Master sends target device address for read request.
2993 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
2994 * the configuration information for I2C module
2995 * @param DevAddress: Target device address
2996 * @retval HAL status
2998 static HAL_StatusTypeDef
I2C_MasterRequestRead(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint32_t Timeout
)
3000 /* Enable Acknowledge */
3001 hi2c
->Instance
->CR1
|= I2C_CR1_ACK
;
3003 /* Generate Start */
3004 hi2c
->Instance
->CR1
|= I2C_CR1_START
;
3006 /* Wait until SB flag is set */
3007 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_SB
, RESET
, Timeout
) != HAL_OK
)
3012 if(hi2c
->Init
.AddressingMode
== I2C_ADDRESSINGMODE_7BIT
)
3014 /* Send slave address */
3015 hi2c
->Instance
->DR
= __HAL_I2C_7BIT_ADD_READ(DevAddress
);
3019 /* Send header of slave address */
3020 hi2c
->Instance
->DR
= __HAL_I2C_10BIT_HEADER_WRITE(DevAddress
);
3022 /* Wait until ADD10 flag is set */
3023 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c
, I2C_FLAG_ADD10
, Timeout
) != HAL_OK
)
3025 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
3035 /* Send slave address */
3036 hi2c
->Instance
->DR
= __HAL_I2C_10BIT_ADDRESS(DevAddress
);
3038 /* Wait until ADDR flag is set */
3039 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c
, I2C_FLAG_ADDR
, Timeout
) != HAL_OK
)
3041 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
3051 /* Clear ADDR flag */
3052 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
3054 /* Generate Restart */
3055 hi2c
->Instance
->CR1
|= I2C_CR1_START
;
3057 /* Wait until SB flag is set */
3058 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_SB
, RESET
, Timeout
) != HAL_OK
)
3063 /* Send header of slave address */
3064 hi2c
->Instance
->DR
= __HAL_I2C_10BIT_HEADER_READ(DevAddress
);
3067 /* Wait until ADDR flag is set */
3068 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c
, I2C_FLAG_ADDR
, Timeout
) != HAL_OK
)
3070 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
3084 * @brief Master sends target device address followed by internal memory address for write request.
3085 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
3086 * the configuration information for I2C module
3087 * @param DevAddress: Target device address
3088 * @param MemAddress: Internal memory address
3089 * @param MemAddSize: Size of internal memory address
3090 * @retval HAL status
3092 static HAL_StatusTypeDef
I2C_RequestMemoryWrite(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint16_t MemAddress
, uint16_t MemAddSize
, uint32_t Timeout
)
3094 /* Generate Start */
3095 hi2c
->Instance
->CR1
|= I2C_CR1_START
;
3097 /* Wait until SB flag is set */
3098 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_SB
, RESET
, Timeout
) != HAL_OK
)
3103 /* Send slave address */
3104 hi2c
->Instance
->DR
= __HAL_I2C_7BIT_ADD_WRITE(DevAddress
);
3106 /* Wait until ADDR flag is set */
3107 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c
, I2C_FLAG_ADDR
, Timeout
) != HAL_OK
)
3109 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
3119 /* Clear ADDR flag */
3120 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
3122 /* Wait until TXE flag is set */
3123 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_TXE
, RESET
, Timeout
) != HAL_OK
)
3128 /* If Memory address size is 8Bit */
3129 if(MemAddSize
== I2C_MEMADD_SIZE_8BIT
)
3131 /* Send Memory Address */
3132 hi2c
->Instance
->DR
= __HAL_I2C_MEM_ADD_LSB(MemAddress
);
3134 /* If Memory address size is 16Bit */
3137 /* Send MSB of Memory Address */
3138 hi2c
->Instance
->DR
= __HAL_I2C_MEM_ADD_MSB(MemAddress
);
3140 /* Wait until TXE flag is set */
3141 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_TXE
, RESET
, Timeout
) != HAL_OK
)
3146 /* Send LSB of Memory Address */
3147 hi2c
->Instance
->DR
= __HAL_I2C_MEM_ADD_LSB(MemAddress
);
3154 * @brief Master sends target device address followed by internal memory address for read request.
3155 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
3156 * the configuration information for I2C module
3157 * @param DevAddress: Target device address
3158 * @param MemAddress: Internal memory address
3159 * @param MemAddSize: Size of internal memory address
3160 * @retval HAL status
3162 static HAL_StatusTypeDef
I2C_RequestMemoryRead(I2C_HandleTypeDef
*hi2c
, uint16_t DevAddress
, uint16_t MemAddress
, uint16_t MemAddSize
, uint32_t Timeout
)
3164 /* Enable Acknowledge */
3165 hi2c
->Instance
->CR1
|= I2C_CR1_ACK
;
3167 /* Generate Start */
3168 hi2c
->Instance
->CR1
|= I2C_CR1_START
;
3170 /* Wait until SB flag is set */
3171 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_SB
, RESET
, Timeout
) != HAL_OK
)
3176 /* Send slave address */
3177 hi2c
->Instance
->DR
= __HAL_I2C_7BIT_ADD_WRITE(DevAddress
);
3179 /* Wait until ADDR flag is set */
3180 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c
, I2C_FLAG_ADDR
, Timeout
) != HAL_OK
)
3182 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
3192 /* Clear ADDR flag */
3193 __HAL_I2C_CLEAR_ADDRFLAG(hi2c
);
3195 /* Wait until TXE flag is set */
3196 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_TXE
, RESET
, Timeout
) != HAL_OK
)
3201 /* If Memory address size is 8Bit */
3202 if(MemAddSize
== I2C_MEMADD_SIZE_8BIT
)
3204 /* Send Memory Address */
3205 hi2c
->Instance
->DR
= __HAL_I2C_MEM_ADD_LSB(MemAddress
);
3207 /* If Memory address size is 16Bit */
3210 /* Send MSB of Memory Address */
3211 hi2c
->Instance
->DR
= __HAL_I2C_MEM_ADD_MSB(MemAddress
);
3213 /* Wait until TXE flag is set */
3214 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_TXE
, RESET
, Timeout
) != HAL_OK
)
3219 /* Send LSB of Memory Address */
3220 hi2c
->Instance
->DR
= __HAL_I2C_MEM_ADD_LSB(MemAddress
);
3223 /* Wait until TXE flag is set */
3224 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_TXE
, RESET
, Timeout
) != HAL_OK
)
3229 /* Generate Restart */
3230 hi2c
->Instance
->CR1
|= I2C_CR1_START
;
3232 /* Wait until SB flag is set */
3233 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_SB
, RESET
, Timeout
) != HAL_OK
)
3238 /* Send slave address */
3239 hi2c
->Instance
->DR
= __HAL_I2C_7BIT_ADD_READ(DevAddress
);
3241 /* Wait until ADDR flag is set */
3242 if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c
, I2C_FLAG_ADDR
, Timeout
) != HAL_OK
)
3244 if(hi2c
->ErrorCode
== HAL_I2C_ERROR_AF
)
3258 * @brief DMA I2C master transmit process complete callback.
3259 * @param hdma: DMA handle
3262 static void I2C_DMAMasterTransmitCplt(DMA_HandleTypeDef
*hdma
)
3264 I2C_HandleTypeDef
* hi2c
= (I2C_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
3266 /* Wait until BTF flag is reset */
3267 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BTF
, RESET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
3269 hi2c
->ErrorCode
|= HAL_I2C_ERROR_TIMEOUT
;
3273 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
3275 /* Disable DMA Request */
3276 hi2c
->Instance
->CR2
&= ~I2C_CR2_DMAEN
;
3278 hi2c
->XferCount
= 0;
3280 /* Wait until BUSY flag is reset */
3281 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
3283 hi2c
->ErrorCode
|= HAL_I2C_ERROR_TIMEOUT
;
3286 hi2c
->State
= HAL_I2C_STATE_READY
;
3288 /* Check if Errors has been detected during transfer */
3289 if(hi2c
->ErrorCode
!= HAL_I2C_ERROR_NONE
)
3291 HAL_I2C_ErrorCallback(hi2c
);
3295 HAL_I2C_MasterTxCpltCallback(hi2c
);
3300 * @brief DMA I2C slave transmit process complete callback.
3301 * @param hdma: DMA handle
3304 static void I2C_DMASlaveTransmitCplt(DMA_HandleTypeDef
*hdma
)
3306 I2C_HandleTypeDef
* hi2c
= (I2C_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
3308 /* Wait until AF flag is reset */
3309 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_AF
, RESET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
3311 hi2c
->ErrorCode
|= HAL_I2C_ERROR_TIMEOUT
;
3315 __HAL_I2C_CLEAR_FLAG(hi2c
, I2C_FLAG_AF
);
3317 /* Disable Address Acknowledge */
3318 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
3320 /* Disable DMA Request */
3321 hi2c
->Instance
->CR2
&= ~I2C_CR2_DMAEN
;
3323 hi2c
->XferCount
= 0;
3325 /* Wait until BUSY flag is reset */
3326 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
3328 hi2c
->ErrorCode
|= HAL_I2C_ERROR_TIMEOUT
;
3331 hi2c
->State
= HAL_I2C_STATE_READY
;
3333 /* Check if Errors has been detected during transfer */
3334 if(hi2c
->ErrorCode
!= HAL_I2C_ERROR_NONE
)
3336 HAL_I2C_ErrorCallback(hi2c
);
3340 HAL_I2C_SlaveTxCpltCallback(hi2c
);
3345 * @brief DMA I2C master receive process complete callback
3346 * @param hdma: DMA handle
3349 static void I2C_DMAMasterReceiveCplt(DMA_HandleTypeDef
*hdma
)
3351 I2C_HandleTypeDef
* hi2c
= (I2C_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
3354 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
3356 /* Disable Last DMA */
3357 hi2c
->Instance
->CR2
&= ~I2C_CR2_LAST
;
3359 /* Disable Acknowledge */
3360 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
3362 /* Disable DMA Request */
3363 hi2c
->Instance
->CR2
&= ~I2C_CR2_DMAEN
;
3365 hi2c
->XferCount
= 0;
3367 /* Wait until BUSY flag is reset */
3368 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
3370 hi2c
->ErrorCode
|= HAL_I2C_ERROR_TIMEOUT
;
3373 hi2c
->State
= HAL_I2C_STATE_READY
;
3375 /* Check if Errors has been detected during transfer */
3376 if(hi2c
->ErrorCode
!= HAL_I2C_ERROR_NONE
)
3378 HAL_I2C_ErrorCallback(hi2c
);
3382 HAL_I2C_MasterRxCpltCallback(hi2c
);
3387 * @brief DMA I2C slave receive process complete callback.
3388 * @param hdma: DMA handle
3391 static void I2C_DMASlaveReceiveCplt(DMA_HandleTypeDef
*hdma
)
3393 I2C_HandleTypeDef
* hi2c
= (I2C_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
3395 /* Wait until STOPF flag is reset */
3396 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_STOPF
, RESET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
3398 hi2c
->ErrorCode
|= HAL_I2C_ERROR_TIMEOUT
;
3401 /* Clear STOPF flag */
3402 __HAL_I2C_CLEAR_STOPFLAG(hi2c
);
3404 /* Disable Address Acknowledge */
3405 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
3407 /* Disable DMA Request */
3408 hi2c
->Instance
->CR2
&= ~I2C_CR2_DMAEN
;
3410 hi2c
->XferCount
= 0;
3412 /* Wait until BUSY flag is reset */
3413 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
3415 hi2c
->ErrorCode
|= HAL_I2C_ERROR_TIMEOUT
;
3418 hi2c
->State
= HAL_I2C_STATE_READY
;
3420 /* Check if Errors has been detected during transfer */
3421 if(hi2c
->ErrorCode
!= HAL_I2C_ERROR_NONE
)
3423 HAL_I2C_ErrorCallback(hi2c
);
3427 HAL_I2C_SlaveRxCpltCallback(hi2c
);
3432 * @brief DMA I2C Memory Write process complete callback
3433 * @param hdma: DMA handle
3436 static void I2C_DMAMemTransmitCplt(DMA_HandleTypeDef
*hdma
)
3438 I2C_HandleTypeDef
* hi2c
= (I2C_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
3440 /* Wait until BTF flag is reset */
3441 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BTF
, RESET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
3443 hi2c
->ErrorCode
|= HAL_I2C_ERROR_TIMEOUT
;
3447 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
3449 /* Disable DMA Request */
3450 hi2c
->Instance
->CR2
&= ~I2C_CR2_DMAEN
;
3452 hi2c
->XferCount
= 0;
3454 /* Wait until BUSY flag is reset */
3455 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
3457 hi2c
->ErrorCode
|= HAL_I2C_ERROR_TIMEOUT
;
3460 hi2c
->State
= HAL_I2C_STATE_READY
;
3462 /* Check if Errors has been detected during transfer */
3463 if(hi2c
->ErrorCode
!= HAL_I2C_ERROR_NONE
)
3465 HAL_I2C_ErrorCallback(hi2c
);
3469 HAL_I2C_MemTxCpltCallback(hi2c
);
3474 * @brief DMA I2C Memory Read process complete callback
3475 * @param hdma: DMA handle
3478 static void I2C_DMAMemReceiveCplt(DMA_HandleTypeDef
*hdma
)
3480 I2C_HandleTypeDef
* hi2c
= (I2C_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
3483 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
3485 /* Disable Last DMA */
3486 hi2c
->Instance
->CR2
&= ~I2C_CR2_LAST
;
3488 /* Disable Acknowledge */
3489 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
3491 /* Disable DMA Request */
3492 hi2c
->Instance
->CR2
&= ~I2C_CR2_DMAEN
;
3494 hi2c
->XferCount
= 0;
3496 /* Wait until BUSY flag is reset */
3497 if(I2C_WaitOnFlagUntilTimeout(hi2c
, I2C_FLAG_BUSY
, SET
, I2C_TIMEOUT_FLAG
) != HAL_OK
)
3499 hi2c
->ErrorCode
|= HAL_I2C_ERROR_TIMEOUT
;
3502 hi2c
->State
= HAL_I2C_STATE_READY
;
3504 /* Check if Errors has been detected during transfer */
3505 if(hi2c
->ErrorCode
!= HAL_I2C_ERROR_NONE
)
3507 HAL_I2C_ErrorCallback(hi2c
);
3511 HAL_I2C_MemRxCpltCallback(hi2c
);
3516 * @brief DMA I2C communication error callback.
3517 * @param hdma: DMA handle
3520 static void I2C_DMAError(DMA_HandleTypeDef
*hdma
)
3522 I2C_HandleTypeDef
* hi2c
= (I2C_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
3524 /* Disable Acknowledge */
3525 hi2c
->Instance
->CR1
&= ~I2C_CR1_ACK
;
3527 hi2c
->XferCount
= 0;
3529 hi2c
->State
= HAL_I2C_STATE_READY
;
3531 hi2c
->ErrorCode
|= HAL_I2C_ERROR_DMA
;
3533 HAL_I2C_ErrorCallback(hi2c
);
3537 * @brief This function handles I2C Communication Timeout.
3538 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
3539 * the configuration information for I2C module
3540 * @param Flag: specifies the I2C flag to check.
3541 * @param Status: The new Flag status (SET or RESET).
3542 * @param Timeout: Timeout duration
3543 * @retval HAL status
3545 static HAL_StatusTypeDef
I2C_WaitOnFlagUntilTimeout(I2C_HandleTypeDef
*hi2c
, uint32_t Flag
, FlagStatus Status
, uint32_t Timeout
)
3547 uint32_t tickstart
= 0;
3550 tickstart
= HAL_GetTick();
3552 /* Wait until flag is set */
3555 while(__HAL_I2C_GET_FLAG(hi2c
, Flag
) == RESET
)
3557 /* Check for the Timeout */
3558 if(Timeout
!= HAL_MAX_DELAY
)
3560 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
3562 hi2c
->State
= HAL_I2C_STATE_READY
;
3564 /* Process Unlocked */
3574 while(__HAL_I2C_GET_FLAG(hi2c
, Flag
) != RESET
)
3576 /* Check for the Timeout */
3577 if(Timeout
!= HAL_MAX_DELAY
)
3579 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
3581 hi2c
->State
= HAL_I2C_STATE_READY
;
3583 /* Process Unlocked */
3595 * @brief This function handles I2C Communication Timeout for Master addressing phase.
3596 * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
3597 * the configuration information for I2C module
3598 * @param Flag: specifies the I2C flag to check.
3599 * @param Timeout: Timeout duration
3600 * @retval HAL status
3602 static HAL_StatusTypeDef
I2C_WaitOnMasterAddressFlagUntilTimeout(I2C_HandleTypeDef
*hi2c
, uint32_t Flag
, uint32_t Timeout
)
3604 uint32_t tickstart
= 0;
3607 tickstart
= HAL_GetTick();
3609 while(__HAL_I2C_GET_FLAG(hi2c
, Flag
) == RESET
)
3611 if(__HAL_I2C_GET_FLAG(hi2c
, I2C_FLAG_AF
) == SET
)
3614 hi2c
->Instance
->CR1
|= I2C_CR1_STOP
;
3617 __HAL_I2C_CLEAR_FLAG(hi2c
, I2C_FLAG_AF
);
3619 hi2c
->ErrorCode
= HAL_I2C_ERROR_AF
;
3620 hi2c
->State
= HAL_I2C_STATE_READY
;
3622 /* Process Unlocked */
3628 /* Check for the Timeout */
3629 if(Timeout
!= HAL_MAX_DELAY
)
3631 if((Timeout
== 0)||((HAL_GetTick() - tickstart
) > Timeout
))
3633 hi2c
->State
= HAL_I2C_STATE_READY
;
3635 /* Process Unlocked */
3649 #endif /* HAL_I2C_MODULE_ENABLED */
3659 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/