2 ******************************************************************************
\r
3 * @file stm32f10x_i2c.c
\r
4 * @author MCD Application Team
\r
7 * @brief This file provides all the I2C firmware functions.
\r
8 ******************************************************************************
\r
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
\r
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
\r
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
\r
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
\r
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
18 * <h2><center>© COPYRIGHT 2009 STMicroelectronics</center></h2>
\r
21 /* Includes ------------------------------------------------------------------*/
\r
22 #include "stm32f10x_i2c.h"
\r
23 #include "stm32f10x_rcc.h"
\r
26 /** @addtogroup STM32F10x_StdPeriph_Driver
\r
31 * @brief I2C driver modules
\r
35 /** @defgroup I2C_Private_TypesDefinitions
\r
43 /** @defgroup I2C_Private_Defines
\r
48 #define CR1_PE_Set ((uint16_t)0x0001)
\r
49 #define CR1_PE_Reset ((uint16_t)0xFFFE)
\r
51 /* I2C START mask */
\r
52 #define CR1_START_Set ((uint16_t)0x0100)
\r
53 #define CR1_START_Reset ((uint16_t)0xFEFF)
\r
56 #define CR1_STOP_Set ((uint16_t)0x0200)
\r
57 #define CR1_STOP_Reset ((uint16_t)0xFDFF)
\r
60 #define CR1_ACK_Set ((uint16_t)0x0400)
\r
61 #define CR1_ACK_Reset ((uint16_t)0xFBFF)
\r
64 #define CR1_ENGC_Set ((uint16_t)0x0040)
\r
65 #define CR1_ENGC_Reset ((uint16_t)0xFFBF)
\r
67 /* I2C SWRST mask */
\r
68 #define CR1_SWRST_Set ((uint16_t)0x8000)
\r
69 #define CR1_SWRST_Reset ((uint16_t)0x7FFF)
\r
72 #define CR1_PEC_Set ((uint16_t)0x1000)
\r
73 #define CR1_PEC_Reset ((uint16_t)0xEFFF)
\r
75 /* I2C ENPEC mask */
\r
76 #define CR1_ENPEC_Set ((uint16_t)0x0020)
\r
77 #define CR1_ENPEC_Reset ((uint16_t)0xFFDF)
\r
79 /* I2C ENARP mask */
\r
80 #define CR1_ENARP_Set ((uint16_t)0x0010)
\r
81 #define CR1_ENARP_Reset ((uint16_t)0xFFEF)
\r
83 /* I2C NOSTRETCH mask */
\r
84 #define CR1_NOSTRETCH_Set ((uint16_t)0x0080)
\r
85 #define CR1_NOSTRETCH_Reset ((uint16_t)0xFF7F)
\r
87 /* I2C registers Masks */
\r
88 #define CR1_CLEAR_Mask ((uint16_t)0xFBF5)
\r
90 /* I2C DMAEN mask */
\r
91 #define CR2_DMAEN_Set ((uint16_t)0x0800)
\r
92 #define CR2_DMAEN_Reset ((uint16_t)0xF7FF)
\r
95 #define CR2_LAST_Set ((uint16_t)0x1000)
\r
96 #define CR2_LAST_Reset ((uint16_t)0xEFFF)
\r
99 #define CR2_FREQ_Reset ((uint16_t)0xFFC0)
\r
101 /* I2C ADD0 mask */
\r
102 #define OAR1_ADD0_Set ((uint16_t)0x0001)
\r
103 #define OAR1_ADD0_Reset ((uint16_t)0xFFFE)
\r
105 /* I2C ENDUAL mask */
\r
106 #define OAR2_ENDUAL_Set ((uint16_t)0x0001)
\r
107 #define OAR2_ENDUAL_Reset ((uint16_t)0xFFFE)
\r
109 /* I2C ADD2 mask */
\r
110 #define OAR2_ADD2_Reset ((uint16_t)0xFF01)
\r
113 #define CCR_FS_Set ((uint16_t)0x8000)
\r
116 #define CCR_CCR_Set ((uint16_t)0x0FFF)
\r
118 /* I2C FLAG mask */
\r
119 #define FLAG_Mask ((uint32_t)0x00FFFFFF)
\r
121 /* I2C Interrupt Enable mask */
\r
122 #define ITEN_Mask ((uint32_t)0x07000000)
\r
128 /** @defgroup I2C_Private_Macros
\r
136 /** @defgroup I2C_Private_Variables
\r
144 /** @defgroup I2C_Private_FunctionPrototypes
\r
152 /** @defgroup I2C_Private_Functions
\r
157 * @brief Deinitializes the I2Cx peripheral registers to their default reset values.
\r
158 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
161 void I2C_DeInit(I2C_TypeDef* I2Cx)
\r
163 /* Check the parameters */
\r
164 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
168 /* Enable I2C1 reset state */
\r
169 RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
\r
170 /* Release I2C1 from reset state */
\r
171 RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);
\r
175 /* Enable I2C2 reset state */
\r
176 RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE);
\r
177 /* Release I2C2 from reset state */
\r
178 RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE);
\r
183 * @brief Initializes the I2Cx peripheral according to the specified
\r
184 * parameters in the I2C_InitStruct.
\r
185 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
186 * @param I2C_InitStruct: pointer to a I2C_InitTypeDef structure that
\r
187 * contains the configuration information for the specified I2C peripheral.
\r
190 void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct)
\r
192 uint16_t tmpreg = 0, freqrange = 0;
\r
193 uint16_t result = 0x04;
\r
194 uint32_t pclk1 = 8000000;
\r
195 RCC_ClocksTypeDef rcc_clocks;
\r
196 /* Check the parameters */
\r
197 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
198 assert_param(IS_I2C_CLOCK_SPEED(I2C_InitStruct->I2C_ClockSpeed));
\r
199 assert_param(IS_I2C_MODE(I2C_InitStruct->I2C_Mode));
\r
200 assert_param(IS_I2C_DUTY_CYCLE(I2C_InitStruct->I2C_DutyCycle));
\r
201 assert_param(IS_I2C_OWN_ADDRESS1(I2C_InitStruct->I2C_OwnAddress1));
\r
202 assert_param(IS_I2C_ACK_STATE(I2C_InitStruct->I2C_Ack));
\r
203 assert_param(IS_I2C_ACKNOWLEDGE_ADDRESS(I2C_InitStruct->I2C_AcknowledgedAddress));
\r
205 /*---------------------------- I2Cx CR2 Configuration ------------------------*/
\r
206 /* Get the I2Cx CR2 value */
\r
207 tmpreg = I2Cx->CR2;
\r
208 /* Clear frequency FREQ[5:0] bits */
\r
209 tmpreg &= CR2_FREQ_Reset;
\r
210 /* Get pclk1 frequency value */
\r
211 RCC_GetClocksFreq(&rcc_clocks);
\r
212 pclk1 = rcc_clocks.PCLK1_Frequency;
\r
213 /* Set frequency bits depending on pclk1 value */
\r
214 freqrange = (uint16_t)(pclk1 / 1000000);
\r
215 tmpreg |= freqrange;
\r
216 /* Write to I2Cx CR2 */
\r
217 I2Cx->CR2 = tmpreg;
\r
219 /*---------------------------- I2Cx CCR Configuration ------------------------*/
\r
220 /* Disable the selected I2C peripheral to configure TRISE */
\r
221 I2Cx->CR1 &= CR1_PE_Reset;
\r
222 /* Reset tmpreg value */
\r
223 /* Clear F/S, DUTY and CCR[11:0] bits */
\r
226 /* Configure speed in standard mode */
\r
227 if (I2C_InitStruct->I2C_ClockSpeed <= 100000)
\r
229 /* Standard mode speed calculate */
\r
230 result = (uint16_t)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed << 1));
\r
231 /* Test if CCR value is under 0x4*/
\r
234 /* Set minimum allowed value */
\r
237 /* Set speed value for standard mode */
\r
239 /* Set Maximum Rise Time for standard mode */
\r
240 I2Cx->TRISE = freqrange + 1;
\r
242 /* Configure speed in fast mode */
\r
243 else /*(I2C_InitStruct->I2C_ClockSpeed <= 400000)*/
\r
245 if (I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_2)
\r
247 /* Fast mode speed calculate: Tlow/Thigh = 2 */
\r
248 result = (uint16_t)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed * 3));
\r
250 else /*I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_16_9*/
\r
252 /* Fast mode speed calculate: Tlow/Thigh = 16/9 */
\r
253 result = (uint16_t)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed * 25));
\r
255 result |= I2C_DutyCycle_16_9;
\r
258 /* Test if CCR value is under 0x1*/
\r
259 if ((result & CCR_CCR_Set) == 0)
\r
261 /* Set minimum allowed value */
\r
262 result |= (uint16_t)0x0001;
\r
264 /* Set speed value and set F/S bit for fast mode */
\r
265 tmpreg |= (uint16_t)(result | CCR_FS_Set);
\r
266 /* Set Maximum Rise Time for fast mode */
\r
267 I2Cx->TRISE = (uint16_t)(((freqrange * (uint16_t)300) / (uint16_t)1000) + (uint16_t)1);
\r
270 /* Write to I2Cx CCR */
\r
271 I2Cx->CCR = tmpreg;
\r
272 /* Enable the selected I2C peripheral */
\r
273 I2Cx->CR1 |= CR1_PE_Set;
\r
275 /*---------------------------- I2Cx CR1 Configuration ------------------------*/
\r
276 /* Get the I2Cx CR1 value */
\r
277 tmpreg = I2Cx->CR1;
\r
278 /* Clear ACK, SMBTYPE and SMBUS bits */
\r
279 tmpreg &= CR1_CLEAR_Mask;
\r
280 /* Configure I2Cx: mode and acknowledgement */
\r
281 /* Set SMBTYPE and SMBUS bits according to I2C_Mode value */
\r
282 /* Set ACK bit according to I2C_Ack value */
\r
283 tmpreg |= (uint16_t)((uint32_t)I2C_InitStruct->I2C_Mode | I2C_InitStruct->I2C_Ack);
\r
284 /* Write to I2Cx CR1 */
\r
285 I2Cx->CR1 = tmpreg;
\r
287 /*---------------------------- I2Cx OAR1 Configuration -----------------------*/
\r
288 /* Set I2Cx Own Address1 and acknowledged address */
\r
289 I2Cx->OAR1 = (I2C_InitStruct->I2C_AcknowledgedAddress | I2C_InitStruct->I2C_OwnAddress1);
\r
293 * @brief Fills each I2C_InitStruct member with its default value.
\r
294 * @param I2C_InitStruct: pointer to an I2C_InitTypeDef structure which will be initialized.
\r
297 void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct)
\r
299 /*---------------- Reset I2C init structure parameters values ----------------*/
\r
300 /* initialize the I2C_ClockSpeed member */
\r
301 I2C_InitStruct->I2C_ClockSpeed = 5000;
\r
302 /* Initialize the I2C_Mode member */
\r
303 I2C_InitStruct->I2C_Mode = I2C_Mode_I2C;
\r
304 /* Initialize the I2C_DutyCycle member */
\r
305 I2C_InitStruct->I2C_DutyCycle = I2C_DutyCycle_2;
\r
306 /* Initialize the I2C_OwnAddress1 member */
\r
307 I2C_InitStruct->I2C_OwnAddress1 = 0;
\r
308 /* Initialize the I2C_Ack member */
\r
309 I2C_InitStruct->I2C_Ack = I2C_Ack_Disable;
\r
310 /* Initialize the I2C_AcknowledgedAddress member */
\r
311 I2C_InitStruct->I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
\r
315 * @brief Enables or disables the specified I2C peripheral.
\r
316 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
317 * @param NewState: new state of the I2Cx peripheral.
\r
318 * This parameter can be: ENABLE or DISABLE.
\r
321 void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
323 /* Check the parameters */
\r
324 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
325 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
326 if (NewState != DISABLE)
\r
328 /* Enable the selected I2C peripheral */
\r
329 I2Cx->CR1 |= CR1_PE_Set;
\r
333 /* Disable the selected I2C peripheral */
\r
334 I2Cx->CR1 &= CR1_PE_Reset;
\r
339 * @brief Enables or disables the specified I2C DMA requests.
\r
340 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
341 * @param NewState: new state of the I2C DMA transfer.
\r
342 * This parameter can be: ENABLE or DISABLE.
\r
345 void I2C_DMACmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
347 /* Check the parameters */
\r
348 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
349 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
350 if (NewState != DISABLE)
\r
352 /* Enable the selected I2C DMA requests */
\r
353 I2Cx->CR2 |= CR2_DMAEN_Set;
\r
357 /* Disable the selected I2C DMA requests */
\r
358 I2Cx->CR2 &= CR2_DMAEN_Reset;
\r
363 * @brief Specifies that the next DMA transfer is the last one.
\r
364 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
365 * @param NewState: new state of the I2C DMA last transfer.
\r
366 * This parameter can be: ENABLE or DISABLE.
\r
369 void I2C_DMALastTransferCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
371 /* Check the parameters */
\r
372 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
373 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
374 if (NewState != DISABLE)
\r
376 /* Next DMA transfer is the last transfer */
\r
377 I2Cx->CR2 |= CR2_LAST_Set;
\r
381 /* Next DMA transfer is not the last transfer */
\r
382 I2Cx->CR2 &= CR2_LAST_Reset;
\r
387 * @brief Generates I2Cx communication START condition.
\r
388 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
389 * @param NewState: new state of the I2C START condition generation.
\r
390 * This parameter can be: ENABLE or DISABLE.
\r
393 void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
395 /* Check the parameters */
\r
396 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
397 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
398 if (NewState != DISABLE)
\r
400 /* Generate a START condition */
\r
401 I2Cx->CR1 |= CR1_START_Set;
\r
405 /* Disable the START condition generation */
\r
406 I2Cx->CR1 &= CR1_START_Reset;
\r
411 * @brief Generates I2Cx communication STOP condition.
\r
412 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
413 * @param NewState: new state of the I2C STOP condition generation.
\r
414 * This parameter can be: ENABLE or DISABLE.
\r
417 void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
419 /* Check the parameters */
\r
420 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
421 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
422 if (NewState != DISABLE)
\r
424 /* Generate a STOP condition */
\r
425 I2Cx->CR1 |= CR1_STOP_Set;
\r
429 /* Disable the STOP condition generation */
\r
430 I2Cx->CR1 &= CR1_STOP_Reset;
\r
435 * @brief Enables or disables the specified I2C acknowledge feature.
\r
436 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
437 * @param NewState: new state of the I2C Acknowledgement.
\r
438 * This parameter can be: ENABLE or DISABLE.
\r
441 void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
443 /* Check the parameters */
\r
444 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
445 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
446 if (NewState != DISABLE)
\r
448 /* Enable the acknowledgement */
\r
449 I2Cx->CR1 |= CR1_ACK_Set;
\r
453 /* Disable the acknowledgement */
\r
454 I2Cx->CR1 &= CR1_ACK_Reset;
\r
459 * @brief Configures the specified I2C own address2.
\r
460 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
461 * @param Address: specifies the 7bit I2C own address2.
\r
464 void I2C_OwnAddress2Config(I2C_TypeDef* I2Cx, uint8_t Address)
\r
466 uint16_t tmpreg = 0;
\r
468 /* Check the parameters */
\r
469 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
471 /* Get the old register value */
\r
472 tmpreg = I2Cx->OAR2;
\r
474 /* Reset I2Cx Own address2 bit [7:1] */
\r
475 tmpreg &= OAR2_ADD2_Reset;
\r
477 /* Set I2Cx Own address2 */
\r
478 tmpreg |= (uint16_t)((uint16_t)Address & (uint16_t)0x00FE);
\r
480 /* Store the new register value */
\r
481 I2Cx->OAR2 = tmpreg;
\r
485 * @brief Enables or disables the specified I2C dual addressing mode.
\r
486 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
487 * @param NewState: new state of the I2C dual addressing mode.
\r
488 * This parameter can be: ENABLE or DISABLE.
\r
491 void I2C_DualAddressCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
493 /* Check the parameters */
\r
494 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
495 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
496 if (NewState != DISABLE)
\r
498 /* Enable dual addressing mode */
\r
499 I2Cx->OAR2 |= OAR2_ENDUAL_Set;
\r
503 /* Disable dual addressing mode */
\r
504 I2Cx->OAR2 &= OAR2_ENDUAL_Reset;
\r
509 * @brief Enables or disables the specified I2C general call feature.
\r
510 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
511 * @param NewState: new state of the I2C General call.
\r
512 * This parameter can be: ENABLE or DISABLE.
\r
515 void I2C_GeneralCallCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
517 /* Check the parameters */
\r
518 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
519 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
520 if (NewState != DISABLE)
\r
522 /* Enable generall call */
\r
523 I2Cx->CR1 |= CR1_ENGC_Set;
\r
527 /* Disable generall call */
\r
528 I2Cx->CR1 &= CR1_ENGC_Reset;
\r
533 * @brief Enables or disables the specified I2C interrupts.
\r
534 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
535 * @param I2C_IT: specifies the I2C interrupts sources to be enabled or disabled.
\r
536 * This parameter can be any combination of the following values:
\r
537 * @arg I2C_IT_BUF: Buffer interrupt mask
\r
538 * @arg I2C_IT_EVT: Event interrupt mask
\r
539 * @arg I2C_IT_ERR: Error interrupt mask
\r
540 * @param NewState: new state of the specified I2C interrupts.
\r
541 * This parameter can be: ENABLE or DISABLE.
\r
544 void I2C_ITConfig(I2C_TypeDef* I2Cx, uint16_t I2C_IT, FunctionalState NewState)
\r
546 /* Check the parameters */
\r
547 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
548 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
549 assert_param(IS_I2C_CONFIG_IT(I2C_IT));
\r
551 if (NewState != DISABLE)
\r
553 /* Enable the selected I2C interrupts */
\r
554 I2Cx->CR2 |= I2C_IT;
\r
558 /* Disable the selected I2C interrupts */
\r
559 I2Cx->CR2 &= (uint16_t)~I2C_IT;
\r
564 * @brief Sends a data byte through the I2Cx peripheral.
\r
565 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
566 * @param Data: Byte to be transmitted..
\r
569 void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data)
\r
571 /* Check the parameters */
\r
572 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
573 /* Write in the DR register the data to be sent */
\r
578 * @brief Returns the most recent received data by the I2Cx peripheral.
\r
579 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
580 * @retval The value of the received data.
\r
582 uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx)
\r
584 /* Check the parameters */
\r
585 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
586 /* Return the data in the DR register */
\r
587 return (uint8_t)I2Cx->DR;
\r
591 * @brief Transmits the address byte to select the slave device.
\r
592 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
593 * @param Address: specifies the slave address which will be transmitted
\r
594 * @param I2C_Direction: specifies whether the I2C device will be a
\r
595 * Transmitter or a Receiver. This parameter can be one of the following values
\r
596 * @arg I2C_Direction_Transmitter: Transmitter mode
\r
597 * @arg I2C_Direction_Receiver: Receiver mode
\r
600 void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, uint8_t Address, uint8_t I2C_Direction)
\r
602 /* Check the parameters */
\r
603 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
604 assert_param(IS_I2C_DIRECTION(I2C_Direction));
\r
605 /* Test on the direction to set/reset the read/write bit */
\r
606 if (I2C_Direction != I2C_Direction_Transmitter)
\r
608 /* Set the address bit0 for read */
\r
609 Address |= OAR1_ADD0_Set;
\r
613 /* Reset the address bit0 for write */
\r
614 Address &= OAR1_ADD0_Reset;
\r
616 /* Send the address */
\r
617 I2Cx->DR = Address;
\r
621 * @brief Reads the specified I2C register and returns its value.
\r
622 * @param I2C_Register: specifies the register to read.
\r
623 * This parameter can be one of the following values:
\r
624 * @arg I2C_Register_CR1: CR1 register.
\r
625 * @arg I2C_Register_CR2: CR2 register.
\r
626 * @arg I2C_Register_OAR1: OAR1 register.
\r
627 * @arg I2C_Register_OAR2: OAR2 register.
\r
628 * @arg I2C_Register_DR: DR register.
\r
629 * @arg I2C_Register_SR1: SR1 register.
\r
630 * @arg I2C_Register_SR2: SR2 register.
\r
631 * @arg I2C_Register_CCR: CCR register.
\r
632 * @arg I2C_Register_TRISE: TRISE register.
\r
633 * @retval The value of the read register.
\r
635 uint16_t I2C_ReadRegister(I2C_TypeDef* I2Cx, uint8_t I2C_Register)
\r
637 __IO uint32_t tmp = 0;
\r
639 /* Check the parameters */
\r
640 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
641 assert_param(IS_I2C_REGISTER(I2C_Register));
\r
643 tmp = (uint32_t) I2Cx;
\r
644 tmp += I2C_Register;
\r
646 /* Return the selected register value */
\r
647 return (*(__IO uint16_t *) tmp);
\r
651 * @brief Enables or disables the specified I2C software reset.
\r
652 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
653 * @param NewState: new state of the I2C software reset.
\r
654 * This parameter can be: ENABLE or DISABLE.
\r
657 void I2C_SoftwareResetCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
659 /* Check the parameters */
\r
660 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
661 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
662 if (NewState != DISABLE)
\r
664 /* Peripheral under reset */
\r
665 I2Cx->CR1 |= CR1_SWRST_Set;
\r
669 /* Peripheral not under reset */
\r
670 I2Cx->CR1 &= CR1_SWRST_Reset;
\r
675 * @brief Drives the SMBusAlert pin high or low for the specified I2C.
\r
676 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
677 * @param I2C_SMBusAlert: specifies SMBAlert pin level.
\r
678 * This parameter can be one of the following values:
\r
679 * @arg I2C_SMBusAlert_Low: SMBAlert pin driven low
\r
680 * @arg I2C_SMBusAlert_High: SMBAlert pin driven high
\r
683 void I2C_SMBusAlertConfig(I2C_TypeDef* I2Cx, uint16_t I2C_SMBusAlert)
\r
685 /* Check the parameters */
\r
686 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
687 assert_param(IS_I2C_SMBUS_ALERT(I2C_SMBusAlert));
\r
688 if (I2C_SMBusAlert == I2C_SMBusAlert_Low)
\r
690 /* Drive the SMBusAlert pin Low */
\r
691 I2Cx->CR1 |= I2C_SMBusAlert_Low;
\r
695 /* Drive the SMBusAlert pin High */
\r
696 I2Cx->CR1 &= I2C_SMBusAlert_High;
\r
701 * @brief Enables or disables the specified I2C PEC transfer.
\r
702 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
703 * @param NewState: new state of the I2C PEC transmission.
\r
704 * This parameter can be: ENABLE or DISABLE.
\r
707 void I2C_TransmitPEC(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
709 /* Check the parameters */
\r
710 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
711 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
712 if (NewState != DISABLE)
\r
714 /* Enable the selected I2C PEC transmission */
\r
715 I2Cx->CR1 |= CR1_PEC_Set;
\r
719 /* Disable the selected I2C PEC transmission */
\r
720 I2Cx->CR1 &= CR1_PEC_Reset;
\r
725 * @brief Selects the specified I2C PEC position.
\r
726 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
727 * @param I2C_PECPosition: specifies the PEC position.
\r
728 * This parameter can be one of the following values:
\r
729 * @arg I2C_PECPosition_Next: indicates that the next byte is PEC
\r
730 * @arg I2C_PECPosition_Current: indicates that current byte is PEC
\r
733 void I2C_PECPositionConfig(I2C_TypeDef* I2Cx, uint16_t I2C_PECPosition)
\r
735 /* Check the parameters */
\r
736 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
737 assert_param(IS_I2C_PEC_POSITION(I2C_PECPosition));
\r
738 if (I2C_PECPosition == I2C_PECPosition_Next)
\r
740 /* Next byte in shift register is PEC */
\r
741 I2Cx->CR1 |= I2C_PECPosition_Next;
\r
745 /* Current byte in shift register is PEC */
\r
746 I2Cx->CR1 &= I2C_PECPosition_Current;
\r
751 * @brief Enables or disables the PEC value calculation of the transfered bytes.
\r
752 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
753 * @param NewState: new state of the I2Cx PEC value calculation.
\r
754 * This parameter can be: ENABLE or DISABLE.
\r
757 void I2C_CalculatePEC(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
759 /* Check the parameters */
\r
760 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
761 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
762 if (NewState != DISABLE)
\r
764 /* Enable the selected I2C PEC calculation */
\r
765 I2Cx->CR1 |= CR1_ENPEC_Set;
\r
769 /* Disable the selected I2C PEC calculation */
\r
770 I2Cx->CR1 &= CR1_ENPEC_Reset;
\r
775 * @brief Returns the PEC value for the specified I2C.
\r
776 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
777 * @retval The PEC value.
\r
779 uint8_t I2C_GetPEC(I2C_TypeDef* I2Cx)
\r
781 /* Check the parameters */
\r
782 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
783 /* Return the selected I2C PEC value */
\r
784 return ((I2Cx->SR2) >> 8);
\r
788 * @brief Enables or disables the specified I2C ARP.
\r
789 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
790 * @param NewState: new state of the I2Cx ARP.
\r
791 * This parameter can be: ENABLE or DISABLE.
\r
794 void I2C_ARPCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
796 /* Check the parameters */
\r
797 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
798 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
799 if (NewState != DISABLE)
\r
801 /* Enable the selected I2C ARP */
\r
802 I2Cx->CR1 |= CR1_ENARP_Set;
\r
806 /* Disable the selected I2C ARP */
\r
807 I2Cx->CR1 &= CR1_ENARP_Reset;
\r
812 * @brief Enables or disables the specified I2C Clock stretching.
\r
813 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
814 * @param NewState: new state of the I2Cx Clock stretching.
\r
815 * This parameter can be: ENABLE or DISABLE.
\r
818 void I2C_StretchClockCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
\r
820 /* Check the parameters */
\r
821 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
822 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
823 if (NewState == DISABLE)
\r
825 /* Enable the selected I2C Clock stretching */
\r
826 I2Cx->CR1 |= CR1_NOSTRETCH_Set;
\r
830 /* Disable the selected I2C Clock stretching */
\r
831 I2Cx->CR1 &= CR1_NOSTRETCH_Reset;
\r
836 * @brief Selects the specified I2C fast mode duty cycle.
\r
837 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
838 * @param I2C_DutyCycle: specifies the fast mode duty cycle.
\r
839 * This parameter can be one of the following values:
\r
840 * @arg I2C_DutyCycle_2: I2C fast mode Tlow/Thigh = 2
\r
841 * @arg I2C_DutyCycle_16_9: I2C fast mode Tlow/Thigh = 16/9
\r
844 void I2C_FastModeDutyCycleConfig(I2C_TypeDef* I2Cx, uint16_t I2C_DutyCycle)
\r
846 /* Check the parameters */
\r
847 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
848 assert_param(IS_I2C_DUTY_CYCLE(I2C_DutyCycle));
\r
849 if (I2C_DutyCycle != I2C_DutyCycle_16_9)
\r
851 /* I2C fast mode Tlow/Thigh=2 */
\r
852 I2Cx->CCR &= I2C_DutyCycle_2;
\r
856 /* I2C fast mode Tlow/Thigh=16/9 */
\r
857 I2Cx->CCR |= I2C_DutyCycle_16_9;
\r
862 * @brief Returns the last I2Cx Event.
\r
863 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
864 * @retval The last event
\r
866 uint32_t I2C_GetLastEvent(I2C_TypeDef* I2Cx)
\r
868 uint32_t lastevent = 0;
\r
869 uint32_t flag1 = 0, flag2 = 0;
\r
870 /* Check the parameters */
\r
871 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
872 /* Read the I2Cx status register */
\r
875 flag2 = flag2 << 16;
\r
876 /* Get the last event value from I2C status register */
\r
877 lastevent = (flag1 | flag2) & FLAG_Mask;
\r
878 /* Return status */
\r
883 * @brief Checks whether the last I2Cx Event is equal to the one passed
\r
885 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
886 * @param I2C_EVENT: specifies the event to be checked.
\r
887 * This parameter can be one of the following values:
\r
888 * @arg I2C_EVENT_SLAVE_ADDRESS_MATCHED : EV1
\r
889 * @arg I2C_EVENT_SLAVE_BYTE_RECEIVED : EV2
\r
890 * @arg I2C_EVENT_SLAVE_BYTE_TRANSMITTED : EV3
\r
891 * @arg I2C_EVENT_SLAVE_ACK_FAILURE : EV3-2
\r
892 * @arg I2C_EVENT_MASTER_MODE_SELECT : EV5
\r
893 * @arg I2C_EVENT_MASTER_MODE_SELECTED : EV6
\r
894 * @arg I2C_EVENT_MASTER_BYTE_RECEIVED : EV7
\r
895 * @arg I2C_EVENT_MASTER_BYTE_TRANSMITTED : EV8
\r
896 * @arg I2C_EVENT_MASTER_MODE_ADDRESS10 : EV9
\r
897 * @arg I2C_EVENT_SLAVE_STOP_DETECTED : EV4
\r
898 * @retval An ErrorStatus enumuration value:
\r
899 * - SUCCESS: Last event is equal to the I2C_EVENT
\r
900 * - ERROR: Last event is different from the I2C_EVENT
\r
902 ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, uint32_t I2C_EVENT)
\r
904 uint32_t lastevent = 0;
\r
905 uint32_t flag1 = 0, flag2 = 0;
\r
906 ErrorStatus status = ERROR;
\r
907 /* Check the parameters */
\r
908 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
909 assert_param(IS_I2C_EVENT(I2C_EVENT));
\r
910 /* Read the I2Cx status register */
\r
913 flag2 = flag2 << 16;
\r
914 /* Get the last event value from I2C status register */
\r
915 lastevent = (flag1 | flag2) & FLAG_Mask;
\r
916 /* Check whether the last event is equal to I2C_EVENT */
\r
917 if (lastevent == I2C_EVENT )
\r
919 /* SUCCESS: last event is equal to I2C_EVENT */
\r
924 /* ERROR: last event is different from I2C_EVENT */
\r
927 /* Return status */
\r
932 * @brief Checks whether the specified I2C flag is set or not.
\r
933 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
934 * @param I2C_FLAG: specifies the flag to check.
\r
935 * This parameter can be one of the following values:
\r
936 * @arg I2C_FLAG_DUALF: Dual flag (Slave mode)
\r
937 * @arg I2C_FLAG_SMBHOST: SMBus host header (Slave mode)
\r
938 * @arg I2C_FLAG_SMBDEFAULT: SMBus default header (Slave mode)
\r
939 * @arg I2C_FLAG_GENCALL: General call header flag (Slave mode)
\r
940 * @arg I2C_FLAG_TRA: Transmitter/Receiver flag
\r
941 * @arg I2C_FLAG_BUSY: Bus busy flag
\r
942 * @arg I2C_FLAG_MSL: Master/Slave flag
\r
943 * @arg I2C_FLAG_SMBALERT: SMBus Alert flag
\r
944 * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
\r
945 * @arg I2C_FLAG_PECERR: PEC error in reception flag
\r
946 * @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
\r
947 * @arg I2C_FLAG_AF: Acknowledge failure flag
\r
948 * @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
\r
949 * @arg I2C_FLAG_BERR: Bus error flag
\r
950 * @arg I2C_FLAG_TXE: Data register empty flag (Transmitter)
\r
951 * @arg I2C_FLAG_RXNE: Data register not empty (Receiver) flag
\r
952 * @arg I2C_FLAG_STOPF: Stop detection flag (Slave mode)
\r
953 * @arg I2C_FLAG_ADD10: 10-bit header sent flag (Master mode)
\r
954 * @arg I2C_FLAG_BTF: Byte transfer finished flag
\r
955 * @arg I2C_FLAG_ADDR: Address sent flag (Master mode)
\93ADSL
\94\r
956 * Address matched flag (Slave mode)
\94ENDAD
\94\r
957 * @arg I2C_FLAG_SB: Start bit flag (Master mode)
\r
958 * @retval The new state of I2C_FLAG (SET or RESET).
\r
960 FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG)
\r
962 FlagStatus bitstatus = RESET;
\r
963 __IO uint32_t i2creg = 0, i2cxbase = 0;
\r
965 /* Check the parameters */
\r
966 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
967 assert_param(IS_I2C_GET_FLAG(I2C_FLAG));
\r
969 /* Get the I2Cx peripheral base address */
\r
970 i2cxbase = (uint32_t)I2Cx;
\r
972 /* Read flag register index */
\r
973 i2creg = I2C_FLAG >> 28;
\r
975 /* Get bit[23:0] of the flag */
\r
976 I2C_FLAG &= FLAG_Mask;
\r
980 /* Get the I2Cx SR1 register address */
\r
985 /* Flag in I2Cx SR2 Register */
\r
986 I2C_FLAG = (uint32_t)(I2C_FLAG >> 16);
\r
987 /* Get the I2Cx SR2 register address */
\r
991 if(((*(__IO uint32_t *)i2cxbase) & I2C_FLAG) != (uint32_t)RESET)
\r
993 /* I2C_FLAG is set */
\r
998 /* I2C_FLAG is reset */
\r
1002 /* Return the I2C_FLAG status */
\r
1007 * @brief Clears the I2Cx's pending flags.
\r
1008 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
1009 * @param I2C_FLAG: specifies the flag to clear.
\r
1010 * This parameter can be any combination of the following values:
\r
1011 * @arg I2C_FLAG_SMBALERT: SMBus Alert flag
\r
1012 * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
\r
1013 * @arg I2C_FLAG_PECERR: PEC error in reception flag
\r
1014 * @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
\r
1015 * @arg I2C_FLAG_AF: Acknowledge failure flag
\r
1016 * @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
\r
1017 * @arg I2C_FLAG_BERR: Bus error flag
\r
1020 * - STOPF (STOP detection) is cleared by software sequence: a read operation
\r
1021 * to I2C_SR1 register (I2C_GetFlagStatus()) followed by a write operation
\r
1022 * to I2C_CR1 register (I2C_Cmd() to re-enable the I2C peripheral).
\r
1023 * - ADD10 (10-bit header sent) is cleared by software sequence: a read
\r
1024 * operation to I2C_SR1 (I2C_GetFlagStatus()) followed by writing the
\r
1025 * second byte of the address in DR register.
\r
1026 * - BTF (Byte Transfer Finished) is cleared by software sequence: a read
\r
1027 * operation to I2C_SR1 register (I2C_GetFlagStatus()) followed by a
\r
1028 * read/write to I2C_DR register (I2C_SendData()).
\r
1029 * - ADDR (Address sent) is cleared by software sequence: a read operation to
\r
1030 * I2C_SR1 register (I2C_GetFlagStatus()) followed by a read operation to
\r
1031 * I2C_SR2 register ((void)(I2Cx->SR2)).
\r
1032 * - SB (Start Bit) is cleared software sequence: a read operation to I2C_SR1
\r
1033 * register (I2C_GetFlagStatus()) followed by a write operation to I2C_DR
\r
1034 * register (I2C_SendData()).
\r
1037 void I2C_ClearFlag(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG)
\r
1039 uint32_t flagpos = 0;
\r
1040 /* Check the parameters */
\r
1041 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
1042 assert_param(IS_I2C_CLEAR_FLAG(I2C_FLAG));
\r
1043 /* Get the I2C flag position */
\r
1044 flagpos = I2C_FLAG & FLAG_Mask;
\r
1045 /* Clear the selected I2C flag */
\r
1046 I2Cx->SR1 = (uint16_t)~flagpos;
\r
1050 * @brief Checks whether the specified I2C interrupt has occurred or not.
\r
1051 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
1052 * @param I2C_IT: specifies the interrupt source to check.
\r
1053 * This parameter can be one of the following values:
\r
1054 * @arg I2C_IT_SMBALERT: SMBus Alert flag
\r
1055 * @arg I2C_IT_TIMEOUT: Timeout or Tlow error flag
\r
1056 * @arg I2C_IT_PECERR: PEC error in reception flag
\r
1057 * @arg I2C_IT_OVR: Overrun/Underrun flag (Slave mode)
\r
1058 * @arg I2C_IT_AF: Acknowledge failure flag
\r
1059 * @arg I2C_IT_ARLO: Arbitration lost flag (Master mode)
\r
1060 * @arg I2C_IT_BERR: Bus error flag
\r
1061 * @arg I2C_IT_TXE: Data register empty flag (Transmitter)
\r
1062 * @arg I2C_IT_RXNE: Data register not empty (Receiver) flag
\r
1063 * @arg I2C_IT_STOPF: Stop detection flag (Slave mode)
\r
1064 * @arg I2C_IT_ADD10: 10-bit header sent flag (Master mode)
\r
1065 * @arg I2C_IT_BTF: Byte transfer finished flag
\r
1066 * @arg I2C_IT_ADDR: Address sent flag (Master mode)
\93ADSL
\94\r
1067 * Address matched flag (Slave mode)
\94ENDAD
\94\r
1068 * @arg I2C_IT_SB: Start bit flag (Master mode)
\r
1069 * @retval The new state of I2C_IT (SET or RESET).
\r
1071 ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, uint32_t I2C_IT)
\r
1073 ITStatus bitstatus = RESET;
\r
1074 uint32_t enablestatus = 0;
\r
1075 /* Check the parameters */
\r
1076 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
1077 assert_param(IS_I2C_GET_IT(I2C_IT));
\r
1078 /* Check if the interrupt source is enabled or not */
\r
1079 enablestatus = (uint32_t)(((I2C_IT & ITEN_Mask) >> 16) & (I2Cx->CR2)) ;
\r
1080 /* Get bit[23:0] of the flag */
\r
1081 I2C_IT &= FLAG_Mask;
\r
1082 /* Check the status of the specified I2C flag */
\r
1083 if (((I2Cx->SR1 & I2C_IT) != (uint32_t)RESET) && enablestatus)
\r
1085 /* I2C_IT is set */
\r
1090 /* I2C_IT is reset */
\r
1091 bitstatus = RESET;
\r
1093 /* Return the I2C_IT status */
\r
1098 * @brief Clears the I2Cx
\92s interrupt pending bits.
\r
1099 * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral.
\r
1100 * @param I2C_IT: specifies the interrupt pending bit to clear.
\r
1101 * This parameter can be any combination of the following values:
\r
1102 * @arg I2C_IT_SMBALERT: SMBus Alert interrupt
\r
1103 * @arg I2C_IT_TIMEOUT: Timeout or Tlow error interrupt
\r
1104 * @arg I2C_IT_PECERR: PEC error in reception interrupt
\r
1105 * @arg I2C_IT_OVR: Overrun/Underrun interrupt (Slave mode)
\r
1106 * @arg I2C_IT_AF: Acknowledge failure interrupt
\r
1107 * @arg I2C_IT_ARLO: Arbitration lost interrupt (Master mode)
\r
1108 * @arg I2C_IT_BERR: Bus error interrupt
\r
1111 * - STOPF (STOP detection) is cleared by software sequence: a read operation
\r
1112 * to I2C_SR1 register (I2C_GetITStatus()) followed by a write operation to
\r
1113 * I2C_CR1 register (I2C_Cmd() to re-enable the I2C peripheral).
\r
1114 * - ADD10 (10-bit header sent) is cleared by software sequence: a read
\r
1115 * operation to I2C_SR1 (I2C_GetITStatus()) followed by writing the second
\r
1116 * byte of the address in I2C_DR register.
\r
1117 * - BTF (Byte Transfer Finished) is cleared by software sequence: a read
\r
1118 * operation to I2C_SR1 register (I2C_GetITStatus()) followed by a
\r
1119 * read/write to I2C_DR register (I2C_SendData()).
\r
1120 * - ADDR (Address sent) is cleared by software sequence: a read operation to
\r
1121 * I2C_SR1 register (I2C_GetITStatus()) followed by a read operation to
\r
1122 * I2C_SR2 register ((void)(I2Cx->SR2)).
\r
1123 * - SB (Start Bit) is cleared by software sequence: a read operation to
\r
1124 * I2C_SR1 register (I2C_GetITStatus()) followed by a write operation to
\r
1125 * I2C_DR register (I2C_SendData()).
\r
1128 void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, uint32_t I2C_IT)
\r
1130 uint32_t flagpos = 0;
\r
1131 /* Check the parameters */
\r
1132 assert_param(IS_I2C_ALL_PERIPH(I2Cx));
\r
1133 assert_param(IS_I2C_CLEAR_IT(I2C_IT));
\r
1134 /* Get the I2C flag position */
\r
1135 flagpos = I2C_IT & FLAG_Mask;
\r
1136 /* Clear the selected I2C flag */
\r
1137 I2Cx->SR1 = (uint16_t)~flagpos;
\r
1152 /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
\r