U8g2lib problems on STM core?

The official STMicroelectronics Arduino core
Post Reply
jeffs555
Posts: 12
Joined: Tue Mar 12, 2019 3:42 pm
Answers: 1

U8g2lib problems on STM core?

Post by jeffs555 » Wed Apr 03, 2019 4:07 am

I have used U8g2lib with an I2C OLED display on several Arduino projects. Now trying the same on a Blue Pill but having problems with STM core.

Trying just a simple "Hello World" to the display. It compiles and works on the Maple based cores. It compiles, but doesn't work on the STM core.

U8g2lib implements its own software I2C using just Arduino pinMode, digitalRead, digitalWrite, and delay functions, so should work on any Arduino compatible core. With the STM core, looking at the I2C pins with a logic analyzer, SCL and SDA appear close to correct. However, there are glitches on both the clock and data that seem to be keeping the display from working.

Anyone have any ideas?

Here is the simple "Hello World" code.

Code: Select all

#include <Arduino.h>
#include <U8g2lib.h>

U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ PB8, /* data=*/ PB9, /* reset=*/ U8X8_PIN_NONE);
 
void setup(void) {
    u8g2.begin(); 
    }
void loop(void) {
    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_9x15_tr);
    u8g2.drawStr(0,15,"Hello World");
    u8g2.sendBuffer();
    delay(1000);
}

User avatar
BennehBoy
Posts: 67
Joined: Tue Mar 05, 2019 7:43 pm
Location: Yorkshire
OS: Windows 10
IDE: 1.8.9, Sloeber
Core: Roger's & STM
Board: Blue/Blackpill, MM, HYTiny, Black407Z/VET6, DiyMroe, FK407M1
Contact:

Re: U8g2lib problems on STM core?

Post by BennehBoy » Wed Apr 03, 2019 6:54 am

Have you tried alternate pins to PB8/PB9 ?
-Ben

Noar
Posts: 4
Joined: Thu Mar 28, 2019 7:33 pm
OS: Windows 10
IDE: PlatformIO
Core: STM officiel
Board: Bluepill

Re: U8g2lib problems on STM core?

Post by Noar » Wed Apr 03, 2019 10:48 am

Hi,

Here is how I use the U8G2 lib,
I connect my LCD on PB6/PB7 (SPI1 if I remember correctly)

Declaration :

Code: Select all

// I2C LCD on first hardware SPI (PB6/PB7)
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE);
Setup:

Code: Select all

void setup()
{
  // put your setup code here, to run once:
  u8g2.begin();
}
Loop:

Code: Select all

  u8g2.firstPage();
  do
  {
      u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f);
      u8g2.setCursor(0, 24);
      u8g2.print(10);
      u8g2.drawStr(0, 32, "Hello");
   } while (u8g2.nextPage());
When you use the full buffer ( the **_F_** in the following declaration)

Code: Select all

U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ PB8, /* data=*/ PB9, /* reset=*/ U8X8_PIN_NONE);
You need to use the loop construction :

Code: Select all

  u8g2.firstPage();
  do
  {
    u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f); // Give a 7x2 display
 u8g2.drawStr(0, 32, "Hello");
      }
    }
  } while (u8g2.nextPage());

Beware of coordinates as the origin point of texts etc is bottom left, you can "print" outside of the display.
Hope it helps, tell me if you need more infos

EDIT:
Just realized that your code is working on MBED so maybe I'm totally wrong :lol: but when I started with the lib, I had the same issue, until I found that the way you display things on LCD differs as you use different constructors (1 page, 2 pages, Full buffer).

I can confirm that this work on BluePill with STMCore (with Arduino and PlatformIO) and a cheap SSD1306 128*64 display

No@R

jeffs555
Posts: 12
Joined: Tue Mar 12, 2019 3:42 pm
Answers: 1

Re: U8g2lib problems on STM core?

Post by jeffs555 » Wed Apr 03, 2019 2:36 pm

I have tried a lot of different pins with the software I2C. It works on Roger's maple based core on any pins I want, but won't work on any pins on the official STM core. On the STM core the signals look close to correct, but there are glitches in many of the clock signals that upset the I2C decoding.
STM core with glitches
U8g2 STM core.jpg
U8g2 STM core.jpg (52.14 KiB) Viewed 865 times
Maple core working
U8g2 Maple core.jpg
U8g2 Maple core.jpg (52.56 KiB) Viewed 865 times

User avatar
BennehBoy
Posts: 67
Joined: Tue Mar 05, 2019 7:43 pm
Location: Yorkshire
OS: Windows 10
IDE: 1.8.9, Sloeber
Core: Roger's & STM
Board: Blue/Blackpill, MM, HYTiny, Black407Z/VET6, DiyMroe, FK407M1
Contact:

Re: U8g2lib problems on STM core?

Post by BennehBoy » Wed Apr 03, 2019 7:21 pm

If I had an i2c display I'd give it a try, I've got 30 SPI SSD1306's here as I prefer the speed of them.
-Ben

jeffs555
Posts: 12
Joined: Tue Mar 12, 2019 3:42 pm
Answers: 1

Re: U8g2lib problems on STM core?

Post by jeffs555 » Thu Apr 04, 2019 2:36 pm

I have managed to make U8g2 work in software I2C mode on the STM32 core by modifying some of the STM32 core files.

I commented out the pinmode value INPUT_PULLUP in the STM32 core files "wiring_digital.c" and "wiring_constants.h". U8g2 checks if INPUT_PULLUP is defined, and if it is, the pinmode switches between OUTPUT and INPUT_PULLUP modes during each clock pulse. Something in that switching modes is causing a glitch on the clock line. If INPUT_PULLUP is not defined, then the clock pin stays in OUTPUT mode and the glitches disappear. Rogers Maple based core does not appear to have an INPUT_PULLUP mode.

Not sure if the problem that is causing the glitch when switching between INPUT_PULLUP and OUTPUT modes is in the STM32 core or in the U8g2 code. When I get some more time, I will trace it down, but for now it is working for me.

stevestrong
Posts: 60
Joined: Tue Mar 05, 2019 7:49 am
Location: Munich
OS: Win7 & 10
IDE: Arduino 1.8.8, Sloeber
Core: Libmaple
Board: Bluepill, Generic F4VET6 black & mini
Contact:

Re: U8g2lib problems on STM core?

Post by stevestrong » Thu Apr 04, 2019 2:47 pm

jeffs555 wrote:
Thu Apr 04, 2019 2:36 pm
Rogers Maple based core does not appear to have an INPUT_PULLUP mode.
Of course it has it and many more, too, see https://github.com/rogerclarkmelbourne/ ... .h#L42-L97

jeffs555
Posts: 12
Joined: Tue Mar 12, 2019 3:42 pm
Answers: 1

Re: U8g2lib problems on STM core?

Post by jeffs555 » Thu Apr 04, 2019 3:44 pm

Thanks for correcting me about the pinmodes in Rogers core.

I was only going by looking at differences in the assembly listings when compiling U8g2 for software I2C on Rogers core and STM core. U8g2 doesn't use INPUT_PULLUP on Rogers core, but does on the STM core. Just looked and the difference is because Rogers core defines INPUT_PULLUP inside a typedef, whereas the STM core uses "#define INPUT_PULLUP 0x2". Since U8g2 does a "#ifdef INPUT_PULLUP" it doesn't realize that Rogers core supports INPUT_PULLUP and only uses OUTPUT mode for the clock signal.

jeffs555
Posts: 12
Joined: Tue Mar 12, 2019 3:42 pm
Answers: 1

Re: U8g2lib problems on STM core?

Post by jeffs555 » Thu Apr 04, 2019 8:00 pm

Have it working fine now by modifying U8x8lib.cpp in the U8g2lib src directory. Here is the file if anyone else is having the same problem. Just unzip it into the U8g2lib src directory.
U8x8lib.zip
(6.78 KiB) Downloaded 30 times

Post Reply