18.8.2.2.2 Workflow

  1. Configure and enable module.
    configure_i2c_slave();
    
    1. Create and initialize configuration structure.
      struct i2c_slave_config config_i2c_slave;
      i2c_slave_get_config_defaults(&config_i2c_slave);
      
    2. 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;
      
    3. Initialize the module with the set configurations.
      i2c_slave_init(&i2c_slave_instance, CONF_I2C_SLAVE_MODULE, &config_i2c_slave);
      
    4. Enable the module.
      i2c_slave_enable(&i2c_slave_instance);
      
  2. Register and enable callback functions.
    configure_i2c_slave_callbacks();
    
    1. 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);