Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed example to work on a raspberry pi #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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