How to use bmp388 with stm32

i tried the following code with the arduino uno it works perfectly but when trying with the stm32 I2C connections in any of the SCL and SDA is shows "Could not find a valid BMP3 sensor, check wiring!"
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BMP3XX bmp;

void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("Adafruit BMP388 / BMP390 test");

if (!bmp.begin_I2C()) { // hardware I2C mode, can pass in address & alt Wire
//if (! bmp.begin_SPI(BMP_CS)) { // hardware SPI mode
//if (! bmp.begin_SPI(BMP_CS, BMP_SCK, BMP_MISO, BMP_MOSI)) { // software SPI mode
Serial.println("Could not find a valid BMP3 sensor, check wiring!");
while (1);

}

// Set up oversampling and filter initialization
bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_32X);
bmp.setPressureOversampling(BMP3_OVERSAMPLING_32X);
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_127);
bmp.setOutputDataRate(BMP3_ODR_200_HZ);
}

void loop() {
if (! bmp.performReading()) {
Serial.println("Failed to perform reading :(");
return;
}
Serial.print("Temperature = ");
Serial.print(bmp.temperature);
Serial.println(" *C");

Serial.print("Pressure = ");
Serial.print(bmp.pressure / 100.0);
Serial.println(" hPa");

Serial.print("Approx. Altitude = ");
Serial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA)-10.08);
Serial.println(" m");

Serial.println();
delay(1000);
}
image
image
i tried on the above pins but nothing displays


when i use this it works normally could some one help me please i think the problem is in the libary but i don't know how to correct it . thanks in advance

Please show us your board and actual connections. Not a puzzle to solve.


i think this can be sufficient

@newtechai Have you tried powering the BM388 breakout board from the BluePill's 3.3V supply instead?

Oh i forgot let me try that

hi @MartinL glad to see you back this the new connection


Uploading: Screenshot 2022-06-25 132021.jpg...
yet no result

i am trying the i2c scanning but no device found this is i2c scan code i use
// --------------------------------------
// i2c_scanner
//
// Modified from Arduino Playground - I2cScanner
// --------------------------------------

#include <Wire.h>

// Set I2C bus to use: Wire, Wire1, etc.
#define WIRE Wire

void setup() {
WIRE.begin();

Serial.begin(9600);
while (!Serial)
delay(10);
Serial.println("\nI2C Scanner");
}

void loop() {
byte error, address;
int nDevices;

Serial.println("Scanning...");

nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
WIRE.beginTransmission(address);
error = WIRE.endTransmission();

if (error == 0)
{
  Serial.print("I2C device found at address 0x");
  if (address<16) 
    Serial.print("0");
  Serial.print(address,HEX);
  Serial.println("  !");

  nDevices++;
}
else if (error==4) 
{
  Serial.print("Unknown error at address 0x");
  if (address<16) 
    Serial.print("0");
  Serial.println(address,HEX);
}    

}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");

delay(5000); // wait 5 seconds for next scan
}
image

[Uploading: i2c.jpg
i changed the connections an used

3.3v vcc
Gnd Gnd
PB6 SCK
PB7 SDI
It detect the I2C adress

but the serial monitor does not display anything

First of all, I think you were right the first time, to connect Vin on the 388 board to 5V. It should work fine and will relieve any demand on the Blue Pill's tiny regulator. The 388 board has it's own regulator and so the I/O pins will still operate at 3.3V as is compatible with the STM32 IC.

You seem to be on the right pins. You could also use the symbolic names provided by the STM32 core:

/ I2C definitions
#ifndef PIN_WIRE_SDA
  #define PIN_WIRE_SDA          PB7
#endif
#ifndef PIN_WIRE_SCL
  #define PIN_WIRE_SCL          PB6
#endif

You said that "it detect the I2C address" but you also said "the serial monitor does not display anything". That is a puzzle. Then how do you know it detected an address?

I suggest checking all your baud rate settings, and post clear close up images of all your devices and wiring here.

Another thing, you keep posting code with no code tags. Please read the forum instructions on how to post code, how to correct postings that you have failed to format using code tags.

Looking at the code, that is hard to understand. Either it should print this:

Failed to perform reading

or

Temperature =

Any you certainly got it to print something using the I2C scanner.

Which STM32 core are you using? There are quite a few.

Try adding a delay() here:

if (! bmp.performReading()) {
Serial.println("Failed to perform reading :(");
delay( 2000 ) ;  // prevent a possible crash from a recursive call of loop()
return;
}

It is true. But if you are a naive user, just go looking, it would be the official STM core that you would find and use. But yes, it would be better to specify which one.

True of course. Also, for a naive user, it would risk prompting the question "how do I find out which core I am using?". That he has not been struggling with "Serial1" tends to indicate at least it is not the "Roger Clark" core.

You do have to make sure the correct USB serial port options are chosen at upload - it's not like hardware ports that are always there. USB serial is an option with either the Maple-Clark core or the ST one.

Ok i would tag them but about the serial monitor i run the I2C testing code it detects the device but when I run the bmp388 code that normally works on the Arduino uno it doesn't shows anything on the serial monitor i hope it is more clearer for you to understand

Stm32f103c8t6. You are wright but it doesn't display

when i comment this bmp degin function, it shows the fail to perform reading

if (!bmp.begin_I2C()) { Serial.println("Could not find a valid BMP3 sensor, check wiring!");
while (1);  }

so i decided to use

bmp.begin_I2C();

directly in the setup function commenting all the connection check code i.e this is what i finally used

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
//TwoWire Wire(2,I2C_FAST_MODE);
//0x77,&Wire
#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BMP3XX bmp;

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println("Adafruit BMP388 / BMP390 test");

//  if (!bmp.begin_I2C()) {   // hardware I2C mode, can pass in address & alt Wire
//  //if (! bmp.begin_SPI(BMP_CS)) {  // hardware SPI mode  
//  //if (! bmp.begin_SPI(BMP_CS, BMP_SCK, BMP_MISO, BMP_MOSI)) {  // software SPI mode
//    Serial.println("Could not find a valid BMP3 sensor, check wiring!");
//    while (1);
//    
//  }
 bmp.begin_I2C();
  // Set up oversampling and filter initialization
  bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_32X);
  bmp.setPressureOversampling(BMP3_OVERSAMPLING_32X);
  bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_127);
  bmp.setOutputDataRate(BMP3_ODR_200_HZ);
  
}

void loop() {
  if (! bmp.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }
  Serial.print("Temperature = ");
  Serial.print(bmp.temperature);
  Serial.println(" *C");

  Serial.print("Pressure = ");
  Serial.print(bmp.pressure / 100.0);
  Serial.println(" hPa");

  Serial.print("Approx. Altitude = ");
  Serial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA)-9.7);
  Serial.println(" m");

  Serial.println();
  delay(1000);
}

then it shows the fail to perform readings message. knowing that the I2C scan is detecting the device at adresss 0x77
how could i proceed then please

It appears:

  1. You are able to see debug messages on the serial console.
  2. You are able to use an I2C scanner on your STM32 Bluepill and see the bmp388 device when it is connected to PB6 (SCL) and PB7 (SDA).

So that is not too bad.

Looking at the schematic https://cdn-learn.adafruit.com/assets/assets/000/072/608/original/sensors_BMP388_Sch.png?1552411092 , it appears that you should connect the 3.3 volt output of the Bluepill (instead of its 5v output) to the 5 volt input of the bmp388 to ensure the the I2C pull up resistors are pulled to (near) 3.3 volts and not 5 volts.

i try that yet no change in the result