This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Detecting NACK response from slave after write?

Other Parts Discussed in Thread: CC3200

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

  • Hi Sridhar,

    Which version of TI-RTOS are you using? Can you also tell us the device that you are using?

    The I2C_transfer should return false when a NACK is received. From the I2C driver docs, the return value will be:

    In I2C_MODE_BLOCKING: true on successful transfer; false on an error, such as an I2C bus fault (NACK). In I2C_MODE_CALLBACK: always true. The transferCallbackFxn's bool argument will be true if successful; false on an error, such as an I2C bus fault (NACK).

    Can you make sure that the i2C slave is sending the master a NACK (with a scope)?

    Thanks,

    Vikram

  • Hi Vikram, 

    Thanks for your response. I'm using TI-RTOS 2.16.01.14 with CC3200, and using the blocking mode. 

    I figured out the problem. The MCP39F521 sends back an ack or a nack as a 1 byte header that needs to be read. I was not doing the reading of the 1 byte response. Once I did that everything worked as expected. 

    Thanks,
    Sridhar