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

I2C LIS3DH Sample Temperature #423

Open
agatha2 opened this issue Sep 30, 2023 · 1 comment
Open

I2C LIS3DH Sample Temperature #423

agatha2 opened this issue Sep 30, 2023 · 1 comment

Comments

@agatha2
Copy link

agatha2 commented Sep 30, 2023

Concerning the I2C LIS3DH sample, the way the incidental temperature sensor is handled doesn't seem correct.

On line 50, you're configuring with the query address TEMP_CFG_REG. However, it looks like that address (0xC0) was copy-pasted from the value you're giving it, also 0xC0. According to the datasheet (pg. 31), this is not a valid register[1]. That is quite bad, actually—the datasheet repeatedly warns against writing read-only or reserved registers, citing permanent hardware damage.

Assuming I'm right about all this (I don't yet have the hardware myself), the solution is simple: change the definition of TEMP_CFG_REG to 0x1f, its actual address. [2]


[1] It may have alternately come from confusion with register OUT_ADC3_L at address 0x0C, which is used (along with 0x0D for >8-bit modes) for reading out the temperature (it's used for that purpose correctly below).

[2] Incidentally, while we're looking at the sample, I'd like some more documentation about it too. For example, I assume the scaling by 64 in lis3dh_calc_value(⋯) corrects for the chip's left-aligned data-output (16-bit -> 10-bit). The sensitivity must be found by realizing that the -2 to +2 default gee range is 4 gees over 10-bit (1024 code points), so 0.00390625 ≈ 0.004 gees/codepoint. These calculations are only valid for certain configurations, and they're wholly mysterious without diving into the datasheet.

@lurch
Copy link
Contributor

lurch commented Oct 1, 2023

See #171 - this was an example written two years by an intern, and it's possible that the necessary hardware has been lost misplaced in the meantime. But if (when) you have working hardware and are able to verify the changes/improvements you're suggesting, a PR would be useful 👍

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

2 participants