17.8.2.2.2 Workflow

  1. Configure and enable module.
    configure_i2c();
    
    1. Create and initialize configuration structure.
      struct i2c_master_config config_i2c_master;
      i2c_master_get_config_defaults(&config_i2c_master);
      
    2. Change settings in the configuration.
      config_i2c_master.buffer_timeout = 65535;
      
    3. Initialize the module with the set configurations.
      while(i2c_master_init(&i2c_master_instance, CONF_I2C_MASTER_MODULE, &config_i2c_master)     \
              != STATUS_OK);
      
    4. Enable the module.
      i2c_master_enable(&i2c_master_instance);
      
  2. Configure callback functionality.
    configure_i2c_callbacks();
    
    1. Register write complete callback.
      i2c_master_register_callback(&i2c_master_instance, i2c_write_complete_callback,
              I2C_MASTER_CALLBACK_WRITE_COMPLETE);
      
    2. Enable write complete callback.
      i2c_master_enable_callback(&i2c_master_instance,
              I2C_MASTER_CALLBACK_WRITE_COMPLETE);
      
  3. Create a packet to send to slave.
    wr_packet.address     = SLAVE_ADDRESS;
    wr_packet.data_length = DATA_LENGTH;
    wr_packet.data        = wr_buffer;