18.8.1.2.1 Code
The following must be added to the user application:
A sample buffer to write from, a sample buffer to read to and length of buffers:
Address to respond to:#define DATA_LENGTH 10uint8_t write_buffer[DATA_LENGTH] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};uint8_t read_buffer[DATA_LENGTH];
#define SLAVE_ADDRESS 0x12
Globally accessible module structure: Function for setting up the module:structi2c_slave_module i2c_slave_instance;
Add to user application main():voidconfigure_i2c_slave(void){/* Create and initialize config_i2c_slave structure */structi2c_slave_config config_i2c_slave;i2c_slave_get_config_defaults(&config_i2c_slave);/* Change address and address_mode */config_i2c_slave.address = SLAVE_ADDRESS;config_i2c_slave.address_mode = I2C_SLAVE_ADDRESS_MODE_MASK;config_i2c_slave.buffer_timeout = 1000;/* Initialize and enable device with config_i2c_slave */i2c_slave_init(&i2c_slave_instance, CONF_I2C_SLAVE_MODULE, &config_i2c_slave);i2c_slave_enable(&i2c_slave_instance);}
configure_i2c_slave();enumi2c_slave_direction dir;structi2c_slave_packet packet = {.data_length = DATA_LENGTH,.data = write_buffer,};
