首页 文章

在i2c套接字中写入覆盆子错误

提问于
浏览
0

我试图通过智能手机控制我的家庭住宅,智能手机通过互联网(Wi-Fi)向Raspberry发送3-4个字节,Raspberry通过I2C总线将所有这些字节发送到相应的Arduino(我有两个Arduinos) . 当我向Raspberry发送命令时,显示“无法写入i2c总线”任何人都可以帮助我吗?

int i2csend(msg_t *pmsg)
  {
    int fd;
    /* Open I2C device */
    if ((fd = open(device, O_RDWR)) < 0) error ("Can't open I2C device");
    if (ioctl(fd, I2C_SLAVE, arduino_addr) < 0) error ("Can't talk to slave");
    if (write(fd, (char *)pmsg, n) < n ) printf ("Failed to write to the i2c bus [1]\n");
    else
    {
      read(fd, (char *)pmsg, n);
      printf("Ricevuto il messaggio: %c%c %d %d\n", pmsg->tipo, pmsg->gruppo, pmsg->dato[0], pmsg->dato[1]);
    }
    close(fd);
    return 0;
  }

1 回答

  • 0

    当我在raspi上使用I2C时,我从未在if语句中使用'open'函数(就像你在i2csend()函数中那样) . 这是我的一个(工作)项目的样本:

    //open file for i2c interface
    int fh=open("/dev/i2c-1",O_RDWR);
    if (ioctl(fh, I2C_SLAVE, UIBC_ADDR) < 0){
        printf("Couldn't establish contact with the UIBC\n");
    }
    

相关问题