18.8.2.2.2 Workflow
- Configure and enable module.
configure_i2c_slave();
- Create and initialize configuration structure.
struct
i2c_slave_config config_i2c_slave;
i2c_slave_get_config_defaults(&config_i2c_slave);
- Change address and address mode settings in the configuration.
config_i2c_slave.address = SLAVE_ADDRESS;
config_i2c_slave.address_mode = I2C_SLAVE_ADDRESS_MODE_MASK;
- Initialize the module with the set configurations.
i2c_slave_init(&i2c_slave_instance, CONF_I2C_SLAVE_MODULE, &config_i2c_slave);
- Enable the module.
i2c_slave_enable(&i2c_slave_instance);
- Register and enable callback functions.
configure_i2c_slave_callbacks();
- Register and enable callbacks for read and write requests from master.
i2c_slave_register_callback(&i2c_slave_instance, i2c_read_request_callback,
I2C_SLAVE_CALLBACK_READ_REQUEST);
i2c_slave_enable_callback(&i2c_slave_instance,
I2C_SLAVE_CALLBACK_READ_REQUEST);
i2c_slave_register_callback(&i2c_slave_instance, i2c_write_request_callback,
I2C_SLAVE_CALLBACK_WRITE_REQUEST);
i2c_slave_enable_callback(&i2c_slave_instance,
I2C_SLAVE_CALLBACK_WRITE_REQUEST);