Do you have any I2C working example (master or receive) ?
My below code throws compile error :class TwoWire’ has no member named ‘onReceive’ with blue pill . (no errors with arduino).
In lib examples I can see i2c scanner only.
#include <Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
// while (1 < Wire.available()) { // loop through all but the last
while ( Wire.available()) {
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
// int x = Wire.read(); // receive byte as an integer
// Serial.println(x); // print the integer
Serial.println();
}
It is all depending what you wish to attach to I2C bus : EEPROMs, GPIO Expanders, RTC Clocks, ADC, DAC.
Which ones are you planning to use ?
I want to connect blue pill to Lego EV3 using I2C.
It works ok using arduino (arduino as a slave).
Now I know that slave mode is not implemented.
I started from i2c_scanner_hwire.ino example to test I2C.
Problem is that code hangs on endTransmission().
But there is also possible mistake of crossing SDA and SCK.
But there is also possible mistake of crossing SDA and SCK.
Do you still have Wire.begin(8) or since you are trying as Master you’ve replaced it with Wire.begin() ?
I’m running out of ideas … Wire library is so simple …
Do you still have Wire.begin(8) or since you are trying as Master you’ve replaced it with Wire.begin() ?
I’m running out of ideas … Wire library is so simple …
Because I2C on F1xx are either PB6/PB7 or PB10/PB11,
On F4xx, PB8/PB9 are alternate pins but not the default PB6/PB7. For using alternate, you will need to tweak core i2c.c file.
Because I2C on F1xx are either PB6/PB7 or PB10/PB11, but NOT PB8/PB9 …
Try PB6/PB7 instead …
Try PB6/PB7 instead …
You can change it to some other values in milliseconds.

