I have a custom board with stm32L072rbt6 and BME280. BME SCL is connected to PB6 (58) and SDA to PB7 (59) on the stm32l0. I am able to read the values from sensor in STM32CubeIDE but now I am trying to get things working with Arduino on PlatformIO.
I used Piconomix PX-HER0 as base since it has same cpu but created custom board setup based on that. I am able to upload code and debug breakpoints but the measurement values are always 0. I can see counter increasing though.
Does anyone know what am I missing here? BME has address 0x76 with SCL & SDA connected to 10k pull-up resistors. I have no leds or serial port on this custom designed board. Only SWD
You also didn’t post your custom board definition, myboard.json. Without that I can’t verify what STM32Duino board variant you’re using, which in turn influences the standard I2C pins it will use.
in that file to make sure it’s correctly taking that exact file, hence it should not compile? Cause it shouldn’t even look at that file when you don’t reference it like
I am not 100% sure how should this work but I am using this code
#include <Wire.h>
void setup()
{
Wire.begin(); // Join I2C bus
Serial.begin(9600); // Start serial communication at 9600 baud rate
while (!Serial)
; // Wait for serial port to connect - necessary for STM32
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices = 0;
Serial.println("Scanning...");
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 the next scan
}
with the breakpoint on Serial.print("I2C device found at address 0x");
but program never stops on the breakpoint. Instead when manually paused it points to following block
int HardwareSerial::availableForWrite(void)
{
tx_buffer_index_t head = _serial.tx_head;
tx_buffer_index_t tail = _serial.tx_tail; <---- HERE
if (head >= tail) {
return SERIAL_TX_BUFFER_SIZE - 1 - head + tail;
}
return tail - head - 1;
}
with output:
Program
received signal SIGINT, Interrupt.
HardwareSerial::availableForWrite (this=0x20000738 ) at C:\Users\me.platformio\packages\framework-arduinoststm32\cores\arduino\HardwareSerial.cpp:482
482 tx_buffer_index_t tail = _serial.tx_tail;
i2c is a null pointer still. Are you inspecting the Wire object after you’ve called “begin” on it? Otherwise it won’t be validly initialized at all.
Then step into the Wire.begin() call and look for suspicious things, like returning from the function early because there’s an error in the pinmap or HAL function or whatever.
Did you touch the PeripheralPins.c too? It may e.g. not have that compiled on to know how to map PB7 to the I2C1 peripheral, etc.