Hey there! I have a strange problem with the I2C bus, no matter which Nucleo board I use (I have the F446RE and the L432KC).
I tried the following I2C Scanner:
#include "mbed.h"
#define I2C1_SDA PB_9
#define I2C1_SCL PB_8
I2C i2c1(I2C1_SDA, I2C1_SCL);
int ack = 1;
int main()
{
debug("...................:[ I2C Scanner ]:...................\n\r");
while (true)
{
debug("Scanning I2C Interface ...\r\n");
for(int address = 1; address < 127; address++)
{
ack = i2c1.write(address, "11", 1);
if (ack == 0)
debug("\tFound device at %3d -- %3x\r\n", address,address);
ThisThread::sleep_for(10ms);
}
debug("Scan finished.\r\n");
ThisThread::sleep_for(1s);
}
}
Unfortunately, none of my I2C devices are discovered and I don’t know why. I checked the wiring again and again, I made sure I have proper resistors (using 2k8) and I used an oscilloscope to make sure, that at least there is something coming out of my microcontroller (yes, I can see how addresses are scanned). Everything seems fine on the hardware side of things, so is there something wrong with my code?
Greetings!
Edit: Above code is for the Nucleo F446RE; the L432KC uses different pins for its I2C1 interface of course.