This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

C advice with app_twi peripheral configuration

I've been trying to wrap my head around the app_twi library by looking at the examples, and I'm slowly getting there. However, for my application I need to send multiple default configuration commands to my accelerometer.

So I was wondering, what is the neatest way to implement this? Would I simply make another default_config[] type array and put an additional write into the "lm75b_init_transfers" array? Or is there a neater way to include all of the config data in one default_config[] array? My C is a little rusty, but I feel like a struct might be what I need but I'm not sure how I'd implement it in this case.

The configuration code as it is in the example is show below.

uint8_t const lm75b_conf_reg_addr  = LM75B_REG_CONF;
uint8_t const lm75b_temp_reg_addr  = LM75B_REG_TEMP;
uint8_t const lm75b_tos_reg_addr   = LM75B_REG_TOS;
uint8_t const lm75b_thyst_reg_addr = LM75B_REG_THYST;


// Set default configuration of LM75B - write 0 to Conf register.
static uint8_t const default_config[] = { LM75B_REG_CONF, 0 }; 
///// I need two config commands 

app_twi_transfer_t const lm75b_init_transfers[LM75B_INIT_TRANSFER_COUNT] =
{
    APP_TWI_WRITE(LM75B_ADDR, default_config, sizeof(default_config), 0)
    /////, Another APP_TWI_WRITE for additional config command here?
};
Related