I2C xfer question using the LPCOpen framework [SOLVED]

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by fjrg76 on Fri Dec 05 17:57:04 MST 2014

I'm using the I2C peripheral for the first time with this CPU and the LPCOpen framework. I'm aware on how I2C works and I've been using it with other chips (LPC1114, LPC2103, etc.) While studying the code in the example "periph_i2cm_polling.c" I noted that the struct variable i2cmXferRec is filled everytime that the function

Chip_I2CM_XferBlocking(LPC_I2C0, &i2cmXferRec)

is called. Is that really needed? I mean, it can be filled just once, and then just check the field .status after each calling. Is that behavior because of the example, or it is the way the function Chip_I2CM_XferBlocking() is used? I'm pasting a cropped code so you get a better idea about I'm talking about. From the code below it's seen that it's not needed to refill the struct every time because almost all fields remain unchanged, except the .status field (and the buffers pointed by the pointers, but the pointers themself doesn't change either).

static void SetupXferRecAndExecute(uint8_t devAddr, uint8_t *txBuffPtr, uint16_t txSize, uint8_t *rxBuffPtr, uint16_t rxSize)
i2cmXferRec.slaveAddr = devAddr;
i2cmXferRec.status = 0;
i2cmXferRec.txSz = txSize;
i2cmXferRec.rxSz = rxSize;
i2cmXferRec.txBuff = txBuffPtr;
i2cmXferRec.rxBuff = rxBuffPtr;

Chip_I2CM_XferBlocking(LPC_I2C0, &i2cmXferRec);

static void ReadTemperatureI2CM(void)
uint8_t temperature[2];
uint8_t lm75TempRegisterAddress = 0;

SetupXferRecAndExecute( I2C_TEMP_ADDR_7BIT, &lm75TempRegisterAddress, 1, temperature, 2);

if (i2cmXferRec.status == I2CM_STATUS_OK) {
/* Do something */
else {
/* Do something*/

int main(void)
/* Setup I2C ... */

/* More setup ... */

while (1) {
while (lastState == state) { __WFI(); }


return 0;

Thank you!!