我的船上我有一个I2C器件,设置一些寄存器。内核驱动程序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;
}
我该怎么做?
最好的问候
我的船上我有一个I2C器件,设置一些寄存器。内核驱动程序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;
}
我该怎么做?
最好的问候
你的问题不是很清楚。但对于Linux操作系统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*/
这个问题是在审查队列。你应该说明内核版本。 – jww
Linux的67年3月4日的版本。 – 7758521