在我的主板上,我有一个设置寄存器的I2C设备。
g_I2cDevFd = open("/dev/" UMAP_DEVNAME_I2C, O_RDWR, 0);
if (g_I2cDevFd < 0)
{
HI_FATAL_I2C("open I2C err.\n");
HI_I2C_UNLOCK();
return HI_ERR_I2C_OPEN_ERR;
}
我该怎么做?
最好的问候
答案 0 :(得分:0)
你的问题不是很清楚。但对于Linux Os中的I2C通信,请参阅此链接Interfacing_with_I2C_Devices
UMAP_DEVNAME_I2C
本身时使用您的设备路径。即,#define UMAP_DEVNAME_I2C "/dev/your_i2c_device"
如果您无法修改sprintf
,即
UMAP_DEVNAME_I2C
char buff[100] = {0}; // size you can change according to your requirement
sprintf(buff,"/dev/%s",UMAP_DEVNAME_I2C);
g_I2cDevFd = open(buff, O_RDWR, 0);
/* Error check for open here*/
int addr = 0xFF; // 0xFF is Invalid, Give I2C address of your device
if (ioctl(g_I2cDevFd, I2C_SLAVE, addr) < 0) {
printf("Failed to acquire bus access and/or talk to slave.\n");
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
/* Write or Read*/