jsimmonds2
Circuits.I2C :: reading sequentially addressed registers?
Using popular Pressure, Temperature sensor LPS25H and Circuits.I2C
Seems I either don’t understand the Circuits.I2C API or don’t understand the I2C sensor device ![]()
My code has to do single-byte register transfers rather than reading 3 sequentially addressed registers to get the latest Pressure value : e.g. for device at bus address 0x5d and the LSByte of the Pressure value in Register 0x28 this is what I see :
Read each byte value seperately
iex(fb2@fb2-e53f.local)24> Circuits.I2C.write_read ph_ref, 0x5d, <<0x28>>, 1
{:ok, <<241>>}
iex(fb2@fb2-e53f.local)25> Circuits.I2C.write_read ph_ref, 0x5d, <<0x29>>, 1
{:ok, <<190>>}
iex(fb2@fb2-e53f.local)26> Circuits.I2C.write_read ph_ref, 0x5d, <<0x2a>>, 1
{:ok, "?"}
Try reading the 3 registers in one go
iex(fb2@fb2-e53f.local)28> Circuits.I2C.write_read ph_ref, 0x5d, <<0x28>>, 3
{:ok, <<241, 241, 241>>}
iex(fb2@fb2-e53f.local)29>
Thanks !
Marked As Solved
fhunleth
Normally what you’re doing would work since I2C devices usually auto-increment the destination register on multi-byte reads. It looks like the LPS25H does something special, though. Take a look at section 5.2.1 of the datasheet. It looks like if you set the high bit of the register that you’re interested in, it will auto-increment, so try this:
iex> Circuits.I2C.write_read ph_ref, 0x5d, <<0xa8>>, 3
Also Liked
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








