0

I'm trying to read value from register on my device using I2C protocol on RPi CM4.
All is connected and workign fine using i2cget/i2cset on shell level.

But when I try to access to register of my device by Pi4J, I always get 0 value and communication with device freeze, I can't even using i2cget/i2cset do anything until I restart my device.

Device is Owiic Relay based on OMRON G5LE.

I'm not sure if my I2CConfig is ok, because I can't find what I should set in id and device fields.

Context context = Pi4J.newAutoContext();
I2CProvider i2CProvider = context.provider("linuxfs-i2c");
I2CConfig i2cConfig = I2C.newConfigBuilder(context).id("i2c-1").bus(1).device(0x18).build();
I2C device = i2CProvider.create(i2cConfig);

device.readRegister(0x18);

Register address is 0x18, and bus number is 1, that's all I know. Also I tried diferent i2c providers like raspberrypi-i2c, pigpio-i2c and linuxfs-i2c.

Son
  • 960
  • 2
  • 14
  • 25
  • If you did `i2cget`, then you must know what the device address is. You have to have that. That's like the IP address of the device. What i2cget command worked? – Tim Roberts May 30 '23 at 21:43
  • If I think correct, then device number and register are same, so in my case is 0x18 - but I'm not sure of that. Same as I2C ID is strict corelated with bus number? – Son May 30 '23 at 21:56
  • Every chip has its own I2C device ID. You need to know that number in order to address the device. Did you mean QWIIC? You said OWIIC. Yes, the QWIIC defaults to an address of 0x18. However, I don't believe 0x18 is a register number. Check the code here: https://github.com/sparkfun/Qwiic_Relay_Py/blob/main/qwiic_relay.py – Tim Roberts May 31 '23 at 05:54
  • As I mentioned, using i2cget/set it's all working. Using register adres 0x18 I can enable and disable flow on device. But problem appears on Pi4J. When I try to read/write data, I'm always get 0, and can't use device again until I restart it (even using i2cget/set). – Son May 31 '23 at 06:25
  • Again, exactly what `i2cset` command did you enter that worked? – Tim Roberts May 31 '23 at 07:08
  • `i2cset -y 1 0x18 1` - enable flow on device – Son May 31 '23 at 07:43
  • What this says is that your device does not use registers, and that agrees with what I read in the datasheet. You are simply sending the one-byte command 1 to device 0x18 on bus 1. I couldn't find documentation to match the module you're using, but there should be a something like a `WriteByte` API that will work. – Tim Roberts May 31 '23 at 17:42
  • Thanks @TimRoberts, it's working :) I can now change status, but still when I try to read value device freeze. Maybe it's something connected with locking logic in LinuxFsI2C... I'm trying to understod how it's working, but it's little complicated :) – Son May 31 '23 at 19:52
  • You'll have to read the datasheet to figure out the sequence, because not all I2C devices use the same options. Like, do you have to issue a "write byte" of 0x05 (which is "read status") and then issue a "read byte", or is it all one sequence? You MIGHT try `ReadRegister` on register 5 to see if that gets you the status. – Tim Roberts May 31 '23 at 22:01

0 Answers0