17.8.2.2.1 Code
The following must be added to the user application:
A sample buffer to write from, a reversed buffer to write from and length of buffers.
Address of slave:#define DATA_LENGTH 8staticuint8_t wr_buffer[DATA_LENGTH] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};staticuint8_t wr_buffer_reversed[DATA_LENGTH] = {0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};staticuint8_t rd_buffer[DATA_LENGTH];
#define SLAVE_ADDRESS 0x12
Globally accessible module structure: Globally accessible packet:structi2c_master_module i2c_master_instance;
Function for setting up module:structi2c_master_packet wr_packet;structi2c_master_packet rd_packet;
Callback function for write complete:voidconfigure_i2c(void){/* Initialize config structure and software module */structi2c_master_config config_i2c_master;i2c_master_get_config_defaults(&config_i2c_master);/* Change buffer timeout to something longer */config_i2c_master.buffer_timeout = 65535;/* Initialize and enable device with config */while(i2c_master_init(&i2c_master_instance, CONF_I2C_MASTER_MODULE, &config_i2c_master) \!= STATUS_OK);i2c_master_enable(&i2c_master_instance);}
Function for setting up the callback functionality of the driver:voidi2c_write_complete_callback(structi2c_master_module *constmodule){/* Initiate new packet read */i2c_master_read_packet_job(&i2c_master_instance,&rd_packet);}
Add to user application main():voidconfigure_i2c_callbacks(void){/* Register callback function. */i2c_master_register_callback(&i2c_master_instance, i2c_write_complete_callback,I2C_MASTER_CALLBACK_WRITE_COMPLETE);i2c_master_enable_callback(&i2c_master_instance,I2C_MASTER_CALLBACK_WRITE_COMPLETE);}
/* Configure device and enable. */configure_i2c();/* Configure callbacks and enable. */configure_i2c_callbacks();
