tomtor / ulp-i2c

Esp32 ULP I2C code and bmp180 example
GNU Lesser General Public License v3.0
99 stars 18 forks source link

read16 has bytes swapped? #3

Closed xlfe closed 3 years ago

xlfe commented 6 years ago

I used your code to read from a bmp280, but I kept getting strange values - I traced it back to the read16 function - it looks like the bytes were being read in reverse order?

https://github.com/xlfe/ulp-i2c/commit/98e453dff33230174d68896905815564586f92f9#diff-1123c8cab49efa03f9998c97c9d6c2d0

tomtor commented 6 years ago

It was quite some time ago I wrote that code. I cannot remember exactly how I tested it, so thanks for your feedback. I will probably have a look at it, at a later time, because I am currently busy with other projects.

xlfe commented 6 years ago

@tomtor of course - just happy having logged an issue to help anyone having similar problems. Thanks for your initial code - it helped a lot getting the esp32 to do what I wanted!

DominicD commented 3 years ago

@xlfe I want to read data from a bme280. Is your code open source? Or any chance I could get the relevant parts?

Edit: Just found your repository. Thanks for both of your work!

xlfe commented 3 years ago

Hi yes it's here https://github.com/xlfe/ulp-i2c

On Fri, 22 Jan 2021, 10:20 pm DominicD, notifications@github.com wrote:

@xlfe https://github.com/xlfe I want to read data from a bme280. Is your code open source? Or any chance I could get the relevant parts?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tomtor/ulp-i2c/issues/3#issuecomment-765333425, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI7RO7CZDEUWPEWFNYHYATS3FNOJANCNFSM4FMUBBFA .

HareshPrajapati commented 3 years ago

is that any working example for bme280 using spi-ulp

HareshPrajapati commented 3 years ago

Hi yes it's here https://github.com/xlfe/ulp-i2c On Fri, 22 Jan 2021, 10:20 pm DominicD, @.***> wrote: @xlfe https://github.com/xlfe I want to read data from a bme280. Is your code open source? Or any chance I could get the relevant parts? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#3 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI7RO7CZDEUWPEWFNYHYATS3FNOJANCNFSM4FMUBBFA . is that any working example for bme280 using spi-ulp

tomtor commented 3 years ago

I used your code to read from a bmp280, but I kept getting strange values - I traced it back to the read16 function - it looks like the bytes were being read in reverse order?

Hi @xlfe

It has taken a long time, but I dusted off this project and running the current code for BMP180 and it prints the correct pressure and temperature.

When I compare

https://github.com/adafruit/Adafruit-BMP085-Library/blob/cd9a26bc77c1fdbd261fb392a50065d249a4fb98/Adafruit_BMP085.cpp#L128-L132

and

https://github.com/tomtor/ulp-i2c/blob/6c7996d8f6d2a5969b49b7485da60e3317c5759b/main/ulp_example_main.c#L98

the code looks identical, so my read16() is producing a similar result as the Arduino read16.

Correct byte order is always a tricky issue, but compatibility with existing Arduino code is nice, so I don't think the bytes are reversed. You are also the only one reporting this issue.

If you don't agree or have other suggestions, please let me know, because I might be missing something.

tomtor commented 3 years ago

No recent activity, code verified to run correctly.

tomtor commented 3 years ago

Did some more research, I2C 16 bit transfers are most significant byte first, which is implemented in read16 and write16.