简体   繁体   English

写入I2C I / O设备

[英]Write to I2C I/O device

I am trying to talk to a Bosch Sensortec BNO055 sensor. 我正在尝试与Bosch Sensortec BNO055传感器交谈。 I am using the shuttleboard. 我正在使用穿梭板。 VDD and VDDIO are connected to 3.3V, on pin 17 and 18 Are SDA and SCL. VDD和VDDIO连接到3.3V,引脚17和18分别为SDA和SCL。 These connected to a embedded linux board. 这些连接到嵌入式linux板上。 An other sensor is on the same bus, I can see its values on the scope. 另一个传感器在同一总线上,我可以在示波器上看到其值。 I have the following code: 我有以下代码:

BNO055_RETURN_FUNCTION_TYPE Bno055I2cBusWrite(u8 dev_addr, u8 reg_addr, u8* reg_data, u8 wr_len){
//According to https://www.kernel.org/doc/Documentation/i2c/dev-interface

    int file = 0;
    char filename[20];
    snprintf(filename, 19, "/dev/i2c-%d", ADAPTER_NR);

    if(open(filename, O_RDWR) < 0){ /*error*/   }
    if(ioctl(file, I2C_SLAVE, dev_addr) < 0){ /*error*/ }

    char buf[1 + wr_len];
    buf[0] = reg_addr;
    memcpy(&buf[1], reg_data, wr_len);

    int written_bytes = 0;
    if(write(file, buf, wr_len) != wr_len){
        printf("Error BusWrite-write: %s.\n", strerror(errno));
        exit(-1);
    }
}

The first two if-statements are passed fine. 前两个if语句可以很好地传递。 The write-operation fails. 写操作失败。 On the oscilloscope I see the correct device-address (which is then not acknowledged). 在示波器上,我看到了正确的设备地址(然后未确认)。 What I've done: 我所做的:

My sensor just does not acknowledges when its device address appears on the line. 我的传感器只是不确认其设备地址何时出现在线路上。

  • What is exactly done by ioctl(file, I2C_SLAVE, dev_addr)? ioctl(file,I2C_SLAVE,dev_addr)到底是做什么的? Does that send out the device-address on the I2C-bus? 是否在I2C总线上发送设备地址?
  • Does the linuxkernel send the device-address by itself? linuxkernel是否自行发送设备地址? I expect so. 我希望这样。

Resuming: 恢复:

  • Can someone point me in the right direction to let the sensor react? 有人可以指出我正确的方向,让传感器做出反应吗?

Well... it just seemed that a wire to the scope interfered too much. 好吧……似乎连接示波器的导线干扰太大。 And the device-address is sent by the driver when writing or reading, to answer my own question. 驱动程序在写入或读取时发送设备地址,以回答我自己的问题。

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

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