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.
Tool/software:
Hello,
I m using AWR1843boost for my project and flashes OUT_OF_BOX_DEMO which is available on resource explorer. Want to establish communication between AWR1843boost and ICM-20948 through I2C. According tho this understanding created function named WriteI2C and ReadI2C.
So firstly to check I2C was working or not, so want to read ICM-20948 one register which is WHO_I_AM. According to the datasheet of the ICM-20948 register was divided in to 4 bank and WHO_I_AM register is in bank 0. so had to write bank 0 register address first then read the WHO_I_AM register of the ICM-20948. According tho this understanding created function named ReadI2C and WriteI2C.
1.
for write
Slaveadd = ICM-20948 address which is 0x68 according to datasheet
slaveregadd = USER_BANK_0 which address is 0x00
value = NULL
len = 1
int32_t WriteI2C(uint16_t Slaveadd, uint16_t slaveregadd, uint8_t value, uint8_t len)
{
2C_Handle i2cHandle;
I2C_Params i2cParams;
bool retVal = false;
int32_t errCode = 0;
uint32_t i = 0, numTestBytes;
uint32_t arg;
I2C_init();
i2cParams.transferMode = I2C_WRITE_MODE;
i2cParams.bitRate = I2C_100kHz;
/* Open the I2C driver */
i2cHandle = I2C_open(0, &i2cParams);
if (i2cHandle == NULL)
{
System_printf ("Error: I2C Driver Open failed\n");
return -1;
}
arg = 0;
errCode = I2C_control (i2cHandle, I2C_CMD_ADDR_MODE, (void* )&arg);
if (errCode < 0)
{
System_printf ("Error: I2C control Set loopback failed [Error code %d]\n", errCode);
return -1;
}
/* Test write only followed by read only */
memset(&txData1, 0, sizeof (txData1));
// txData1[0] = 0xA;
txData1[0] = slaveregadd;
txData1[1] = value;
numTestBytes = len;
i2cTransaction.slaveAddress = Slaveadd;
i2cTransaction.writeBuf = txData1;
i2cTransaction.writeCount = numTestBytes;
i2cTransaction.readBuf = NULL;
i2cTransaction.readCount = 0;
retVal = I2C_transfer(i2cHandle, &i2cTransaction);
if (retVal == false)
{
System_printf ("Error: I2C Read from Slave failed\n");
return -1;
}
/* Close I2C driver */
I2C_close(i2cHandle);
return 0;
}
2.
for read
Slaveadd = ICM-20948 address which is 0x68 according to datasheet
slaveregadd = WHO_AM_I_REG which address is 0x00
value = NULL
len = 1
int32_t ReadI2C(uint16_t Slaveadd, uint16_t slaveregadd, uint8_t value, uint8_t len)
{
I2C_Handle i2cHandle;
I2C_Params i2cParams;
bool retVal = false;
int32_t errCode = 0;
uint32_t i = 0, numTestBytes;
uint32_t arg;
I2C_init();
i2cParams.transferMode = I2C_READ_MODE;
i2cParams.bitRate = I2C_100kHz;
/* Open the I2C driver */
i2cHandle = I2C_open(0, &i2cParams);
if (i2cHandle == NULL)
{
System_printf ("Error: I2C Driver Open failed\n");
}
/* Configure the I2C device in loopback mode */
arg = 0;
errCode = I2C_control (i2cHandle, I2C_CMD_ADDR_MODE, (void* )&arg);
if (errCode < 0)
{
System_printf ("Error: I2C control Set loopback failed [Error code %d]\n", errCode);
return -1;
}
/* Test write only followed by read only */
// memset(&rxData1, 0, sizeof (rxData1));
// txData1[0] = 0xA;
// txData1[0] = USER_BANK_SEL;
txData1[0] = slaveregadd;
txData1[1] = value;
numTestBytes = len;
i2cTransaction.slaveAddress = Slaveadd;
i2cTransaction.writeBuf = txData1;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxData1;
i2cTransaction.readCount = numTestBytes;
/* Re-try writing to slave till I2C_transfer returns true */
retVal = I2C_transfer(i2cHandle, &i2cTransaction);
ret = retVal;
if (retVal == false)
{
System_printf ("Error: I2C Read from Slave failed\n");
return -1;
}
/* Close I2C driver */
I2C_close(i2cHandle);
return 0;
}
But, while write the output of the I2C_transfer function was received as -1, so please tell me that my understanding is correct.?, if no so guide me with the right steps for the same.
Regards,
Miit prajapati.
Hi,
We provide I2C unit tests in the driver examples.
Unfortunately we don't have examples with the demos.
C:\ti\mmwave_sdk_03_06_02_00-LTS\packages\ti\drivers\i2c
Thank you
Cesar
Hello cesar,
Thanks for replying.
Can you provide debugging support session from your side for the same, Because write and read function is not working when i connect ICM-20948 to AWR1843boost.
Regrads,
Miit prajapati.
Hi
Unfortunately our team is not able to support this.
Let's open this question to the forum community. Other team members may have been able to use I2C in their system
thank you
Cesar