guild icon
Toit
#is it possible to use I2C bus devices with 16-bit register addresses ?
Thread channel in help
kaxori
kaxori 09/23/2024 02:14 PM
see => comment in i2c.toit
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).
kaxori
kaxori 09/23/2024 02:25 PM
I am trying to use a VL6180X (Proximity and ambient light sensing (ALS) module).
floitsch
floitsch 09/23/2024 02:26 PM
It's possible. I'm trying to find a driver that uses 16-bit registers.
floitsch
floitsch 09/23/2024 02:28 PM
Can't find the driver.
kaxori
kaxori 09/23/2024 02:28 PM
floitsch
floitsch 09/23/2024 02:30 PM
What were the arguments for this call?
kaxori
kaxori 09/23/2024 02:32 PM
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
floitsch
floitsch 09/23/2024 02:33 PM
Basically you can't use read-reg directly. But as the command explains, you should be able to do read-address #[your-address] size
floitsch
floitsch 09/23/2024 02:33 PM
Where #[your-address] consists of two bytes.
floitschfloitsch
What were the arguments for this call?
kaxori
kaxori 09/23/2024 02:33 PM
print "registers_ : $(registers_.read-u8 0x00)" print "registers_ : $(registers_.read-u8 0x0212)"
kaxoriOPkaxori
print "registers_ : $(registers_.read-u8 0x00)" print "registers_ : $(registers_.read-u8 0x0212)"
kaxori
kaxori 09/23/2024 02:34 PM
2nd call causes the error
floitsch
floitsch 09/23/2024 02:34 PM
I think you will need to work directly on the device instead of the registers.
floitsch
floitsch 09/23/2024 02:36 PM
If you do device := bus.device ..., then you get an i2c.Device back which has the method 'read-address` method.
floitsch
floitsch 09/23/2024 02:36 PM
just means that you don't have the utitility functions read-uint16 ,...
floitsch
floitsch 09/23/2024 02:37 PM
Contribute to jacobqvist/scd30 development by creating an account on GitHub.
floitsch
floitsch 09/23/2024 02:38 PM
That driver just writes the command and then reads a certain number of bytes.
Not sure that would work with your sensor.
floitsch
floitsch 09/23/2024 02:38 PM
But the read-address should.
kaxori
kaxori 09/23/2024 03:38 PM
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!
๐Ÿ‘1
20 messages in total