Skip to content

Conversation

@JamesWP
Copy link

@JamesWP JamesWP commented May 28, 2020

the linux api to talk to i2c devices requires that the device id be specified by ioctl, otherwise how would it know which device to talk to?!

the linux api to talk to i2c devices requires that the device id be specified by ioctl, otherwise how would it know which device to talk to?!
@komigabor
Copy link

I tested this on a Raspberry Pi 4 (with latest Raspberry Pi OS) and can confirm that it works (after resolving conflicts). In contrast with the current version which does not.

Conflict resolution:

  • use id struct (this is what marked as conflict)
  • assign device address before use

final result:

[...]
    /* Make sure to select BME280_I2C_ADDR_PRIM or BME280_I2C_ADDR_SEC as needed */
    id.dev_addr = BME280_I2C_ADDR_PRIM;

    if (ioctl(id.fd, I2C_SLAVE, id.dev_addr) < 0)
    {
        fprintf(stderr, "Failed to acquire bus access and/or talk to slave.\n");
        exit(1);
    }

    dev.intf = BME280_I2C_INTF;
    dev.read = user_i2c_read;
    dev.write = user_i2c_write;
    dev.delay_us = user_delay_us;
[...]

bablokb added a commit to bablokb/BME280_driver that referenced this pull request Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants