Page 1 of 2

[Risolto] I2C and ADS1115 communication problem with STM32F103C8T6

Posted: Mon Jul 27, 2020 10:04 pm
by Domenico
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?

Re: I2C and ADS1115 communication problem with STM32F103C8T6

Posted: Thu Jul 30, 2020 8:19 am
by stevestrong
viewtopic.php?f=2&t=301
Which core do you use?
Have you tried other I2C modules?

Re: I2C and ADS1115 communication problem with STM32F103C8T6

Posted: Thu Jul 30, 2020 5:10 pm
by Domenico
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.

Re: I2C and ADS1115 communication problem with STM32F103C8T6

Posted: Thu Jul 30, 2020 8:14 pm
by Domenico
I saw the library in case the solution to the problem was within my reach ....

Re: I2C and ADS1115 communication problem with STM32F103C8T6

Posted: Sat Aug 01, 2020 10:22 am
by stevestrong
HardWire on PB6/7 uses the harware I2C interface.
For SoftWire you can define your own pins.

Re: I2C and ADS1115 communication problem with STM32F103C8T6

Posted: Sun Aug 02, 2020 8:16 pm
by Domenico
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?

Re: I2C and ADS1115 communication problem with STM32F103C8T6

Posted: Sun Aug 02, 2020 11:30 pm
by mrburnette
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
...
Assuming you are using Roger's version of STM32duino, there is a function to remap the pins:

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)) {
    ...
Roger's version is a rewrite/update from the old LeafLabs code:
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.

Re: I2C and ADS1115 communication problem with STM32F103C8T6

Posted: Mon Aug 03, 2020 8:52 am
by stevestrong
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).

Re: I2C and ADS1115 communication problem with STM32F103C8T6

Posted: Mon Aug 03, 2020 10:40 am
by Domenico
The library I use is that of Adafruit:
Adafruit_ADS1X15.
https://github.com/adafruit/Adafruit_ADS1X15

Re: I2C and ADS1115 communication problem with STM32F103C8T6

Posted: Mon Aug 03, 2020 10:46 am
by Domenico
After work, I will try to remap the pins as suggested by mrburnette.