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.

RM46L852: I2C communication with INA237

Part Number: RM46L852
Other Parts Discussed in Thread: INA237, , SYSCONFIG

Dear Champs,

My customer connected INA237 to RM46L852 through I2C, but failed to communicate with INA237.

As there is no implementation for I2C communication in below sysconfig generated driver code, 

https://dev.ti.com/sysconfig/index.html?product=ascstudio&module=/ti/sensors/currentsensor/INA237

they implemented it by themselves, but failed to communcate with INA237.

Could you please check below code or share the example for I2C communication with INA237?

~~~~~~~

uint8_t i2c_send(uint32 length, uint8 * data, uint8_t slave_Address)
{
    uint8_t err_ret = 0;
//   while(i2cIsTxReady(i2cREG1) == 0){}
 uint16_t cnt = 0;
    i2cSetSlaveAdd(i2cREG1, slave_Address);
    i2cSetDirection(i2cREG1,I2C_TRANSMITTER);
    i2cSetCount(i2cREG1, length);
    i2cSetMode(i2cREG1, I2C_MASTER);
    i2cSetStop(i2cREG1);
    i2cSetStart(i2cREG1);
    i2cSend(i2cREG1, length, data);
    //i2cSetStop(i2cREG1);
   
    while(i2cIsBusBusy(i2cREG1) == true){
  cnt++;
  if(cnt > 0x7ff){
   //printf("i2c_send timeout!!\n");
   err_ret = 1;
   break;
  }
 }
 cnt = 0;
    while(i2cIsStopDetected(i2cREG1) == 0){
  cnt++;
  if(cnt > 0x7ff){
   //printf("i2c_send timeout!!\n");
   err_ret = 1;
   break;
  }
 }
    i2cClearSCD(i2cREG1);

 cnt = 0;
    while(i2cIsMasterReady(i2cREG1) == 0){
  cnt++;
  if(cnt > 0x7ff){
   //printf("i2c_send timeout!!\n");
   err_ret = 1;
   break;
  }
 }

    if (err_ret == 1) {
        //printf("err_ret %d : do i2cInit\n", err_ret);
        i2c_reinit();
    }

    return err_ret;
}

 

uint8_t i2c_receive(uint8 * data, uint8_t cnt, uint8_t slave_Address)
{
 uint8_t err_ret = 0;
 uint16_t failcnt = 0;
  //  uint8_t i;
  //  uint8_t tempData[40];

//    while(i2cIsRxReady(i2cREG1) == 0){}
    i2cSetSlaveAdd(i2cREG1, slave_Address);
    i2cSetDirection(i2cREG1,I2C_RECEIVER);
    i2cSetCount(i2cREG1, cnt);
    i2cSetMode(i2cREG1, I2C_MASTER);
    i2cSetStop(i2cREG1);
    i2cSetStart(i2cREG1);
#if 0

    i2cReceive(i2cREG1,40,tempData);

#else
    i2cReceive(i2cREG1,cnt,&data[0]);
/*
    if(data[0]<3)
    {
        i2cREG1->MDR |= 0x8000;
        i2cSetStop(i2cREG1);
        i2cReceive(i2cREG1,1,&data[1]);
    }
    else
    {
        i2cReceive(i2cREG1,data[0]-2,&data[1]);
        i2cREG1->MDR |= 0x8000;
        i2cSetStop(i2cREG1);
        i2cReceive(i2cREG1,1,&data[data[0]-1]);
    }
*/
#endif
    //i2cSetStop(i2cREG1);
    while(i2cIsBusBusy(i2cREG1) == true){
        failcnt++;
  if(failcnt > 0x7ff){
   //printf("i2c_receive timeout!!\n");
   err_ret = 1;
   break;
  }
 }
    failcnt = 0;
    while(i2cIsStopDetected(i2cREG1) == 0){
        failcnt++;
  if(failcnt > 0x7ff){
   //printf("i2c_receive timeout!!\n");
   err_ret = 1;
   break;
  }
 }
    failcnt = 0;

    i2cClearSCD(i2cREG1);
    while(i2cIsMasterReady(i2cREG1) == 0){
        failcnt++;
  if(failcnt > 0x7ff){
   //printf("i2c_receive timeout!!\n");
   err_ret = 1;
   break;
  }
 }

    i2c_delay(100);
   // memcpy(data,tempData,tempData[0]);
    return err_ret;
}

 

int8_t mcu_i2cTransfer( uint8_t busId, uint8_t i2cAddr,
                        uint8_t *dataToWrite, uint8_t writeLength,
                        uint8_t *dataToRead,  uint8_t readLength)
{
    /*
     *  Add MCU specific I2C read/write code here.
     */
    int8_t err_ret = 0;
    err_ret = (int8_t)i2c_send(writeLength, dataToWrite, i2cAddr);
    if(err_ret != 0){
        printf("send err\n");
    }
    else if(readLength > 0){
        err_ret = i2c_receive(dataToRead, readLength, i2cAddr);
        if(err_ret != 0){
            printf("receive err\n");
        }
    }
    return err_ret;
    /*
     *  Add MCU specific return code for error handling
     */

    return (0);
}

~~~~~~~~

Thanks and Best Regards,

SI.

  • Could you please check below code or share the example for I2C communication with INA237?

    What is the problem with your code? We don't have example code for communicating with INA237.

    Are I2C SCL and SDA pulled up through resistors? Both SCL and SDA lines are "open drain", so the I2C module can drive SCL and SDA Low, but cannot drive them High. For those two lines to be able to go high you must provide pull-up resistors.

    Do you use the correct slave address? The I2C address of INA237 is defined by pin A0 and pin A1. 

    The pin 3 and pin 4 are shared between I2C and N2HET1, and MibSPI. Please configure the pinmmx properly: