This is an attempt to debug much bigger program:
I recently moved it to STM32, and ran into this issue:
The program never sees any packet addressed to it (address 0xB / d11)
I DO see and decode packets incoming on the I2C bus (from the master), using a scope connected to SCL1/PB6/22 and SDA1/PB7/23 .
I do NOT get to see them in the serial monitor.
#include <Arduino.h>
#include <Wire.h>
long lastms;
volatile int x = 0;
volatile int y = 0;
void receiveEvent(int howMany) {
x = Wire.read();
}
void requestEvent() {
y = 1;
}
void setup() {
Serial.begin(115200);
pinMode(PB6, INPUT);
pinMode(PB7, INPUT);
Wire.setSCL(PB6);
Wire.setSDA(PB7);
Wire.begin(0x0B); // join i2c bus as slave
Wire.onRequest(requestEvent); // register event
Wire.onReceive(receiveEvent); // register event
lastms = millis();
}
void loop() {
if (millis() > lastms + 1000) {
Serial.print("=");
lastms = millis();
}
if (x != 0) {
Serial.print("U:0x");
Serial.println(x, HEX);
x = 0;
}
if (y != 0) {
Serial.println("V");
y = 0;
}
}
platformio.ini
[env] ; common settings
platform = ststm32
board = genericSTM32F103C8
framework = arduino
upload_protocol = stlink
build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBD_VID=0x0483
-D USBD_PID=0x5740
-D USBD_USE_CDC
-D USBCON
-D USB_MANUFACTURER="Unknown"
-D USB_PRODUCT=\"STM32F103C8\"
-D HAL_PCD_MODULE_ENABLED
-D HAL_I2C_MODULE_ENABLED
-D ENABLE_HWSERIAL1
;-Wl,--no-warn-rwx-segments
board_build.upload_method = stlink
monitor_port = /dev/ttyACM0
monitor_speed = 115200
lib_deps =
Wire
[env:for_stlink]
upload_protocol = stlink