jsimmonds2

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 :expressionless:

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

fhunleth

Co-author of Nerves

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

jsimmonds2

jsimmonds2

@fhunleth, thanks for being my helpful eyes once again . . works as desired now.

      {:ok, <<pressure::size(24)-little>>} = I2C.write_read state.lps25hb_ref, state.lps25hb_i2c_addr, <<0xa8>>, 3

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement