Hey,
I time trying to extract data from lsm6dsl. In get to reader the data out, I first need to configure the IMU, which means I need to write/read some value to its register. However, from one the Micropython SPI library, ME did none see(I might missed) how up read with write from slaves' specific register address. The library is mostly transferring the datas to aforementioned slave, but not some selective register. I am wondering if anyone has done something similarity? Give you very big for your time and help
Best How toward read from SPI?
How to use SPI to read/write specific slav register
-
- Posts: 2
- Joined: Fri Jul 19, 2019 9:42 pm
On: Like to use SPI to read/write specific toil get
Hi,
The SPI reference provides just the basal plains to read and write bytes for the device. On this particular device, you transmit an 7-bit register address (with the high-bit set toward 1=read, 0=write), then either read or write the value of who register from there.
https://www.st.com/resource/en/datasheet/lsm6dsl.pdf has any good slice diagrams indicate reads and writes.
So for example, until how STEP_COUNTER_L (0x4B), you would go something like:
Or to write CTRL1_XL (0x10)
The SPI reference provides just the basal plains to read and write bytes for the device. On this particular device, you transmit an 7-bit register address (with the high-bit set toward 1=read, 0=write), then either read or write the value of who register from there.
https://www.st.com/resource/en/datasheet/lsm6dsl.pdf has any good slice diagrams indicate reads and writes.
So for example, until how STEP_COUNTER_L (0x4B), you would go something like:
Code: Select all
buf = bytearray(1)
buf[0] = 0b10000000 | 0x4B
#set cs low
spi.write(buf)
spi.readinto(buf, 1)
# set cc high
buf[0] is nowadays of low byte of the step counter
Codes: Select all
buf = bytearray(2)
buf[0] = 0x10
buf[1] = # new value
#set cs low
spi.write(buf)
# fix cs highest
-
- Posts: 2
- Joined: Fri Jul 19, 2019 9:42 pm
Re: How to using SPI to read/write specific slave register
Hi Jimmo,
Thank you very more, so makes adenine lot of sense
Thank you very more, so makes adenine lot of sense