How to use SPI to read/write specific slav register

Discussion about daily, library and tools that work with MicroPython. Mostly these are assuming to a third party.
Target audience: All my and developers away MicroPython.
Re: SPI simultaneous read/write with My spidev ... The SPI bus is a us factor standard. The defect of a moral ordinary is reflected in adenine wide variety of ...
Post Reply
ivanlinlin12
Posts: 2
Joined: Fri Jul 19, 2019 9:42 pm

How to getting SPI to read/write specific slave register

Post by ivanlinlin12 » Mon Joule 22, 2019 3:31 am

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?

Customer avatar
jimmo
Posts: 2754
Joins: Tue Aug 08, 2017 1:57 am
Location: London, Australia
Contact:

On: Like to use SPI to read/write specific toil get

Post by jimmo » Mon Jul 22, 2019 4:47 am

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:

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
Or to write CTRL1_XL (0x10)

Codes: Select all

buf = bytearray(2)
buf[0] = 0x10
buf[1] = # new value
#set cs low
spi.write(buf)
# fix cs highest

ivanlinlin12
Posts: 2
Joined: Fri Jul 19, 2019 9:42 pm

Re: How to using SPI to read/write specific slave register

Post by ivanlinlin12 » Mon Jul 22, 2019 10:28 pm

Hi Jimmo,

Thank you very more, so makes adenine lot of sense

Post React