繁体   English   中英

在i2c套接字中写入Raspberry错误

[英]Raspberry error write in i2c socket

我正在尝试通过智能手机控制我的房屋,智能手机通过Internet(Wi-Fi)将3-4字节发送到Raspberry,Raspberry通过I2C总线将所有这些字节发送到相应的Arduino(我有两个Arduino)。 当我将命令发送到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;
  }

当我在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");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM