cancel
Showing results for 
Search instead for 
Did you mean: 

LIS3DH Auxiliary ADC using STM8 is giving constant value

SDhare
Associate

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

  1. What do these values mean?
  2. What could be wrong with my configuration? Am I missing setting up some register? Do I need to follow the read regsiter command with some other command after every operation?

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).

4 REPLIES 4
Federica Bossi
ST Employee

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?

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
SDhare
Associate

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.
_legacyfs_online_stmicro_images_0693W00000bkH6fQAE.png 

Federica Bossi
ST Employee

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?

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Does the input range 1200mV +-400mV mean:

  • The ADC will read 800mV-1600mV and a higher or lower value will be clipped to the max-min.
    • If so, when measuring a regulator's Voltage, ST expects the regulator voltage to be a resistor divided down to centre on 1200mV. It can then monitor a rail when it is powered.

or

  • It will read 0-800mV but some devices will achieve 1600mV.