相关疑难解决方法(0)

在Linux上使用I2C读/写

我正在尝试读取/写入FM24CL64-GTR FRAM通过地址上的I2C总线连接的芯片0b 1010 011.

当我试图写3个字节(数据地址2个字节,+数据一个字节)时,我得到一个内核消息([12406.360000] i2c-adapter i2c-0: sendbytes: NAK bailout.),以及写返回!= 3.参见下面的代码:

#include <linux/i2c-dev.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>

int file;
char filename[20];
int addr = 0x53; // 0b1010011; /* The I2C address */
uint16_t dataAddr = 0x1234;
uint8_t val = 0x5c;
uint8_t buf[3];

sprintf(filename,"/dev/i2c-%d",0);
if ((file = open(filename,O_RDWR)) < 0)
    exit(1);

if (ioctl(file,I2C_SLAVE,addr) < 0)
    exit(2);

buf[0] = dataAddr >> 8;
buf[1] = dataAddr & 0xff;
buf[2] = val;

if (write(file, buf, 3) …
Run Code Online (Sandbox Code Playgroud)

c linux ioctl i2c

13
推荐指数
2
解决办法
5万
查看次数

标签 统计

c ×1

i2c ×1

ioctl ×1

linux ×1