Skip to content

I2C Slave does not work (STM32F103) #2585

@AndKe

Description

@AndKe

Describe the bug
I2C slave does not recieve requests.

To Reproduce

#include <Wire.h>
long lastms;
volatile int x = 0;
volatile int y = 0;

static void receiveEvent(int howMany) {
  x = Wire.read();
}

static void requestEvent() {
  y = 1;
}

void setup() {
  Serial.begin(115200);

  pinMode(PB6, INPUT); //PB6=SCL
  pinMode(PB7, INPUT); //PB7=setSDA
  pinMode(PC13, OUTPUT);

  Wire.setSCL(PB6);
  Wire.setSDA(PB7);
  Wire.begin(11);                // 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);
    //digitalWrite(PC13,!digitalRead(PC13));
    x = 0;
  }
  if (y != 0) {
    Serial.println("V");
    y = 0;
  }
}

Steps to reproduce the behavior:

  1. Run the code om STM32F103Cx
  2. the code expects requests from master to address x0xB / 11d
  3. I see the data requests using a oscolloscope/logic analyzer on PB6/PB7
  4. The software outputs only "-"

Expected behavior
I'd expect it to work like it does on Atmega/atmel controllers - where this code works. see arduino/ArduinoCore-API#241

Than I rebuilt it all using Arduino Core 2.9.0 (current release)
On Core 2.9.0 - the PB6 is at least not pulled low - which is good, but it still does not work.

image

Desktop (please complete the following information):

  • OS: Linux Ubuntu24.10
  • Arduino IDE version: 2.3.3
  • STM32 core version: 2.9.0
  • Tools menu settings if not the default: [e.g. Newlib Standard, No Serial]
  • Upload method: SWD

Board (please complete the following information):

  • Name: Bluepill STM32F103C8
  • Hardware Revision: n/a
  • Extra hardware used if any: -

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions