Hi everyone,
I use pyboard to read an I2C device, I only connect one device, but can scan to a lot of.
My I2C device is MCX514
Here my code on the REPL
[code]
MicroPython v1.9.3 on 2017-11-01; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>>from machine import Pin, I2C
>>>i2c = I2C(scl=Pin('Y9'), sda=Pin('Y10'), freq=400000)
>>>i2c.scan()
[112, 113, 114, 115, 116, 117, 118, 119]
>>>i2c.readfrom_mem(112, 0x02, 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 19] ENODEV
[/code]
I2C can not read
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: I2C can not read
I think you need to use i2c.readfrom, i2c.writeto, and i2c.readfrom_into. The readfrom_mem function is primarily for memory devices like EEPROM's. You need to compute the register address from the device address (which from the scan seems to be 0x70) + the register offset (in range 0-0xf).
I'm not sure why the scan doesn't show all 16 registers: I suspect the reason is buried somewhere in the 285 page datasheet which I confess I haven't read
I'm not sure why the scan doesn't show all 16 registers: I suspect the reason is buried somewhere in the 285 page datasheet which I confess I haven't read
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.