I can't solve I2C and SPI

Maple Mini, Maple Rev3, Maple Rev 5 and Maple Ret 6, iTead Maple etc
TasEs
Posts: 5
Joined: Wed Feb 05, 2025 10:21 pm

I can't solve I2C and SPI

Post by TasEs »

Hi!
I have been using the Arduino platform for many years, but this is my first time with STM32. After several days of torment (yes, also with ChatGPT support) I decided to ask for help. I have a STM32F103C8T6 board (identified as MapleMini in PC) and I have tried to use I2C - every time the board stops working correctly. I have localized the root of the problem in a primitive sketch with the Wire.h library. It works correctly until the Wire.begin() command is removed - the Built In LED blinks and HELLO is received on the Serial Monitor. When Wire.begin() is added, the LED blinks, but the Serial Monitor does not receive anything. It seems that similar manifestations were also observed with SPI attempts. The board was uploaded via ST-Link from Arduino IDE v.1.8.13 for testing.
I think that Wire.h changes the pins to Serial output. Maybe I should use another library? Which one? Maybe the pins to Serial can be restored? Which ones and how?

Code: Select all

#include <Wire.h>

TwoWire WIRE1 (PB11, PB10);  //SDA=PB11 & SCL=PB10 or PB9 & PB8 or PB7 & PB6

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
// WIRE1.begin();
}

void loop() {
 digitalWrite(LED_BUILTIN, HIGH);
 delay(500);
 digitalWrite(LED_BUILTIN, LOW);
 delay(500);
 Serial.println("HELLO");
}
Thanks for help.
fpiSTM
Posts: 1944
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: I can't solve I2C and SPI

Post by fpiSTM »

First which core you used ? Maple core or stm32core?

If you used the maple core (Roger's one) do not care about below comments:

So if you used the STM32core, Arduino 1.8.13 is very old.
Don't know which stm32 core version you used but be aware the Arduino 1.x support was dropped.

So which version of the core you used? Which target you select in the menu ?

By default Maple target instantiate a Wire instance with PB7/PB6 (I2C1) pins.
Serial uses PA10/PA9 (USART1) pins.
Anyway, if you have enabled the USB CDC support, Serial is mapped to the SerialUSB.

To use PB11 and PB10 for wire, you can do this to change default pins before Wire.begin():
Wire.setSCL(PB11);
Wire.setSDA(PB10);

Finally, you told about issue with SPI but your code doesn't use it.
ag123
Posts: 1898
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: I can't solve I2C and SPI

Post by ag123 »

well, the 'official' core is
https://github.com/stm32duino/Arduino_Core_STM32
https://github.com/stm32duino/Arduino_Core_STM32/wiki

and the libmaple core is
https://github.com/rogerclarkmelbourne/Arduino_STM32
https://github.com/rogerclarkmelbourne/ ... STM32/wiki

for the 'official' core select USB CDC Serial from the menu as your Serial interface.

use the 'official' core if you may decide to use a 'better' board say at a 'future' time, that one has better support for other STM32 mcus
e.g.
https://www.adafruit.com/product/4382
https://store.micropython.org/product/PYBv1.1
https://www.st.com/en/evaluation-tools/ ... 411re.html
https://github.com/WeActStudio/WeActStu ... iSTM32F4x1
etc.
I'm a fan of the stm32f4xx family, they have ART accelerator (on chip cache), FPU single precision floating point is *very very* fast compared to f103c8, more sram often 32k or more, more flash many boards use chips with 128k or more flash and generally outperform every single io performance, clocks can be tuned to every hz (much better PLL clocks), DMA etc even for the same hz vs the stm32f103. There is very little reason for tinkerers to stick with stm32f103c8 (and possibly clones) as the price difference for a few boards are still affordable with the f4xx family of boards. e.g. even stm32f401cc or f411ce is plenty better than stm32f103c8.

However, libmaple core is leaner and is targetted towards stm32f103c{8,b} specifically and some of the f4xx boards.
usb serial is default for stm32f103c8 'generic' or maple mini board in libmaple core.

you should test serial without i2c e.g.

Code: Select all

void setup() {
	Serial.begin(); // no baud rate needed
	pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
	Serial.println("hello world");
	digitalWrite(LED_BUILTIN, ! digitalRead(LED_BUILTIN));
	delay(500);
}
i2c e.g. Wire has its own set of problems, among which you need to sent to the correct address etc.
And hardware wise, you need to pull up the clk and data lines in i2c connections to 3.3v say with a 1k resistor.
one of those things is to run an address probe on i2c, but proir that, you should provide more details about your setup.

e.g. which core ? 'official' or 'libmaple'
and did you check usb serial as like above?

oh, and stm32f103c8 blue pill has 'clones' and 'fakes'. 'clones' may work, but there has been some reports of wayward behavior of bad clones and fakes.
TasEs
Posts: 5
Joined: Wed Feb 05, 2025 10:21 pm

Re: I can't solve I2C and SPI

Post by TasEs »

Thanks for the interested answer!
I'm sorry, but I have understand a lot of these terminology with ChatGPT help. I apologize for that.
1) What core - from your question I understand that it could be STM32, because the IDE has an STM32 board add-on installed, but when I marked the board Maple Mini, ST-Link is not available. I recognize simpler solutions - I would gladly follow the Maple core recommendation, unfortunately, ChatGPT did not tell me anything about the Maple core.
2) vers. 1.8.19. is the highest, which is suitable for my PC with win.7, but 1.8.13 was recommended to me as the most stable.
3) I have tried soldering the I2C connection to all possible pins, the essence does not change.
4) if I use Wire.setSCL(PB11); and Wire.setSDA(PB10); there is an error message 'class TwoWire' has no member named 'setSCL'
5) encountering problems with the TFT touchscreen (SPI interface), I resorted to a simpler task, where I2C communication ... SPI is left for later ... Actually, I need the STM32 because of the TFT and energy saving.
fpiSTM
Posts: 1944
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: I can't solve I2C and SPI

Post by fpiSTM »

TasEs wrote: Thu Feb 06, 2025 4:06 pm 4) if I use Wire.setSCL(PB11); and Wire.setSDA(PB10); there is an error message 'class TwoWire' has no member named 'setSCL'
So you used the Maple core.
Read this post to understand which cores are available.
TasEs
Posts: 5
Joined: Wed Feb 05, 2025 10:21 pm

Re: I can't solve I2C and SPI

Post by TasEs »

Thanks ag123!
Of course, I first tested the purchased board with the classic Blink sketch modified with Serial.print - it works correctly. Unfortunately, I still have to figure out how to navigate the jungle of library offers, installation and usage. What is what and where to put what ... I used ChatGPT for help.
Thanks for the board recommendations for the future! I really don't feel so old that I don't need them. It's normal to learn from the simplest to the most complex ... sometimes it can turn out the other way around ;)
ag123
Posts: 1898
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: I can't solve I2C and SPI

Post by ag123 »

TasEs wrote: Thu Feb 06, 2025 4:06 pm Thanks for the interested answer!
I'm sorry, but I have understand a lot of these terminology with ChatGPT help. I apologize for that.
1) What core - from your question I understand that it could be STM32, because the IDE has an STM32 board add-on installed, but when I marked the board Maple Mini, ST-Link is not available. I recognize simpler solutions - I would gladly follow the Maple core recommendation, unfortunately, ChatGPT did not tell me anything about the Maple core.
2) vers. 1.8.19. is the highest, which is suitable for my PC with win.7, but 1.8.13 was recommended to me as the most stable.
3) I have tried soldering the I2C connection to all possible pins, the essence does not change.
4) if I use Wire.setSCL(PB11); and Wire.setSDA(PB10); there is an error message 'class TwoWire' has no member named 'setSCL'
5) encountering problems with the TFT touchscreen (SPI interface), I resorted to a simpler task, where I2C communication ... SPI is left for later ... Actually, I need the STM32 because of the TFT and energy saving.
ok for a starter, I'd recommend starting with 'official' core
https://github.com/stm32duino/Arduino_Core_STM32
the wiki is here
https://github.com/stm32duino/Arduino_Core_STM32/wiki
follow instructions there would let you install the core appripriately.

ok, but a few hints up, it is a biased opinion, the 'official' core is 'fat', but *wait*, rather than to call it 'fat', I'd say the core adds a lot of things in the basic configuration that would otherwise not be there, so it conforms more to the official Arduino API.
Next, 'official' core is based around STM32 Cube HAL, this is important as practically a huge portfolio of the stm32 microcontrollers are supported,
just take a look at the board list
https://github.com/stm32duino/Arduino_Core_STM32
the unfortunate fact it it carries quite a bit of 'baggage', but that you can practically switch boards on the board list just selecting it, and there are a *lot* of boards and mcu to choose.

now back to libmaple
https://github.com/rogerclarkmelbourne/Arduino_STM32
^ that could be deemed the 'pioneers', that started with the leaflabs maple (it is called roger's core, for a reason, but the stem is libmaple)
https://www.leaflabs.com/maple
http://static.leaflabs.com/pub/leaflabs ... index.html
that is further developed by the community and is a 'lean and mean' core, it works lean and fast on stm32f103c{8,b}, but it is specific to f103c{8,b} and some f4xx variants, but it may take significant effort to port your codes, or the core, if you decide to switch to newer mcus/boards.

But if you look at some of the newer boards on offer e.g. :
https://weactstudio.aliexpress.com/stor ... items.html
and from Adafruit
https://www.adafruit.com/product/4382
micropython
https://store.micropython.org/product/PYBv1.1
from ST itself
https://www.st.com/en/evaluation-tools/ ... oards.html
Olimex
https://www.olimex.com/Products/ARM/ST/
etc and the huge board list
https://github.com/stm32duino/Arduino_Core_STM32
i'd guess it makes 'more sense' with the 'official' core.

to use the 'official' core, i'd recommend a beefier chip, e.g. stm32f4x1 with more sram and flash
https://github.com/WeActStudio/WeActStu ... iSTM32F4x1
because the 'official' core has a 'bigger footprint' for bundling more things in the basic configs.
it is still lean though as I've build Adafruit ili9341 lcd library on the 'official' core
https://github.com/ag88/Adafruit_ILI9341_SPI_stm32duino
and the binary size comes to about 40k bytes with the Adafruit graphics test + USB Serial compiled.
it is 'effortless' with the newer boards that has more flash and sram, but if using a stm32f103c8 one may find it a little 'squeezy'.

----
now back to the topic about I2C

Assuming that you are using 'libmaple' (e.g. roger's) core.
There is an 'i2c scanner' to scan for peripherals on the i2c bus.
https://github.com/rogerclarkmelbourne/ ... r_wire.ino
a similar I2C scanner is available for the 'official' core
https://github.com/stm32duino/Arduino_C ... canner.ino

I find this a very useful sketch to run for i2c as it'd probe and tell you what address is your i2c peripheral at, that matters as I've seen for myself some SSD1306 LCDs are configured for a different address vs an assumed default. It is also a good test that your I2C setup is after all working.
Last edited by ag123 on Fri Feb 07, 2025 4:19 am, edited 1 time in total.
TasEs
Posts: 5
Joined: Wed Feb 05, 2025 10:21 pm

Re: I can't solve I2C and SPI

Post by TasEs »

Thanks, fpiSTM!
I realized that my board uses Maple core... logically, if the processor declares itself as Maple Mini, but I didn't understand what conclusions I should read.
Thanks, ag123!
I appreciate your suggestion to install Arduino_Core_STM32, but it seems to me that the processor CPU (that is, the "core") is not available for user programming. ... or maybe "core" here means something on flash, or maybe IDE? From .../Arduino_Core_STM32/wiki I understand that this core is on IDE - "core" is a synonime to Arduino IDE addons for hardvare/programm-instruments. This will probably seem funny to you - for my it is a discovery, so now I have to read a lot with a "new understanding". I am right?
GonzoG
Posts: 491
Joined: Wed Jan 15, 2020 11:30 am
Answers: 36
Location: Prudnik, Poland

Re: I can't solve I2C and SPI

Post by GonzoG »

"core" is a arduino addon that supports MCUs.
For STM MCUs there are 3 cores: official STM (made by STM), Maple (LibMaple) (it's old and supports only few MCUs) and Steve's core (formerly Roger's Clark core), it's an extension of Maple core with more features and supports more MCUs.

Maple is just a brand of boards with STM32F103 MCU, that ware made by LeafLabs. And how it identifies on PC depends on drivers installed and firmware.

From what you've wrote, looks like you're using Steve's core but you're trying to use functions from official STM core.

To use official STM core in Arduino IDE 1.8 you'll have to install v2.7 of the core, as newer need IDE 2.0
ag123
Posts: 1898
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: I can't solve I2C and SPI

Post by ag123 »

@TasEs
TasEs wrote: Thu Feb 06, 2025 8:37 pm Thanks, ag123!
I appreciate your suggestion to install Arduino_Core_STM32, but it seems to me that the processor CPU (that is, the "core") is not available for user programming. ... or maybe "core" here means something on flash, or maybe IDE? From .../Arduino_Core_STM32/wiki I understand that this core is on IDE - "core" is a synonime to Arduino IDE addons for hardvare/programm-instruments. This will probably seem funny to you - for my it is a discovery, so now I have to read a lot with a "new understanding". I am right?
To install Arduino_Core_STM32 follow this guide
https://github.com/stm32duino/Arduino_C ... ng-Started

the "core" is the Arduino implementation for a particular MCU
that to the extent offers the Arduino API
https://docs.arduino.cc/learn/programming/reference/
but note that one should refer to the specific docs for the relevant core e.g. for 'official' core
https://github.com/stm32duino/Arduino_C ... 2/wiki/API
because not all functions may be available or different.

"libmaple" core are the 'pioneers' that started with leaflabs and subsequently significantly improved by the (this) community.
But it is targetted to / developed specifically for stm32f103c{8,b} and subsequently the community (actually @stevestrong , added the F4xx implementation)
Arduino_Core_STM32 is the 'official' core, developed based on STM32 Cube HAL and thus supported a large portfolio of stm32 MCUs and boards.
Post Reply

Return to “Maple & Maple mini etc”