Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read16 has bytes swapped? #3

Closed
xlfe opened this issue Jul 28, 2018 · 9 comments
Closed

read16 has bytes swapped? #3

xlfe opened this issue Jul 28, 2018 · 9 comments

Comments

@xlfe
Copy link

xlfe commented Jul 28, 2018

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?

xlfe@98e453d#diff-1123c8cab49efa03f9998c97c9d6c2d0

@tomtor
Copy link
Owner

tomtor commented Jul 28, 2018

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
Copy link
Author

xlfe commented Jul 29, 2018

@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
Copy link

DominicD commented Jan 22, 2021

@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
Copy link
Author

xlfe commented Jan 22, 2021 via email

@HareshPrajapati
Copy link

is that any working example for bme280 using spi-ulp

@HareshPrajapati
Copy link

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
Copy link
Owner

tomtor commented May 2, 2021

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

int32_t UP= ((((ulp_pressure & 0xFFFF) << 8) | (ulp_pressure2 & 0xFFFF)) >> (8-oversampling));

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 tomtor closed this as completed May 19, 2021
@tomtor
Copy link
Owner

tomtor commented May 19, 2021

No recent activity, code verified to run correctly.

@tomtor
Copy link
Owner

tomtor commented May 19, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants