I2C xfer question using the LPCOpen framework [SOLVED]

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I2C xfer question using the LPCOpen framework [SOLVED]

1,173 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Fri Dec 05 17:57:04 MST 2014
Hi,

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(); }

ReadTemperatureI2CM();
}

return 0;
}


Thank you!!
Labels (1)
0 Kudos
Reply
2 Replies

966 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Tue Dec 23 19:32:18 MST 2014

Quote: 1234567890
Indeed you only have to write the fields with changed values.
But this is a allways-safe function. And usually you change [u]all[/u] values during runtime of a program (address, sizes, sometimes buffers as well) and this avoids using an outdated wrong value.



That's right!! I found that when using only and only one I2C device it's enough to fill the struct once. However, a typical system has more than one I2C device on-board; so one needs to update the struct fields whenever communicating with any other device.

Thank you!
0 Kudos
Reply

966 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by 1234567890 on Sat Dec 06 04:54:06 MST 2014
Indeed you only have to write the fields with changed values.
But this is a allways-safe function. And usually you change [u]all[/u] values during runtime of a program (address, sizes, sometimes buffers as well) and this avoids using an outdated wrong value.
0 Kudos
Reply