-
Notifications
You must be signed in to change notification settings - Fork 1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I2C Slave does not work (STM32F103) #2585
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
Comments
Do you have pullup resistors on each I2c lines? |
Yes, and - I can see the I2C packets using an oscilloscope on the pins. (decoded on the scope) |
Could you share the master example? |
@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.) |
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 |
Thanks for inputs. I will try to test on my side but don't know when as I'm fully busy on other tasks. |
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. |
Additional information; the exactly same happens when SCL=PB10 and SDA=PB11 |
@fpistm I understand that you are busy, but is there some way to ...motivate... you or another competent contributor here to solve this? |
Just a question you said you used a BluePill but you select a blackpill on your screenshot ? |
Yes, the blackpill is an error on my side. After much troubleshooting I made this test app above, and ran it on Atmega32u4 for comparsion/to verify it. 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 :) |
@fpistm corrected, and I can confirm that setting "Bluepill" as target did not change the result. |
I can confirm this issue exists. |
@ItsXor Thank you! - for making me doubt my sanity. I started to wonder how this was possible, without anyone spotting it before. |
@fpistm Dear STM - please note: "all I want for Christmas is a fix for I2C Slave" - this is the losest "writing to Santa" i ever did. :) |
Will try to work on this soon anyway any help will be appreciated. |
@fpistm very glad to hear that. Unfortunately I won't be of much help nailing the issue(insufficient skills in the area), but I definitely can help testing or running a debug build. |
@AndKe
but I've tested all the examples from Wire for Master (send/receive) and Slave(send/receive) and they work. |
Here test sketch: Master#include <Wire.h>
#define I2C_ADDR 11
static byte x = 1;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
Wire.requestFrom(I2C_ADDR, 1); // request 1 bytes from slave device
while(Wire.available()) // slave may send less than requested
{
char c = Wire.read(); // receive a byte as character
Serial.println(c, HEX); // print the character
}
delay(10);
Wire.beginTransmission(I2C_ADDR); // transmit to device
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
x++;
delay(500);
} Slave based on your sketch#include <Wire.h>
long lastms;
volatile int x = 0;
volatile int y = 0;
static void receiveEvent(int howMany) {
x = Wire.read();
}
static void requestEvent() {
Wire.write(y++);
}
void setup() {
Serial.begin(115200);
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.printf("U:0x %x\n", x);
x = 0;
}
} Note that I've clean up useless thing and optimize the slave. When you get the request you have to send it immediately else you missed the target. |
@fpistm I believe that the commented I uploaded the "Slave based on your sketch" that you posted, Please note how the SCL is suddenly kept low indefinitely. Then another capture: the F103 is running fine for several selconds, and then I connect the I2C bus (where the master is talking to it.) Please note that in both cases: the F103 is the one that is stuck keeping the SCL low - intil reset - disconnecting master leaves a fully functional I2C master. Please see the Saleae logic capture - Saleae capture.zip When SCL is stuck low like that, the "-" is no longer printed. (most likely the device is crashed/hung/looped at that point) |
Please test sketches provided. And what is your full setup. You talk about Ardupilot but it seems to be a dedicated software. What does the Ardupilot software does? Are you sure I2C @ used by the master to request data is the correct one? |
@fpistm Yes, I've been emulating that BMS for several years using Atmega 328 and Atmega32u4 with Arduino libraries. That's why we are now trying to do basic stuff like trying to see a write requests as a slave. I loaded master sketch on another STM32F103 - but it does not generate I2C traffic. (both lines remain high) Here is my slave firmware: Maybe there's something with the toolchain/build environment? |
With pullup on each I2C lines? |
yes, 10k to 5v for both, of course. |
Usually 4.7k and stm32 is 3.3v even if gpio are 5v tolerant. |
I know, but this is not the issue here, I do not see some odd levels when looking at the signals with an oscilloscope, crisp and clear - (when there is something to see) my choice is simply because some of the autopilots use 5v buffers for I/O and then 10k is standard. |
Finally I've tested with an Ardunio UNO as master (5V) and BluePill with your slave binary and it works. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the bug
I2C slave does not recieve requests.
To Reproduce
Steps to reproduce the behavior:
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.
Desktop (please complete the following information):
Board (please complete the following information):
The text was updated successfully, but these errors were encountered: