gossamer 0.0.1
a very lightweight app framework for SAMD and SAML chips
Loading...
Searching...
No Matches
Inter-IC Communications Peripheral

The I2C peripheral is used for communication with I2C devices over SDA and SCL pins. More...

Enumerations

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
}
 

Functions

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.
 

Detailed Description

The I2C peripheral is used for communication with I2C devices over SDA and SCL pins.

Function Documentation

◆ i2c_disable_instance()

void i2c_disable_instance ( uint8_t  sercom)

Disables the I2C peripheral on the given SERCOM.

Parameters
sercomThe 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
sercomThe SERCOM of the I2C peripheral, as numbered in the data sheet.

◆ i2c_init()

void i2c_init ( void  )

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
sercomThe SERCOM you wish to use, as numbered in the data sheet.
baudThe 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
addressThe I2C address of the device.
dataA pointer to the buffer to read into.
lenThe 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
sercomThe SERCOM of the I2C peripheral, as numbered in the data sheet.
addressThe I2C address of the device.
dataA pointer to the buffer to read into.
lenThe 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
addressThe I2C address of the device.
dataThe data to write.
lenThe 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
sercomThe SERCOM of the I2C peripheral, as numbered in the data sheet.
addressThe I2C address of the device.
dataThe data to write.
lenThe length of the data to write.