我的船上我有一個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