Multiple I2C libraries

FiveO
Posts: 27
Joined: Mon Oct 16, 2017 6:41 am

Multiple I2C libraries

Post by FiveO » Wed Dec 13, 2017 10:46 am

Hi,

I am having troubles with multiple I2C libraries in one sketch on stm32f103

Separately they work:

Adafruit SSD1306
Adarfuit VL6180
I2C anything

They work together in Arduino Nano or Mega.

Why is that? How can it be done?
Last edited by FiveO on Wed Dec 13, 2017 6:05 pm, edited 1 time in total.

User avatar
RogerClark
Posts: 7691
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Multiple I2C libaries

Post by RogerClark » Wed Dec 13, 2017 10:51 am

Which core are you using ?

FiveO
Posts: 27
Joined: Mon Oct 16, 2017 6:41 am

Re: Multiple I2C libaries

Post by FiveO » Wed Dec 13, 2017 1:12 pm

Latest Arduino_STM32 Core

Oled starts with Adafruit logo and stays there, nothing after that works.

SSD1306 with VL6180 code here:

Code: Select all

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306_STM32.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

#include "Adafruit_VL6180X.h"
Adafruit_VL6180X vl = Adafruit_VL6180X();

void setup()   {
  Serial.begin(115200);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  
  display.display();
  delay(2000);

  vl.begin();
  Serial.println("Sensor found!");
}


void loop() {
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println(vl.readRange());
  display.display();
}

stevestrong
Posts: 2067
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: Multiple I2C libaries

Post by stevestrong » Wed Dec 13, 2017 1:18 pm

Put some serial output lines to detect which is the line where the sketch hangs.

User avatar
mrburnette
Posts: 2226
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Multiple I2C libaries

Post by mrburnette » Wed Dec 13, 2017 2:42 pm

FiveO wrote:
Wed Dec 13, 2017 10:46 am
Hi, I am having troubles with multiple I2C libraries in one sketch on stm32f103
Separately they work:

Adafruit SSD1306
Adarfuit VL6180
I2C anything

They work together in Arduino Nano or Mega. Why is that? How can it be done?
The STM32duino core IS NOT THE SAME as the official AVR core. As late as last year, the AVR core was still defaulting to I2C software, if my memory serves me correctly. As such, the I2C implementation is "blocking" by implementation.

The LeafLabs' implementation was also software I2C (blocking) even though there is a dedicated I2C peripheral in the STM32F1xx. I had to use Google to get to the next layer, but it seems that the STM32duino F1 core was changed this past summer and the default is now hardware I2C, that is, non-blocking.
Reference: viewtopic.php?t=2408
  • You can therefore configure the most recent core to use I2C software.
  • Or, you can "regress" the code on github to deliver a download image prior to the change.
Sadly, I cannot promise that doing either of the above will make your code work as it does on the 16-bit AVR uC; testing will be your responsibility. We all will be grateful that you do report back in this thread if you are successful or if you are not successful. This forum is not moderated, but a few members often take your (full) code and attempt to ascertain a fix - strictly on a volunteer basis since to test generally requires exactly the same hardware components.

For future reference, please do NOT assume that the STM32F1xx STM32duino core will work the same as the official Arduino core(s) ... some serious effort has gone into migrating the original LeafLabs core to be compatible with the current ArduinoIDE and some serious effort has gone into manipulating the STM32F1xx core to conform to official Arduino compatibility. However, the two cores are very different in the underlying codebase. And, this forum reserves the option to change core functionality to make best usage of the more advance architectural design of the STM32Fxxx devices.


Ray

FiveO
Posts: 27
Joined: Mon Oct 16, 2017 6:41 am

Re: Multiple I2C libaries

Post by FiveO » Thu Dec 14, 2017 9:22 am

stevestrong wrote:
Wed Dec 13, 2017 1:18 pm
Put some serial output lines to detect which is the line where the sketch hangs.
Ok, I did that. It doesn't print thing in setup or loop.

And to mrburnette. Thanks for your answer, coding is kind of new for me and I will try to read that thread.

User avatar
RogerClark
Posts: 7691
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Multiple I2C libraries

Post by RogerClark » Thu Dec 14, 2017 9:54 am

Sounds like the code may be crashing before setup() is called.

This is commonly caused by the constructors in libraries attempting to use GPIO or I2c or SPI etc before its initialised.

stevestrong
Posts: 2067
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: Multiple I2C libraries

Post by stevestrong » Thu Dec 14, 2017 12:25 pm

You can try adding similar check points:

Code: Select all

void setup()   {
  Serial.begin(115200);
  while (!Serial) ; // wait for a serial connection via USB
  delay(1000);

  Serial.println("SSD1306 begin"); // check point
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  
  display.display();
  delay(2000);

  Serial.println("VL begin"); // check point
  vl.begin();
  Serial.println("Sensor found!");
}

FiveO
Posts: 27
Joined: Mon Oct 16, 2017 6:41 am

Re: Multiple I2C libraries

Post by FiveO » Fri Dec 15, 2017 8:40 am

With that While() it now prints only "SSD1306 begin" and "VL begin". Doesn't print "Sensor found!" or any other markers I added to loop.

stevestrong
Posts: 2067
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: Multiple I2C libraries

Post by stevestrong » Fri Dec 15, 2017 10:38 pm

So it seems that it hangs in the VL6180 begin () function.

Where did you get the library? Any link?

Post Reply