I2C Peripheral.
More...
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
Go to the source code of this file.
|
enum | I2CResult {
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 defined SDA/SCL pins. Defaults to a bus speed of 100kHz. More...
|
|
void | i2c_enable (void) |
| Enables the I2C peripheral for a board with defined SDA/SCL pins.
|
|
I2CResult | i2c_write (uint8_t address, uint8_t *data, size_t len) |
| Writes data to an I2C device at the provided address. More...
|
|
I2CResult | i2c_read (uint8_t address, uint8_t *data, size_t len) |
| Reads data from an I2C device at the provided address. More...
|
|
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. More...
|
|
void | i2c_enable_instance (uint8_t sercom) |
| Enables the I2C peripheral on the given SERCOM. More...
|
|
I2CResult | 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. More...
|
|
I2CResult | 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. More...
|
|
void | i2c_disable_instance (uint8_t sercom) |
| Disables the I2C peripheral on the given SERCOM. More...
|
|
◆ 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 defined SDA/SCL pins. Defaults to a bus speed of 100kHz.
This function will only work if a board has pins named SDA and SCL, and relevant definitions for I2C_SERCOM. If you don't have these definitions, the build will fail at link time.
◆ 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()
I2CResult 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()
I2CResult 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()
I2CResult 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()
I2CResult 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. |