https://toitlang.org/ logo
is it possible to use I2C bus devices with 16-bit ...
# help
k
see => comment in i2c.toit
Copy code
Writes the $bytes to the device at the given $register.

  The $register value must satisfy 0 <= $register < 256.
  This is a convenience method and equivalent to prepending the $register byte to $bytes
    and then calling $(write bytes).
I am trying to use a VL6180X (Proximity and ambient light sensing (ALS) module).
f
It's possible. I'm trying to find a driver that uses 16-bit registers.
Can't find the driver.
f
What were the arguments for this call?
k
Copy code
i2c-read-reg_ i2c address reg size:
  #primitive.i2c.read-reg
may be the reg is meant to be only a byte wide. But the chip uses 16bit register addresses
f
Basically you can't use
read-reg
directly. But as the command explains, you should be able to do
read-address #[your-address] size
Where
#[your-address]
consists of two bytes.
k
Copy code
print "registers_ : $(registers_.read-u8 0x00)"
print "registers_ : $(registers_.read-u8 0x0212)"
2nd call causes the error
f
I think you will need to work directly on the device instead of the registers.
If you do
device := bus.device ...
, then you get an
i2c.Device
back which has the method 'read-address` method.
just means that you don't have the utitility functions
read-uint16
,...
That driver just writes the command and then reads a certain number of bytes. Not sure that would work with your sensor.
But the
read-address
should.
k
Copy code
read-register16 reg bytes -> ByteArray:
    return device_.read-address #[reg>>8, reg] bytes

  write-register16 reg bytes/ByteArray:
    device_.write-address #[reg>>8, reg] bytes
Thank you - it works!