cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Debugging with Platformio

LucaBresciani
Associate II

Hi everyone: i received in these days a custom PCB i designed based on the STM32F411 microcontroller:

I wanted to experiment with such MCUs and make a custom board with them for the first time; i was also interested in making it compatible with the arduino framework through PlatformIO as i am already experienced with that environment.

I started running some tests and i turned out that i was able to program it in DFU mode and to use the serial monitor just fine; however the problems started when i tryed to use I2C sensors like this BME280 Breackout board i got from Amazon: i started simple by connecting it up to 3V3, same GND ans the STM32 board, and SDA and SCL according to the attached PCB schematic.

I also used this code in the platformio's main.c file:

#include <Arduino.h>
#include <Wire.h>

int nDevices = 0;

void setup() {
  Wire.begin(PB7, PB6);
  Serial.begin(115200);
  delay(100);
  pinMode(PC13, OUTPUT);
  Serial.println("I2C pronto!");

  // Scan I2C
  byte error, address;
  for (address = 1; address < 127; address++) {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    if (error == 0) {
      Serial.print("Device found on 0x");
      Serial.println(address, HEX);
      nDevices++;
    }
    delay(5);  // Add small delay between attempts
  }
}

void loop() {
  if(nDevices != 0){
    digitalWrite(PC13, !digitalRead(PC13));
    delay(1000);
  } else {
    Serial.println("No I2C Device Found");
    delay(1000);
  }
}

and this in the platformio.ini file:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:genericSTM32F411CE]
platform = ststm32
board = genericSTM32F411CE
framework = arduino
upload_protocol = dfu
build_flags =
    -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
    -D USBCON
    -D HSE_VALUE=8000000

When the code runs it basically doesn't find any I2C devices connected.

 

Since this is my first time working with STM32 it's i made some mistake for sure, but i can't spot it.

Any help would be apreciated. 

12 REPLIES 12
LucaBresciani
Associate II

Unfortunately i don't have access to an oscilloscope right now and getting one sounds like a big investment right now. Do you kwno any cheaper models (under 150 bucks) on amazon that i can get for a few weeks and then refound after?

You might get used oscilloscope for relatively cheap.

But what I especially meant were logic analysers. Starting with a simple 8-channel DIN device like this: https://sigrok.org/wiki/MCU123_Saleae_Logic_clone

You can get similiar (compatible) devices from all sorts of electronics distributors, including Amazon, for 10 to 20€, or even less.
This site ( https://sigrok.org/wiki/Main_Page ) provides free PC based software as well.
I'm using it with Sigrok/Pulseview under Linux.
As a bonus, this software comes with protocol decoders for all the standard stuff, including RS232, SPI, and I2C.


@Ozone wrote:

But what I especially meant were logic analysers.


But it's important to also be able to see the "analogue" domain.

I'm sure there must be low-cost devices available...

 

Here's a Raspberry Pi shield:

https://cpc.farnell.com/whadda/wpsh206/oscilloscope-board-raspberry-pi/dp/SC19412

It only goes up to ~100kHz, but that should be OK for slow I2C.

 

A USB pen-like "oscilloscoe" for £32:

https://thedebugstore.com/products/penscopedaq-usb-oscilloscope-rk-system-uk

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.