工具与软件:
您好!
我尝试使用 C 代码与 J721e EVM 板(通用板)中的 I2C 器件进行通信。 但无法访问器件。 我将代码附在这里。
void Config_value();
int i2cfile = 0;
void main()
{
char *bus = "/dev/i2c-3"; // assigning a pointer to the path
//Opening the bus
if((i2cfile = open(bus, O_RDWR)) < 0)
{
printf("Failed to open the bus. \n");
exit(1);
}
// Get I2C device,
if(ioctl(i2cfile, I2C_SLAVE, 0x28)<0)
{
printf("Error\n");
exit(1);
}
printf("\nCommunication Started\n");
Config_value();
}
void Config_value()
{
char i2cconfig[3] = {0};
i2cconfig[0] = 0x0E;//Configuration register 14
i2cconfig[1] = 0x3F;
write(i2cfile,i2cconfig,2);
}
执行上述代码后、我使用命令"i2cget -f -y 3 0x22 0x0E b"检查寄存器。 值不变。
我可以使用"i2cset -f -y 3 0x22 0x0E 0x3F b"更改值。 从器件地址为0x22。
此致、
Rejin




