The I2C peripheral is used for communication with I2C devices over SDA and SCL pins.
More...
|
enum | i2c_result_t {
I2C_RESULT_SUCCESS = 0
, I2C_RESULT_ERR_ADDR_NACK = -1
, I2C_RESULT_ERR_BUSSTATE = -2
, I2C_RESULT_ERR_BUSERR = -3
,
I2C_RESULT_ERR_DATA_NACK = -4
} |
|
|
void | i2c_init (void) |
| Initializes the I2C peripheral for a board with a defined I2C_SERCOM.
|
|
void | i2c_enable (void) |
| Enables the I2C peripheral for a board with a defined I2C_SERCOM.
|
|
i2c_result_t | i2c_write (uint8_t address, uint8_t *data, size_t len) |
| Writes data to an I2C device at the provided address.
|
|
i2c_result_t | i2c_read (uint8_t address, uint8_t *data, size_t len) |
| Reads data from an I2C device at the provided address.
|
|
void | i2c_disable (void) |
| Disables the I2C peripheral for a board with defined SDA/SCL pins.
|
|
void | i2c_init_instance (uint8_t sercom, uint32_t baud) |
| Initializes an I2C peripheral on the given SERCOM.
|
|
void | i2c_enable_instance (uint8_t sercom) |
| Enables the I2C peripheral on the given SERCOM.
|
|
i2c_result_t | i2c_write_instance (uint8_t sercom, uint8_t address, uint8_t *data, size_t len) |
| Writes data to an I2C device on the given SERCOM at the provided address.
|
|
i2c_result_t | i2c_read_instance (uint8_t sercom, uint8_t address, uint8_t *data, size_t len) |
| Reads data from an I2C device on the given SERCOM at the provided address.
|
|
void | i2c_disable_instance (uint8_t sercom) |
| Disables the I2C peripheral on the given SERCOM.
|
|
The I2C peripheral is used for communication with I2C devices over SDA and SCL pins.
◆ i2c_disable_instance()
void i2c_disable_instance |
( |
uint8_t |
sercom | ) |
|
Disables the I2C peripheral on the given SERCOM.
- Parameters
-
sercom | The SERCOM of the I2C peripheral, as numbered in the data sheet. |
◆ i2c_enable_instance()
void i2c_enable_instance |
( |
uint8_t |
sercom | ) |
|
Enables the I2C peripheral on the given SERCOM.
- Parameters
-
sercom | The SERCOM of the I2C peripheral, as numbered in the data sheet. |
◆ i2c_init()
Initializes the I2C peripheral for a board with a defined I2C_SERCOM.
This function will set up the I2C peripheral with a bus speed of 100kHz.
- Note
- You are responsible for setting the appropriate pin mux for the SDA and SCL pins. This function does not know which pins you intend to use, or whether they are on the SERCOM or SERCOM_ALT pin mux.
◆ i2c_init_instance()
void i2c_init_instance |
( |
uint8_t |
sercom, |
|
|
uint32_t |
baud |
|
) |
| |
Initializes an I2C peripheral on the given SERCOM.
- Parameters
-
sercom | The SERCOM you wish to use, as numbered in the data sheet. |
baud | The baud rate you wish to use. |
- Note
- You are responsible for setting the appropriate pin mux for the SDA and SCL pins. This function does not know which pins you intend to use, or whether they are on the SERCOM or SERCOM_ALT pin mux.
◆ i2c_read()
i2c_result_t i2c_read |
( |
uint8_t |
address, |
|
|
uint8_t * |
data, |
|
|
size_t |
len |
|
) |
| |
Reads data from an I2C device at the provided address.
- Parameters
-
address | The I2C address of the device. |
data | A pointer to the buffer to read into. |
len | The length of the data to read. |
◆ i2c_read_instance()
i2c_result_t i2c_read_instance |
( |
uint8_t |
sercom, |
|
|
uint8_t |
address, |
|
|
uint8_t * |
data, |
|
|
size_t |
len |
|
) |
| |
Reads data from an I2C device on the given SERCOM at the provided address.
- Parameters
-
sercom | The SERCOM of the I2C peripheral, as numbered in the data sheet. |
address | The I2C address of the device. |
data | A pointer to the buffer to read into. |
len | The length of the data to read. |
◆ i2c_write()
i2c_result_t i2c_write |
( |
uint8_t |
address, |
|
|
uint8_t * |
data, |
|
|
size_t |
len |
|
) |
| |
Writes data to an I2C device at the provided address.
- Parameters
-
address | The I2C address of the device. |
data | The data to write. |
len | The length of the data to write. |
◆ i2c_write_instance()
i2c_result_t i2c_write_instance |
( |
uint8_t |
sercom, |
|
|
uint8_t |
address, |
|
|
uint8_t * |
data, |
|
|
size_t |
len |
|
) |
| |
Writes data to an I2C device on the given SERCOM at the provided address.
- Parameters
-
sercom | The SERCOM of the I2C peripheral, as numbered in the data sheet. |
address | The I2C address of the device. |
data | The data to write. |
len | The length of the data to write. |