我正在读/写到通过I2C总线连接的地址为0b 1010 011的FM24CL64-GTR FRAM芯片.
当我试图写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) != 3) exit(3); ...
但是当我写2个字节,然后写另一个字节,我没有内核错误,但是当尝试从FRAM读取时,我总是得到0.这是从FRAM读取的代码:
uint8_t val; if ((file = open(filename,addr) < 0) exit(2); if (write(file,&dataAddr,2) != 2) { exit(3); if (read(file,&val,1) != 1) { exit(3);
#include <linux/i2c.h> struct i2c_rdwr_ioctl_data work_queue; struct i2c_msg msg[2]; uint8_t ret; work_queue.nmsgs = 2; work_queue.msgs = msg; work_queue.msgs[0].addr = addr; work_queue.msgs[0].len = 2; work_queue.msgs[0].flags = 0; work_queue.msgs[0].buf = &dataAddr; work_queue.msgs[1].addr = addr; work_queue.msgs[1].len = 1; work_queue.msgs[1].flags = I2C_M_RD; work_queue.msgs[1].buf = &ret; if (ioctl(file,I2C_RDWR,&work_queue) < 0) exit(3);
哪个也成功,但总是返回0.这是否表示硬件问题,或者我做错了?
FM24CL64-GTR在Linux上是否有任何FRAM驱动程序,而且API是什么?任何链接将是有帮助的.