The I2C device mode peripheral allows the chip to act as an I2C device, responding to a controller driving the bus.
More...
The I2C device mode peripheral allows the chip to act as an I2C device, responding to a controller driving the bus.
I2C device mode is interrupt-driven. You MUST implement the following function, replacing 'N' with the SERCOM number you are using: void irq_handler_sercomN(void) { i2c_device_irq_handler(N); }
- Warning
- If you don't implement the interrupt handler, your device will not respond to any I2C transactions.
◆ i2c_device_address_cb_t
| typedef void(* i2c_device_address_cb_t) (uint8_t sercom, bool direction) |
Called when a controller addresses this device.
- Parameters
-
| sercom | The SERCOM instance that received the address match. |
| direction | false = controller will write (device receives data), true = controller will read (device must provide data). |
◆ i2c_device_data_received_cb_t
| typedef void(* i2c_device_data_received_cb_t) (uint8_t sercom, uint8_t data) |
Called when the controller has written a byte to this device.
- Parameters
-
| sercom | The SERCOM instance that received the data. |
| data | The byte received from the controller. |
◆ i2c_device_data_requested_cb_t
| typedef uint8_t(* i2c_device_data_requested_cb_t) (uint8_t sercom) |
Called when the controller wants to read a byte from this device.
- Parameters
-
| sercom | The SERCOM instance requesting data. |
- Returns
- The byte to send to the controller.
◆ i2c_device_error_cb_t
| typedef void(* i2c_device_error_cb_t) (uint8_t sercom) |
Called when a bus error occurs.
- Parameters
-
| sercom | The SERCOM instance that encountered the error. |
◆ i2c_device_stop_cb_t
| typedef void(* i2c_device_stop_cb_t) (uint8_t sercom) |
Called when the controller sends a stop condition, ending the transaction.
- Parameters
-
| sercom | The SERCOM instance that received the stop. |
◆ i2c_device_disable_instance()
| void i2c_device_disable_instance |
( |
uint8_t | sercom | ) |
|
Disables I2C device mode on the given SERCOM.
- Parameters
-
| sercom | The SERCOM instance, as numbered in the data sheet. |
◆ i2c_device_enable_instance()
| void i2c_device_enable_instance |
( |
uint8_t | sercom | ) |
|
Enables I2C device mode on the given SERCOM.
- Parameters
-
| sercom | The SERCOM instance, as numbered in the data sheet. |
◆ i2c_device_init_instance()
| void i2c_device_init_instance |
( |
uint8_t | sercom, |
|
|
uint8_t | address ) |
Initializes I2C device mode on the given SERCOM.
- Parameters
-
| sercom | The SERCOM instance, as numbered in the data sheet. |
| address | The 7-bit I2C address this device should respond to. |
- Note
- You are responsible for setting the appropriate pin mux for the SDA and SCL pins.
◆ i2c_device_irq_handler()
| void i2c_device_irq_handler |
( |
uint8_t | sercom | ) |
|
I2C device mode IRQ handler.
Call this from the SERCOM IRQ handler for your I2C device SERCOM: void irq_handler_sercom0(void) { i2c_device_irq_handler(0); }
- Parameters
-
| sercom | The SERCOM instance number. |
◆ i2c_device_is_enabled_instance()
| bool i2c_device_is_enabled_instance |
( |
uint8_t | sercom | ) |
|
Checks if I2C device mode is enabled on the given SERCOM.
- Parameters
-
| sercom | The SERCOM instance, as numbered in the data sheet. |
- Returns
- true if I2C device mode is enabled, false if it is not.
◆ i2c_device_set_callbacks_instance()
Sets callbacks for I2C device mode events on the given SERCOM.
- Parameters
-
| sercom | The SERCOM instance, as numbered in the data sheet. |
| on_address_match | Called when the controller addresses this device. May be NULL. |
| on_data_received | Called when the controller writes a byte. May be NULL. |
| on_data_requested | Called when the controller reads a byte. May be NULL (sends 0x00). |
| on_stop | Called when the controller sends a stop condition. May be NULL. |
| on_error | Called on bus error. May be NULL. |