我正在尝试翻译对于M5热帽(使用MLX90640)(在M5Stickc上),该帽子适合我的微popython(1.18)。
在尝试通过I2C读取数据时,发生了奇怪的事情。
创建 i2c
对象并使用帽子附加的范围扫描总线如预期的工作:
>>> from machine import Pin, I2C
>>> i2c = I2C(0, sda=Pin(0), scl=Pin(26), freq=800000)
>>> i2c.scan()
[51]
0x8000
在 mlx90680文档也可以返回我的数据,这似乎是我的
>>> list(i2c.readfrom_mem(0x33, 0x8000, 2))
[0, 8]
>>> list(i2c.readfrom_mem(0x33, 0x8000, 2))
[0, 9]
:位0似乎要切换页面。
但是现在魔术开始了。
当我尝试读取 0x800D
的“控制寄存器”时“ nofollow noreferrer”> adafruit示例(以及所有其他示例),它的行为似乎完全像状态寄存器(带有一个切换的第一位,不应在控制寄存器上发生):
>>> list(i2c.readfrom_mem(0x33, 0x800D, 2))
[0, 9]
>>> list(i2c.readfrom_mem(0x33, 0x800D, 2))
[0, 8]
经过一点点实验和播放之后有了不同的地址和大小,我必须意识到提供的地址 i2c.readfrom_mem()
似乎完全忽略了:
>>> list(i2c.readfrom_mem(0x33, 0x0000, 16))
[0, 9, 0, 191, 121, 159, 0, 0, 32, 97, 0, 4, 3, 32, 3, 224]
>>> list(i2c.readfrom_mem(0x33, 0x1000, 16))
[0, 9, 0, 191, 121, 159, 0, 0, 32, 97, 0, 4, 3, 32, 3, 224]
>>> list(i2c.readfrom_mem(0x33, 0x2400, 16))
[0, 9, 0, 191, 121, 159, 0, 0, 32, 97, 0, 4, 3, 32, 3, 224]
>>> list(i2c.readfrom_mem(0x33, 0x2800, 16))
[0, 8, 0, 191, 121, 159, 0, 0, 32, 97, 0, 4, 3, 32, 3, 224]
我尝试将所有设备打开,然后重新打开所有设备,播放不同的值 addRsize
和时钟速度,并尝试了插座上附加的另一个帽子(以确保I2C在主体中正常工作),但没有任何见解。
由于大多数代码示例(例如 ReadFROM_MEM 实现)我还尝试了一种离散的写入/阅读方法:
>>> i2c.writeto(0x33, bytes([0x80, 0x0D]))
2
>>> list(i2c.readfrom(0x33, 2))
[0, 9]
>>> i2c.writeto(0x33, bytes([0x0D, 0x80])) # try swapped byte order
2
>>> list(i2c.readfrom(0x33, 2))
[0, 9]
具有相同的效果。
我在这里做错了什么?由于我可以从I2C总线中读取数据,因此我想我没有电气性质的问题。
到目前为止,我错过了一些基本的I2C知识吗?
为什么Micropython发出的此设备上的所有I2C 读取
操作似乎无视地址,而其他人的工作正常?
I'm trying to translate an Arduino example project for the M5 Thermal HAT (using MLX90640) (on an M5StickC) which works for me to MicroPython (1.18).
While trying to read data via I2C strange things happen.
Creating the I2C
object and scanning the bus with the HAT attached works as expected:
>>> from machine import Pin, I2C
>>> i2c = I2C(0, sda=Pin(0), scl=Pin(26), freq=800000)
>>> i2c.scan()
[51]
Reading the status register at 0x8000
as described in the MLX90680 documentation also returns data which seems plausible to me:
>>> list(i2c.readfrom_mem(0x33, 0x8000, 2))
[0, 8]
>>> list(i2c.readfrom_mem(0x33, 0x8000, 2))
[0, 9]
Bit 3 indicates available data and bit 0 seems to toggle pages.
But now the magic begins.
As I try to read the "control register" at 0x800D
as demonstrated in an Adafruit example (and all other examples) it seems to behave exactly like the status register (with a toggling first bit, which should not happen on a control register):
>>> list(i2c.readfrom_mem(0x33, 0x800D, 2))
[0, 9]
>>> list(i2c.readfrom_mem(0x33, 0x800D, 2))
[0, 8]
After a bit of experimenting and playing with different addresses and sizes I had to realize that the address provided with I2C.readfrom_mem()
seems to be totally ignored:
>>> list(i2c.readfrom_mem(0x33, 0x0000, 16))
[0, 9, 0, 191, 121, 159, 0, 0, 32, 97, 0, 4, 3, 32, 3, 224]
>>> list(i2c.readfrom_mem(0x33, 0x1000, 16))
[0, 9, 0, 191, 121, 159, 0, 0, 32, 97, 0, 4, 3, 32, 3, 224]
>>> list(i2c.readfrom_mem(0x33, 0x2400, 16))
[0, 9, 0, 191, 121, 159, 0, 0, 32, 97, 0, 4, 3, 32, 3, 224]
>>> list(i2c.readfrom_mem(0x33, 0x2800, 16))
[0, 8, 0, 191, 121, 159, 0, 0, 32, 97, 0, 4, 3, 32, 3, 224]
I tried turning all devices off and on again, played with different values for addrsize
and clock speeds and tried a different HAT attached to the stick (to make sure I2C is working fine in principal) but all with no insights.
Since most code examples (e.g. this or that) demonstrating how to use the MLX90640 sensor via I2C use low level access to I2C (rather than MicroPythons readfrom_mem
implementation) I also tried a discrete write/read approach:
>>> i2c.writeto(0x33, bytes([0x80, 0x0D]))
2
>>> list(i2c.readfrom(0x33, 2))
[0, 9]
>>> i2c.writeto(0x33, bytes([0x0D, 0x80])) # try swapped byte order
2
>>> list(i2c.readfrom(0x33, 2))
[0, 9]
With all the same effect.
What do I do wrong here? Since I can read data from the I2C bus I guess I don't have a problem of electrical nature.. (also the native Arduino example is fully working on the same device).
Is there some basic I2C knowledge I missed until now?
Why do all I2C read
operations on this device issued by MicroPython seem to disregard the address while others are working totally fine?
发布评论
评论(1)
看来您缺少 stop 参数。
nofollow noreferrer“> micropopropython i2c writeto
试试此:
因此,要编写您要编写的数据:
It looks like you are missing the stop parameter.
micropython I2C writeto
Try this:
Accordingly to write data you'd write: