小编Joh*_*rye的帖子

读取时不返回写入 I2C 的缓冲区

我试图在写入后从 I2C 总线上的内存位置读取一个值。当我在终端中运行它时,我得到了奇怪的输出。

这是我的程序

    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    #include <inttypes.h>

    #include <errno.h>
    #include <string.h>

    #include <sys/stat.h>
    #include <fcntl.h>
    #include <unistd.h>

    #include <linux/i2c.h>
    #include <linux/i2c-dev.h>
    #include <sys/ioctl.h>

    #define I2C_ADAPTER "/dev/i2c-0"
    #define I2C_DEVICE  0x00


    int main (int argc, char *argv[])
    {
        int file;
        int addr = 0X00; /* XGPIOPS_DATA_LOW_OFFSET */

        if((file = open(I2C_ADAPTER, O_RDWR)) < 0) {
            printf("Failed to open the bus");
            return -1;
        }

        if(ioctl(file, I2C_SLAVE, addr) < 0) {
            printf("Unable to open device as slave %s", strerror(errno));
            return …
Run Code Online (Sandbox Code Playgroud)

c linux embedded qemu i2c

3
推荐指数
1
解决办法
2005
查看次数

标签 统计

c ×1

embedded ×1

i2c ×1

linux ×1

qemu ×1