how to enable smbus quick command on my i2c bus?

Options
alexis_nicolas
alexis_nicolas New Member Posts: 8

I want to use a sensor with one of the 2 i2c bus on the 40 pins HAT on the UP4000. but my sensor requires an i2c quick command to start a measurement. basically I need just to send the address of the sensor and the write bit, with no other bytes sent after. but the SMBus Quick Command is not not enabled on the 2 bus. I ran i2cdetect -F 0 and 1 to verify that the 2 bus didn't have this functionality enabled.

I am using c++. I already did the open() and ioctl() calls si Im just showing you the code that wont let me send the quick command.
if (write(busNumber, NULL, 0) != 0) { perror("could not ask the humidity sensor to take the measurement"); }

and

struct i2c_smbus_ioctl_data test;
test.read_write = I2C_SMBUS_WRITE;
test.command = 0;
test.size = I2C_SMBUS_QUICK;
test.data = NULL;
if (ioctl(busNumber, I2C_SMBUS, &test) < 0) {
   perror("ioctl error");
}

int the 2 cases I receive an Operation not supported error message, I believe it is because the quick command is not enabled, because doing a write with sending bytes is working.

is there a way that I could enable the quick command on my i2c bus? or that my code could bypass that.

Thank you

Tagged:

Best Answer

  • garyw
    garyw New Member, Moderator, AAEON Posts: 82 admin
    Answer ✓
    Options

    @alexis_nicolas
    every i2c device has their own slave address,
    you can try command i2cdetect -y -r i2cbus(0 ~ 3) to detect your i2c device in specific bus,

    then you can reference i2c-tools source code, the detect function is write slave address to check is there are any ack from i2c bus, the struct should filled as below

    //actually no matter read or write because just check has ACK or not
    test.read_write = I2C_SMBUS_WRITE;
    test.command = 0;
    test.size = I2C_SMBUS_BYTE;
    //in i2cdetect it's for loop 0x8~0x77
    test.data = you slave address;

    print your error then you will know what error in ioctl call.

Answers