[Risolto] I2C and ADS1115 communication problem with STM32F103C8T6
[Risolto] I2C and ADS1115 communication problem with STM32F103C8T6
Hello
I would like to read analog inputs with a 16-bit ADS1115 shield with the i2c protocol on pins PB10 and PB11.
First of all, I tried the ADS1115 shield with Arduino Nano, and it works correctly.
I'm using an STM32F103C8T6.
I have tried using the Adafruit ADS1X15 library without success.
I have run the i2c scanner several times on the various i2c ports and the card seems blocked, until I disconnect the SDA and SCL pins, and on the serial monitor I get the message that it has found nothing.
Could anyone help me understand and solve this problem?
I would like to read analog inputs with a 16-bit ADS1115 shield with the i2c protocol on pins PB10 and PB11.
First of all, I tried the ADS1115 shield with Arduino Nano, and it works correctly.
I'm using an STM32F103C8T6.
I have tried using the Adafruit ADS1X15 library without success.
I have run the i2c scanner several times on the various i2c ports and the card seems blocked, until I disconnect the SDA and SCL pins, and on the serial monitor I get the message that it has found nothing.
Could anyone help me understand and solve this problem?
Great!!
Now everything works.
Thank you very much.
This is the working code
However the sketch also works by not omitting

Go to full postNow everything works.
Thank you very much.
This is the working code
Code: Select all
//#include <Wire.h>
#include <Adafruit_ADS1015.h>
//Use IIC2 interface
// Modify the file C: \ ... \Documents\Arduino\hardware\Arduino_STM32\STM32F1\libraries\Wire\Wire.cpp line 106 as follows: TwoWire Wire (2);
TwoWire WIRE(2);
Adafruit_ADS1115 adc;
void setup() {
Serial.begin(115200);
// adc.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
adc.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
// adc.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
// adc.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
// adc.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
// adc.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
adc.begin();
}
void loop() {
for (int i = 0; i < 4; i++) {
int val = adc.readADC_SingleEnded(i);
Serial.print(i);
Serial.print(":\t");
Serial.print(val);
Serial.print("\t");
}
Serial.println(" ");
delay(100);
}
Code: Select all
#include <Wire.h>



Last edited by Domenico on Thu Aug 06, 2020 11:04 am, edited 1 time in total.
-
- Posts: 505
- Joined: Fri Dec 27, 2019 4:53 pm
- Location: Munich, Germany
- Contact:
Re: I2C and ADS1115 communication problem with STM32F103C8T6
After several attempts, I managed to get the ADS1115 to work partially.
I use the core maple, and a Chinese STM32F103C8T6 shield.
With the I2C_scanner I see the ADS1115 address only from pins PB6-PB7 and PB10-PB11, while nothing is detected on the pins PB8-PB9.
The schetch I wrote on the base of the library only works well on PB6-PB7 pins.
I enclose screen shoots of what I wrote, so that someone can help me understand and correct what is wrong, remembering that I would like to read ADS1115 on the PB10-PB11 pins.
I use the core maple, and a Chinese STM32F103C8T6 shield.
With the I2C_scanner I see the ADS1115 address only from pins PB6-PB7 and PB10-PB11, while nothing is detected on the pins PB8-PB9.
The schetch I wrote on the base of the library only works well on PB6-PB7 pins.
I enclose screen shoots of what I wrote, so that someone can help me understand and correct what is wrong, remembering that I would like to read ADS1115 on the PB10-PB11 pins.
- Attachments
-
- ADS1115 on I2C.jpg (95.71 KiB) Viewed 12082 times
-
- ADS1115 on I2C2.jpg (75.83 KiB) Viewed 12082 times
-
- I2C2 scanner.jpg (83.74 KiB) Viewed 12082 times
Re: I2C and ADS1115 communication problem with STM32F103C8T6
I saw the library in case the solution to the problem was within my reach ....
-
- Posts: 505
- Joined: Fri Dec 27, 2019 4:53 pm
- Location: Munich, Germany
- Contact:
Re: I2C and ADS1115 communication problem with STM32F103C8T6
HardWire on PB6/7 uses the harware I2C interface.
For SoftWire you can define your own pins.
For SoftWire you can define your own pins.
Re: I2C and ADS1115 communication problem with STM32F103C8T6
I connected the ADS1115 shield to the PB10 and PB11 pins and I did the schetch i2c_scanner_softwire first and then I tried to read the values sent by the ADS1115.
Through the scanner you can see the address of the device as in the case of the hard wire, but when you want to read the values of the chip things do not go in the right direction.
Also this time I attach the screen shots of the tests.
Where can the problem lie?
Through the scanner you can see the address of the device as in the case of the hard wire, but when you want to read the values of the chip things do not go in the right direction.
Also this time I attach the screen shots of the tests.
Where can the problem lie?
- Attachments
-
- I2C PB11 PB10 Software Wire.jpg (71.35 KiB) Viewed 11989 times
-
- ADC1115 with Software Wire.jpg (74.11 KiB) Viewed 11989 times
-
- Posts: 633
- Joined: Thu Dec 19, 2019 1:23 am
Re: I2C and ADS1115 communication problem with STM32F103C8T6
Assuming you are using Roger's version of STM32duino, there is a function to remap the pins:Domenico wrote: Mon Jul 27, 2020 10:04 pm ...
I would like to read analog inputs with a 16-bit ADS1115 shield with the i2c protocol on pins PB10 and PB11
...
Code: Select all
STM32F1/cores/maple/libmaple/i2c_f1.c
static int i2c1_wants_remap(const i2c_dev *dev) {
/* Check if we've got I2C1 configured for SDA/SCL remap on PB9/PB8 */
(dev->scl_pin == 8);
}
void i2c_config_gpios(const i2c_dev *dev) {
if (i2c1_wants_remap(dev)) {
...
http://docs.leaflabs.com/static.leaflab ... i/i2c.html
There are a few caveats to using it that I cannot recall off-hand. The subject comes up from time to time. The obvious solution is to just use the default pin mapping or move to the Official core where there is more support.
-
- Posts: 505
- Joined: Fri Dec 27, 2019 4:53 pm
- Location: Munich, Germany
- Contact:
Re: I2C and ADS1115 communication problem with STM32F103C8T6
The scanner works on I2C2 means that your HW connection is OK.
Which library do you use for the ADS chip?
It is not enough to initialize the interface in setup, you should somehow tell the lib that you are not using the "standard" interface I2C 1, but I2C 2.
Otherwise the lib will continue to communicate over I2C 1 interface, which will obviously fail.
Please post textual information instead of images (they have low resolution).
Which library do you use for the ADS chip?
It is not enough to initialize the interface in setup, you should somehow tell the lib that you are not using the "standard" interface I2C 1, but I2C 2.
Otherwise the lib will continue to communicate over I2C 1 interface, which will obviously fail.
Please post textual information instead of images (they have low resolution).
Re: I2C and ADS1115 communication problem with STM32F103C8T6
The library I use is that of Adafruit:
Adafruit_ADS1X15.
https://github.com/adafruit/Adafruit_ADS1X15
Adafruit_ADS1X15.
https://github.com/adafruit/Adafruit_ADS1X15
Re: I2C and ADS1115 communication problem with STM32F103C8T6
After work, I will try to remap the pins as suggested by mrburnette.