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.

Integrating INA219 & CC2650 - I2C Bus

Other Parts Discussed in Thread: INA219, CC2650, TMP006, CC2650STK, TMP007

Hi

I am working on integrating INA219 & CC2650 through the I2C, I am following the guidelines given in the datasheet for INA219. I want to go step by step, as I understand from the datasheet of INA219, the first task is to write into the calibration register '05h'. Assuming a 0.1 ohm shunt resistor, In order to configure the maximum I/P voltage & current to 2A and 26V after some calculations as per datasheet I came up with a value of 4096 which in hexadecimal is 1000. Now, when I write 1000 in the calibration register, I can now expect values from the current and power registers(adress 04H & 03H) respectively. I have hence modified the TI temperature sensor example code(mainly the taskFXN) as shown below to read the current and power registers. However I am not successfull!, can someone please point out the mistake in my code. My Code is as given below.

Void taskFxn(UArg arg0, UArg arg1)
{
// unsigned int i;
// uint16_t temperature;
uint8_t txBuffer[4];
uint8_t rxBuffer[3];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;

/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(Board_I2C_TMP, &i2cParams);
if (i2c == NULL) {
System_abort("Error Initializing I2C\n");
}
else {
System_printf("I2C Initialized!\n");
}

/* Point to the T ambient register and read its 2 bytes */
txBuffer[0] = 0x05; // Calibration Register Address
txBuffer[1] = 0x1000; // Value written onto the calibration register- 4096(0x1000) for 32V,2A configuration
txBuffer[2] = 0x04; //Current Register address
txBuffer[3] = 0x03; //Power Register address
// i2cTransaction.slaveAddress = Board_TMP006_ADDR;
i2cTransaction.slaveAddress = 0x40; //address of INA219 foe A0, A1 grounded
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 2;
if (I2C_transfer(i2c, &i2cTransaction)){
System_printf("Current: %x W \n", rxBuffer[0]);
System_printf("Power: %x A \n", rxBuffer[1]);
} else {
System_printf("Read/write fail!\n");

System_flush();
Task_sleep(1000000 / Clock_tickPeriod);
}

I2C_close(i2c);
System_printf("I2C closed!\n");

System_flush();
}

My Console port results are as follows:

[Cortex_M3_0] Starting the I2C example
System provider is set to SysMin. Halt the target to view any SysMin contents in ROV.
I2C Initialized!
Read fail!
I2C closed!

Can Some please point out the mistake in my code.

Thanks in advance for the help.

  • Make sure your INA219 A0 and A1 pins are well grounded.
  • Hi Yikai

    It is well grounded, I am infact using the adafruit INA219 Eval board, I have made sure it is well grounded, do let me know if there is a mistake with my code.

    Thanks.
  • Your code looks OK. I would suggest you to use oscilloscope to check I2C SCL and SDA signal.
  • Hi Yikai

    I am now able to read from the registers of INA219, I was trying to read from DI08 & DI09,but however I am able to read using DI05 &DI06 as I2C ports. I want to use DI08 & DI09 as I2C ports. In the sensortag schematics 'MPU-9250' is connected to DI08 &DI09. Please guide me on how to configure the ports 'DI08 &DI09' as I2C pins in the I2C_TMP example program,

    Thanksin advance.

  • Can you show me how you config I2C pins to DI08 & DI09 instead of DI05 &DI06?
  • well, in the I2Ctmp006 example program I open CC2650STK.C and there under the following structure given below..

    const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC2650STK_I2CCOUNT] = {
    {
    .baseAddr = I2C0_BASE,
    .powerMngrId = PowerCC26XX_PERIPH_I2C0,
    .intNum = INT_I2C_IRQ,
    .intPriority = ~0,
    .swiPriority = 0,
    .sdaPin = Board_I2C0_SDA0,
    .sclPin = Board_I2C0_SCL0,
    }

    the statements .sdaPin & .sclPin are assigned with the addresses, in the actually program 'Board_I2C0_SDA0'& 'Board_I2C0_SCL0' is assigned with DIO5 & 6 respectively which is 0x00000005 & 0x00000006, instead I am assigning 0x00000008 & 0x00000009 to .sdaPin & .sclPin respectively.

    But I'm not ableto get the desired result.

    Pl help me.

    Thanks
  • Your setting looks correct. Do you use oscilloscope to check if there is clock signal output on I2C SCL pin?
  • Hi Pritam,

    I will take a look at this question and get back to you soon with feedback.

    Best regards,

    Aymeric Nicolas

  • Hi Pritam,

    I had a look to your code and would like to confirm with you some points.

    1) You declare the buffer array: uint8_t txBuffer[4]; which is a bytes array. Then you write a value on the 2nd case of this array: txBuffer[1] = 0x1000;
    If it's bytes array you should not be able to write down a value which is more than a byte.

    2) You said you are using the "I2C_TMP example program". Do you mean you are using the sensorTag project which uses tmp007 drivers?
    If you use the sensorTag project or any other project from the TI BLE stack you have a file called Board.h where the different IOs are listed.

    /* I2C */
    #define Board_I2C0_SDA0 IOID_5
    #define Board_I2C0_SCL0 IOID_6
    #define Board_I2C0_SDA1 IOID_8
    #define Board_I2C0_SCL1 IOID_9

    Best regards,
    Aymeric Nicolas