Dear All,
I am
The Sensorlib's I2C master driver documentation says that the driver has a queue buffer for I2C commands (10 commands organized in a ring-buffer).
In my interpretation this means that especially for the register write operations the code does not have to wait for the end-of-transaction callback before issuing another command (fire and forget), just needs to make sure not to overload the buffer, which is clearly indicated by the return value of the command. I am sure this was the original intention, and it would be nice as I wouldn't have to delay the code execution or create states for all writes).
However here are my experiences: I am trying to interface a common Invensense MPU6050 sensor (but I guess any will do).
For this example let's take three subsequent register write operations from my code:
MPU_I2CWrite(psInst, MPU_RA_SMPLRT_DIV, 9); MPU_I2CWrite(psInst, MPU_RA_GYRO_CONFIG, (MPU_GYRO_FS_500<<3)); MPU_I2CWrite(psInst, MPU_RA_ACCEL_CONFIG, (MPU_ACCEL_FS_2<<3)); while(1);
The register values (third argument) of these three commands are 0x09, 0x08, 0x00.
Here is the write function:
void MPU_I2CWrite(tMPUInst *psInst, uint8_t ui8Reg, uint8_t ui8Value) {
psInst->pui8Buffer[0] = ui8Reg;
psInst->pui8Buffer[1] = ui8Value;
while(!(I2CMCommand(psInst->psI2CInst, psInst->ui8Addr, psInst->pui8Buffer,
2, 0, 0, 0, 0, MPU_write_callback, psInst)));
}
And its callback function:
void MPU_write_callback(void *pvCallbackData, uint_fast8_t ui8Status) {
if(ui8Status != I2CM_STATUS_SUCCESS) g_sErrorCounters.ui16I2CMErrorCount++;
}
The callback does not do anything, but checks if the operation was completed successfully.
But if check the communication the results show that although the device and register addresses are right, except the register values take the last value for all unsent commands (sorry I don't have a logic analyser at hand, just a lousy scope):
I know it's not much fun decoding this, but I confirm the all the device and register addresses are right, but in all three cases the register value is 0 (which is easy to check).
And if I limit the code to two subsequent writes, then -- again -- the value for both writes will be the value for the last issued command (0x08 in my case).
Do I do something wrong? Do I overlook anything?
I would do appreciate your comments, thanks,
Marton
