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.
工具与软件:
您好!
我将 AWR1843BOOST 用于我的项目、并刷写 Resource Explorer 上提供的 out_of_box_demo。 在它们之间建立通信 AWR1843BOOST 和 ICM - 20948 本地多帧时钟。 根据这种理解 创建的函数命名 WriteI2C 和 ReadI2C .
首先检查 I2C 是否正常工作、因此需要读取一个寄存器 WHO_I_AM、即 ICM -20948。 根据数据表、ICM -20948寄存器分为4组、WHO_I_AM 寄存器位于4组中。 因此、必须先写入组0寄存器地址、然后读取 who_i_am 的 ICM - 20948 . 根据此理解 、创建了名为 ReadI2C 和 WriteI2C 的函数。
1.
专用写入地址
Slaveadd = ICM - 20948地址、根据数据表为0x68
slaveregadd = USER_BANK_0、其地址为0x00
值= NULL
LEN = 1
int32_t WriteI2C (uint16_t Slaveadd、uint16_t slaveregadd、uint8_t 值、uint8_t len)
{
2c_handle i2cHandle;
I2C_Params i2cParams;
Bool RetVal = false;
int32_t errCode = 0;
uint32_t i = 0、numTestBytes;
uint32_t 参数;
I2C_INIT();
i2cParams.transferMode = I2C_WRITE_MODE;
i2cParams.bitrate = I2C_100kHz;
/*打开 I2C 驱动程序*/
i2cHandle = I2C_open (0、&i2cParams);
如果(i2cHandle == NULL)
{
System_printf ("错误:I2C 驱动程序打开失败\n");
返回-1;
}
ARG = 0;
errCode = I2C_CONTROL (i2cHandle、I2C_CMD_ADDR_MODE、(void*)&arg);
如果(errCode < 0)
{
System_printf ("错误:I2C 控制集环回失败[错误代码%d]\n"、errCode);
返回-1;
}
/*测试写入后只读*/
memset (&txData1、0、sizeof (txData1));
// txData1[0]= 0xA;
txData1[0]= slaveregadd;
txData1[1]=值;
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");
返回-1;
}
/*关闭 I2C 驱动程序*/
I2C_Close (i2cHandle);
返回0;
}
2.
读取功能
Slaveadd = ICM - 20948地址、根据数据表为0x68
slaveregadd = who_am_i_REG 的地址为0x00
值= 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 参数;
I2C_INIT();
i2cParams.transferMode = I2C_READ_MODE;
i2cParams.bitrate = I2C_100kHz;
/*打开 I2C 驱动程序*/
i2cHandle = I2C_open (0、&i2cParams);
如果(i2cHandle == NULL)
{
System_printf ("错误:I2C 驱动程序打开失败\n");
}
/*在环回模式下配置 I2C 器件*/
ARG = 0;
errCode = I2C_CONTROL (i2cHandle、I2C_CMD_ADDR_MODE、(void*)&arg);
如果(errCode < 0)
{
System_printf ("错误:I2C 控制集环回失败[错误代码%d]\n"、errCode);
返回-1;
}
/*测试写入后只读*/
// memset (&rxData1、0、sizeof (rxData1));
// txData1[0]= 0xA;
// txData1[0]= USER_BANK_SEL;
txData1[0]= slaveregadd;
txData1[1]=值;
numTestBytes = len;
i2cTransaction .slaveAddress = Slaveadd;
i2cTransaction .writeBuf = txData1;
i2cTransaction .writeCount = 1;
i2cTransaction .readBuf = rxData1;
i2cTransaction .ReadCount = numTestBytes;
/* Re -尝试写入从器件、直到 I2C_transfer 返回 true */
retval = I2C_transfer (i2cHandle、&i2cTransaction);
RET =返回值;
if (retval == false)
{
System_printf ("Error:I2C Read from Slave Failed\n");
返回-1;
}
/*关闭 I2C 驱动程序*/
I2C_Close (i2cHandle);
返回0;
}
但是、虽然写入 I2C_transfer 函数的输出是作为-1接收的、因此请告诉我这方面的理解是正确的。如果没有、请告诉我如何针对相同操作完成正确的步骤。
此致、
MIIT Prajapati.
您好!
我们在驱动程序示例中提供了 I2C 单元测试。
很遗憾、我们没有用于演示的示例。
C:\ti\mmwave_sdk_03_06_02_00-LTS \packages\ti\drivers\i2c
谢谢你
Cesar
cesar、您好!
感谢您的答复。
您能否提供相同的调试支持会话、因为当我将 ICM -20948连接到 AWR1843boost 时、写入和读取功能不起作用。
平地机、
MIIT Prajapati.
你(们)好
很遗憾、我们的团队无法支持这一点。
让我们在论坛社区中打开此问题。 其他团队成员可能已经能够在自己的系统中使用 I2C
谢谢你
Cesar