gossamer 0.0.1
a very lightweight app framework for SAMD and SAML chips
Loading...
Searching...
No Matches
I2C Device Mode Peripheral

The I2C device mode peripheral allows the chip to act as an I2C device, responding to a controller driving the bus. More...

Typedefs

typedef void(* i2c_device_address_cb_t) (uint8_t sercom, bool direction)
 Called when a controller addresses this device.
 
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.
 
typedef uint8_t(* i2c_device_data_requested_cb_t) (uint8_t sercom)
 Called when the controller wants to read a byte from this device.
 
typedef void(* i2c_device_stop_cb_t) (uint8_t sercom)
 Called when the controller sends a stop condition, ending the transaction.
 
typedef void(* i2c_device_error_cb_t) (uint8_t sercom)
 Called when a bus error occurs.
 

Functions

void i2c_device_init_instance (uint8_t sercom, uint8_t address)
 Initializes I2C device mode on the given SERCOM.
 
void i2c_device_enable_instance (uint8_t sercom)
 Enables I2C device mode on the given SERCOM.
 
bool i2c_device_is_enabled_instance (uint8_t sercom)
 Checks if I2C device mode is enabled on the given SERCOM.
 
void i2c_device_set_callbacks_instance (uint8_t sercom, i2c_device_address_cb_t on_address_match, i2c_device_data_received_cb_t on_data_received, i2c_device_data_requested_cb_t on_data_requested, i2c_device_stop_cb_t on_stop, i2c_device_error_cb_t on_error)
 Sets callbacks for I2C device mode events on the given SERCOM.
 
void i2c_device_disable_instance (uint8_t sercom)
 Disables I2C device mode on the given SERCOM.
 
void i2c_device_irq_handler (uint8_t sercom)
 I2C device mode IRQ handler.
 

Detailed Description

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.

Typedef Documentation

◆ 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
sercomThe SERCOM instance that received the address match.
directionfalse = 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
sercomThe SERCOM instance that received the data.
dataThe 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
sercomThe 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
sercomThe 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
sercomThe SERCOM instance that received the stop.

Function Documentation

◆ i2c_device_disable_instance()

void i2c_device_disable_instance ( uint8_t sercom)

Disables I2C device mode on the given SERCOM.

Parameters
sercomThe 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
sercomThe 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
sercomThe SERCOM instance, as numbered in the data sheet.
addressThe 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
sercomThe 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
sercomThe 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()

void i2c_device_set_callbacks_instance ( uint8_t sercom,
i2c_device_address_cb_t on_address_match,
i2c_device_data_received_cb_t on_data_received,
i2c_device_data_requested_cb_t on_data_requested,
i2c_device_stop_cb_t on_stop,
i2c_device_error_cb_t on_error )

Sets callbacks for I2C device mode events on the given SERCOM.

Parameters
sercomThe SERCOM instance, as numbered in the data sheet.
on_address_matchCalled when the controller addresses this device. May be NULL.
on_data_receivedCalled when the controller writes a byte. May be NULL.
on_data_requestedCalled when the controller reads a byte. May be NULL (sends 0x00).
on_stopCalled when the controller sends a stop condition. May be NULL.
on_errorCalled on bus error. May be NULL.