Hi,
I have an i2c slave (Microchip MCP39F521) and one of the commands returns a nack when the command does not succeed.
I expect the I2C_transfer that I do to return false, but it does not.
int autoCalibrateGain()
{
uint8_t aucWriteDataBuf[4];
int i;
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
uint32_t checksumTotal = 0;
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_100kHz;
i2c = I2C_open(Board_I2C_TMP, &i2cParams);
if (i2c == NULL) {
System_printf("[MCP39F521] Error Initializing I2C\n");
return 0;
}
else {
System_printf("[MCP39F521] I2C Initialized!\n");
}
System_printf("[MCP39F521] After I2C init\n");
aucWriteDataBuf[0] = 0xa5; // Header
aucWriteDataBuf[1] = 0x04; // Num bytes
aucWriteDataBuf[2] = 0x5a; // Command
aucWriteDataBuf[3] = 0x03; // checksum
i2cTransaction.slaveAddress = 0x74;
i2cTransaction.writeBuf = aucWriteDataBuf;
i2cTransaction.writeCount = 4;
i2cTransaction.readBuf = NULL;
i2cTransaction.readCount = 0;
System_printf("[MCP39F521] Before I2C_transfer\n");
if (I2C_transfer(i2c, &i2cTransaction)) {
System_printf("[MCP39F521] I2C write complete\n");
}
else {
System_printf("[MCP39F521] I2C write failed 1\n");
/* Deinitialized I2C */
I2C_close(i2c);
System_printf("[MCP39F521] I2C Closed\n");
return 0;
}
/* Deinitialized I2C */
I2C_close(i2c);
System_printf("[MCP39F521] I2C Closed\n");
return 1;
}
In my particular case, I expect the command write to give me a NACK, and so for the I2C_transfer to return false.
TABLE 4-9: AUTO-CALIBRATE GAIN COMMAND Byte # Value Byte Description Response from MCP39F521 1 0xA5 Header Byte 2 0x04 Number of Bytes in Frame 3 0x5A Command (Auto-Calibrate Gain) 4 0x03 Checksum ACK (or NAK if unable to calibrate),
see Section 8.0,MCP39F521 Calibration for more information.
I'm wondering if my understanding of I2C_transfer is right in this circumstance?
Thanks,
Sridhar