I²C target receiver on a NUCLEO-F401RE
Use the STM32 Arduino core to receive bytes over I²C and trace address, pin, and callback problems.
Wire and check the bus
Use SDA and SCL on the Nucleo Arduino header, marked D14 and D15. Join the controller and target grounds and provide pull-ups to a voltage both devices support, normally 3.3 V for this setup. Check the combined pull-ups if both breakout boards already include them.
Use a 7-bit target address such as 0x42 on both boards. Start at 100 kHz. If a bus scan reports no ACK, verify the selected pins, pull-ups and address before debugging the receive callback. A line stuck low at idle points to a wiring fault or a device holding the bus.
Receive a byte
With the STM32 Arduino core selected for NUCLEO-F401RE, send one byte from the controller to address 0x42. The target can show its latest byte on the serial monitor. Keep target callbacks short and move printing or other slow work into loop(). This example records the latest byte and intentionally coalesces arrivals between iterations.
#include <Wire.h>
volatile uint8_t lastByte = 0;
volatile bool received = false;
void receiveBytes(int) {
while (Wire.available()) {
lastByte = Wire.read();
received = true;
}
}
void setup() {
Serial.begin(115200);
Wire.begin(0x42);
Wire.onReceive(receiveBytes);
}
void loop() {
noInterrupts();
bool ready = received;
uint8_t byte = lastByte;
received = false;
interrupts();
if (ready) Serial.println(byte);
}Wire, TwoWire and another I²C port
TwoWire is the class and Wire is a board-provided instance. A library that accepts a TwoWire reference or pointer can use a different instance. In STM32 Arduino you can construct another TwoWire with its SDA and SCL pins, provided both map to the same supported I²C peripheral. Confirm those mappings in the chosen variant's PeripheralPins.c.
If the hardware ACKs but a long write is incomplete, retest with one byte and then check the core's target buffer size. The old libmaple core used separate Wire, HWire and WireSlave implementations on some boards. Use its own API and pin map when compiling an old sketch.
Distinguish a bus fault from a damaged I²C pin
With power off, disconnect the other devices and check for shorts between SDA or SCL, ground and the supply rails. Power the controller and verify each line returns high with a known pull-up. Try known-good SDA/SCL pins from another supported I²C instance to isolate a board fault.
A broken ACK can also come from a misconfigured pin or an address mismatch. Check the voltage on the pins under normal operation against the exact part's datasheet, including any limits when the MCU is unpowered. Some breakout boards pull the bus up to their supply instead of 3.3 V.
Use I²C on a Blue Pill
The usual STM32F103 Blue Pill exposes I²C1 on PB7 (SDA) and PB6 (SCL), and I²C2 on PB11 (SDA) and PB10 (SCL). Match the explicit pin selection to the board variant and the core. The default Wire pins on a Nucleo board may differ.
Start with known pull-ups to 3.3 V and a single device. Run a 7-bit address scan before loading its full library. If I²C2 works with software bit banging but fails on the hardware port, check that the selected Wire instance uses I²C2 and that no other peripheral reconfigures PB10 or PB11.
