STM32 ADS1115 USAGE
STM32 ADS1115 USAGE

Hello everyone, In this article I will talk about How can we use ADS1115 with STM32 and Cubemx.

Firstly I want to talk about what ADS1115 is and what it does.

ADS1115 is an analog to digital converter (ADC). It is ultra small sized and has I2C communication. It has 4 channels to read analog voltages and transmit these voltage values via I2C communication bus. For more details you can check datasheet of ADS1115.

Now lets start with a cubemx project and configure board for ADS1115 and I2C communication. My processor is STM32F051R8T6 and I have created project with this microprocessor.

STM32 CUBEMX I2C CONFIGURAION
STM32 CUBEMX I2C CONFIGURAION

After creating new cubemx project we need to acticate I2C under Connectivity section. PB7 as SDA and PB6 as SCL pin will be activated. On the left panel in parameter Above image have all my I2C parameter settings. I did not activated NVIC because I will do send and receive. This means I will send data and according to this ADS1115 will send requested datas. So just activate I2C and set parameter like above. Do not activate NVIC and DMA for this process.

If we are ready to start we must generate code now.

First we need to declare necessary variables.

We are gonna use these variables to read voltage values from ADS1115.

Now we need to insert below code block into while section.

As you can see there is a for loop top of code. This for loop looking for 4 values. We are choosing which channel to read in this for loop. 0xC0, 0xD0, 0xE0 and 0xF0 values provided from datasheet. These values are for selecting to channel. Last value of the sended variable is for choosing LSB or MSB. If we want get value as reversed. After specifing the read configurations we need to transmit this variable into I2C data bus and ADS1115 will read this values. After this ADS1115 will answer to our microprocessor. Then receive the answer.

Then multiply the value with voltage conversation constant and get the between 0 – 5 voltage value.

You are ready for reading ADS1115 now. We can make this with all series stm32. If you want to do this STM32F4 processors you are free to do this.

That is all for this post now.

Burak Hamdi TUFAN

LEAVE A REPLY

Please enter your comment!
Please enter your name here