# I2C
- [Overview](#section1269538504165623)
- [Summary](#section1310832739165623)
- [Files](#files)
- [Data Structures](#nested-classes)
- [Enumerations](#enum-members)
- [Functions](#func-members)
- [Details](#section1093936068165623)
- [Enumeration Type](#section716022081165623)
- [I2cFlag](#ga32b58f021632085445d80c80e382a546)
- [Function](#section1683434957165623)
- [I2cClose\(\)](#ga3ca9d500e6fb6592a04f7dc33806c13e)
- [I2cOpen\(\)](#ga564086bbb2121cd6771c66c886da11b5)
- [I2cTransfer\(\)](#ga2395dc94da99c2b990096c659fcefc72)
## **Overview**
**Description:**
Provides standard Inter-Integrated Circuit \(I2C\) interfaces.
This module allows a driver to perform operations on an I2C controller for accessing devices on the I2C bus, including creating and destroying I2C controller handles as well as reading and writing data.
**Since:**
1.0
## **Summary**
## Files
File Name
|
Description
|
i2c_if.h
|
Declares the standard I2C interface functions.
|
## Data Structures
Data Structure Name
|
Description
|
I2cMsg
|
Defines the I2C transfer message used during custom transfers.
|
## Enumerations
## Functions
## **Details**
## **Enumeration Type **
## I2cFlag
```
enum [I2cFlag](i2c.md#ga32b58f021632085445d80c80e382a546)
```
**Description:**
Enumerates flags used for transferring I2C messages.
Multiple flags can be used to jointly control a single I2C message transfer. If a bit is set to **1**, the corresponding feature is enabled. If a bit is set to **0**, the corresponding feature is disabled.
Enumerator
|
Description
|
| I2C_FLAG_READ |
Read flag. The value 1 indicates the read operation, and 0 indicates the write operation.
|
| I2C_FLAG_ADDR_10BIT |
10-bit addressing flag. The value 1 indicates that a 10-bit address is used.
|
| I2C_FLAG_READ_NO_ACK |
Non-ACK read flag. The value 1 indicates that no ACK signal is sent during the read process.
|
| I2C_FLAG_IGNORE_NO_ACK |
Ignoring no-ACK flag. The value 1 indicates that the non-ACK signal is ignored.
|
| I2C_FLAG_NO_START |
No START condition flag. The value 1 indicates that there is no START condition for the message transfer.
|
| I2C_FLAG_STOP |
STOP condition flag. The value 1 indicates that the current transfer ends with a STOP condition.
|
## **Function **
## I2cClose\(\)
```
void I2cClose ([DevHandle](common.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle)
```
**Description:**
Releases the handle of an I2C controller.
If you no longer need to access the I2C controller, you should call this function to close its handle so as to release unused memory resources.
**Parameters:**
Name
|
Description
|
| handle |
Indicates the pointer to the device handle of the I2C controller. |
## I2cOpen\(\)
```
[DevHandle](common.md#gab8c2d38e46eec50bd097a27d3d8bf041) I2cOpen (int16_t number)
```
**Description:**
Obtains the handle of an I2C controller.
You must call this function before accessing the I2C bus.
**Parameters:**
Name
|
Description
|
| number |
Indicates the I2C controller ID. |
**Returns:**
Returns the pointer to the [DevHandle](common.md#gab8c2d38e46eec50bd097a27d3d8bf041) of the I2C controller if the operation is successful; returns **NULL** otherwise.
## I2cTransfer\(\)
```
int32_t I2cTransfer ([DevHandle](common.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, struct [I2cMsg](i2cmsg.md) * msgs, int16_t count )
```
**Description:**
Launches a custom transfer to an I2C device.
**Parameters:**
Name
|
Description
|
| handle |
Indicates the pointer to the device handle of the I2C controller obtained via I2cOpen. |
| msgs |
Indicates the pointer to the I2C transfer message structure array. |
| count |
Indicates the length of the message structure array. |
**Returns:**
Returns the number of transferred message structures if the operation is successful; returns a negative value otherwise.
**See also:**
[I2cMsg](i2cmsg.md)
**Attention:**
This function does not limit the number of message structures specified by **count** or the data length of each message structure. The specific I2C controller determines the maximum number and data length allowed.