下面是一段使用 C 语言进行 I2C 通信的示例代码:
#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
// I2C 设备文件的路径
#define I2C_DEV "/dev/i2c-1"
// 要连接的设备的 I2C 地址
#define I2C_ADDR 0x48
int main(int argc, char *argv[])
{
int fd;
unsigned char buf[2];