我正在使用C打开MT7688上的 openwrt / dev / i2c-0 并发送64个字节,这很好。 但发送128个字节会出错。 我发现发送超过64个字节将是错误的。我收到“ 无效的参数”错误消息。 我可以发送64个字节,所以它不是SMbus。 我使用128x64 OLED屏幕,一次需要发送130个字节。
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#define I2C_SLAVE 0x0703
int main(int argc, char **argv) {
int fd;
/* is't work fine
char buffer[63] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
0x41,0x42,0x43
};
*/
// does not send
char buffer[128] = {0x01,0x02,0x03,0x04,0x05,....,0x80};
fd = open("/dev/i2c-0", O_RDWR);
if (fd < 0)
{
// Open port for reading and writing
fprintf(stderr, "Failed to open i2c bus /dev/i2c-0\n");
return 1;
}
ioctl(fd, I2C_SLAVE, 0x3C);
write(fd, buffer, sizeof(buffer));
close(fd);
return 0;
}
有人知道如何解决吗?