2023-05-06 11:07 PM
Hi
I am working on a project where we are reading the battery level on the ADC1 of LIS3DH. This value I need to read using STM8L051F3P. I am using SDCC compiler.
I am able to read the WHO_AM_I register. I am also able to set the accelerometer thresholds and detect the interrupt. This means that I2C communication between STM and LIS is working fine.
I have followed the steps to configure ADC1 as given in datasheet:
The user must set the BDU bit (bit 7) to 1 in CTRL_REG4 (23h) -- DONE
The ADC_EN bit (bit 7) to 1 in TEMP_CFG_REG (1Fh) -- DONE
In low-power mode, the ADC resolution is 8-bit. -- OK
Now what's happening is, whenever I read the
OUT_ADC1_L (08h) -- always giving 0x00
OUT_ADC1_H (09h) -- always giving 0x80
I didn't find any relevant codes online on blogs etc. either.
(Because I am using SDCC, I cannot do LIVE debugging in ST Visual Develop, so I am writing the variable values in EEPROM instead.)
Looking forward to your input(s).
2023-05-17 02:00 AM
Hi @SDhare ,
Welcome to ST Community!
It seems that your configuration procedure is correct, but in order to be sure can you share with me the corresponding lines of code?
However, following the conversion procedure the value in the register should be 800mV. Is this a reliable value for you application?
2023-05-17 03:16 AM - edited 2023-11-20 06:14 AM
Hi,
Thanks for your reply. Attaching the C file here, which primarily does the job of initializing the I2C and setting up the registers one by one.
If you follow the sequence, it is done in this order -
WHO_AM_I
CTRL_REG0
TEMP_CFG_REG
CTRL_REG1
CTRL_REG4
CTRL_REG5
INT1_CFG
INT1_THS
SETUP_INT1_DURATION
CTRL_REG6
CTRL_REG3
CLEAR_INT1
All these are being set because I am making use of Accelerometer interrupt also, to detect 'shaking'. ADC can work in parallel with accelerometer right?
In the end of file, there is a function lis3dh_read_adc() which does the job of reading the low byte followed by high byte.
One observation I made here - https://cdn-learn.adafruit.com/downloads/pdf/adafruit-lis3dh-triple-axis-accelerometer-breakout.pdf
Is that input range is 0.9V to 1.8V. As shown in attached image.
What I am supplying is 6V divided by 7 i.e. 850 mV. Maybe that is a root cause.
2023-05-22 05:50 AM
Ciao @SDhare,
Actually in the DS the input range is 1200mV +-400mV, so your power supply (850mV) is within the range. However, if in the file attached it is state that the reading range is 1.8V-0.9V, it could be like this. You can try to read the value using 10-bit resolution and see if something change, or switching the power supply, if you can.
Do you have an example of output data, represented like the picture that you attached in your answer?
2024-09-27 12:28 PM - edited 2024-09-27 12:29 PM
Does the input range 1200mV +-400mV mean:
or