Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2C Slave does not work (STM32F103) #2585

Open
AndKe opened this issue Dec 1, 2024 · 13 comments
Open

I2C Slave does not work (STM32F103) #2585

AndKe opened this issue Dec 1, 2024 · 13 comments

Comments

@AndKe
Copy link

AndKe commented Dec 1, 2024

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: -
@fpistm
Copy link
Member

fpistm commented Dec 1, 2024

Do you have pullup resistors on each I2c lines?

@AndKe
Copy link
Author

AndKe commented Dec 1, 2024

Yes, and - I can see the I2C packets using an oscilloscope on the pins. (decoded on the scope)
Plus : for simple troubleshooting I hooked it up on a breadboard. When I do the very same setup, but switch the blackpill an Atmega based arduino boards - it works.

@fpistm
Copy link
Member

fpistm commented Dec 1, 2024

Could you share the master example?

@AndKe
Copy link
Author

AndKe commented Dec 1, 2024

@fpistm unable, the master is Ardupilot (which is open source)- if you have some hardware that can run Ardupilot, and configure BATT_MONITOR 5 - then you have that I2C traffic too.

The traffic is really nothing special - it is all about spotting a normal 7-bit address that is being interrogated by a master. I bet this is reproducible with a ny simple Arduino program that tried to read data from a I2C device (just set the address to the same on both ends.)

@AndKe
Copy link
Author

AndKe commented Dec 2, 2024

Please see attached communication capture with device 0xB - the capture should clarify any questions you might have about protocol/timing etc. it is captured using Saleae logic analyzer, which is perfectly multi-platform with nice software: https://www.saleae.com/pages/downloads

BMSEmu Boot.zip

@fpistm
Copy link
Member

fpistm commented Dec 2, 2024

Thanks for inputs. I will try to test on my side but don't know when as I'm fully busy on other tasks.

@AndKe
Copy link
Author

AndKe commented Dec 2, 2024

Thank you, I am really stuck on this one, I "modernized" previous design (Atmega32u4) by dropping in STM32F103, and now - with plenty of new PCB's manufactured, I am stuck with this issue.
I have previously had projects with STM32F103C8 and CB acting as master without any issues.

@AndKe
Copy link
Author

AndKe commented Dec 2, 2024

Additional information; the exactly same happens when SCL=PB10 and SDA=PB11

@AndKe
Copy link
Author

AndKe commented Dec 2, 2024

@fpistm I understand that you are busy, but is there some way to ...motivate... you or another competent contributor here to solve this?

@fpistm
Copy link
Member

fpistm commented Dec 3, 2024

Just a question you said you used a BluePill but you select a blackpill on your screenshot ?

@AndKe
Copy link
Author

AndKe commented Dec 3, 2024

Yes, the blackpill is an error on my side.
The device in question is something that did not work as I2C slave after being ported from Atmega32U4 And all issues here are about STM32F103C8T6. be it on my hardware, or Bluepill.

After much troubleshooting I made this test app above, and ran it on Atmega32u4 for comparsion/to verify it.
Then I also moved from my board to an actual bluepill (just to easily test on PB10/PB11) .
During the compilations for various targets, I must have messed it up.
I will retest that once I get home, in about 2 hours.

BTW: I have also tried to build it on VSCode w/platformio (and Arduino library) - with same results. So me trying both Arduino and all that are kind of desperate attempts to make it work :)

@AndKe
Copy link
Author

AndKe commented Dec 3, 2024

@fpistm corrected, and I can confirm that setting "Bluepill" as target did not change the result.

@ItsXor
Copy link

ItsXor commented Dec 4, 2024

I can confirm this issue exists.
Only input I can give is that Wire Slave sometimes accepts data right after reset, maybe first 300ms.
This issue is not present in other core (https://github.com/rogerclarkmelbourne/Arduino_STM32).
Would love this to be resolved because SimpleFOC only works with this core, but I can't control my Bluepill as I2C slave simultaneously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants