General discussions and questions abound development of code
with
MicroPython that is not hardware specific.
Target audience: MicroPython Users.
I am wanting to write and read from a encoder counter IC LS7366R using SPI. After not being able to get it to work in MicroPython I hooked it up to my Raspberry Pi and wrote a short program and it worked fine in RPi version of python so it seems that my MicroPython program is the problem.
For me to read the 4 byte counter I have to write a command byte (to tell it to read the 4 bytes) then read back 4 bytes.
In python on the RPi I used this code
RPi python returned correct data then I had to shift the bytes in to an integer but MicroPython always returned b'\xff\xff\xff\xff'
What am I doing wrong??
Comparing the different scripts, You might have to use SPI.write_readinto(), like:
Thanks for your suggestion
I tried it and got the same result. It is just a quick cut in Python to write some zeros to pulse the clock line as as it reads and writes at the same time in RPi Python. In the data sheet for the LS7366R it says the chip ignores the MOSI input while writing to MISO, it just needs the clock line to pulse.
Here's my Micropython code and u can see where I have copmment out a few other things that I tried, all had same result. I think that maybe I am using the SPI wrongly??
cmd = bytearray((0x64, 0, 0, 0, 0))
res= bytearray(5)
spi.write_readinto(cmd, res)
Thanks for this info! One important thing I just learned. If you have just one byte in the byte array, then this gets used as the length.