I am having a strange problem trying to use PA_14 and PA_15 for I2C on STM32F303K8.
I just received my custom board with an STM32F303K8. To map the pins and avoid conflicts, I used STM32CubeMX. I enabled I2C1, which defaulted to pins PA_14 and PA_15 for SDA and SCL respectively. I used these defaults, and only today found out that the default for mbed (or at least the one on their pinout page) is PB_7 and PB_6. I already connected pins PA_14 and PA_15 to the I2C bus on my board and I use PB_6 and PB_7 as digital pins for something else.
This should be no problem though, right? I just need to specify I2C i2c (PA_14, PA_15)
when instantiating my i2c instance. This does not work. Not only does it not connect to my sensor, but it seems that the processor halts immediately.
As the comments suggest, even instantiating i2c
on pin PA_15 (PA_14 seems fine though?) results in the processor halting. No more logs in my serial terminal. Unfortunately, this board doesn’t have any leds, but I could solder a through hole one on a digital pin if you think it’s a required troubleshooting step.
#include <mbed.h>
// I2C i2c(PA_14, PA_15); <-- Halts processor if commented out
// I2C i2c(PB_7, PB_6); <-- This is fine
// I2C i2c(PA_14, PB_6); <-- Even this is fine
// I2C i2c(PB_7, PA_15); <-- This is NOT fine
static BufferedSerial serial_port(PA_9, PA_10, 9600);
FileHandle *mbed::mbed_override_console(int fd) {
return &serial_port;
}
int main() {
// Nothing to do with I2C after instantiation
while (true) {
printf(
"Mbed OS version %d.%d.%d\n",
MBED_MAJOR_VERSION,
MBED_MINOR_VERSION,
MBED_PATCH_VERSION
);
thread_sleep_for(100);
}
}
I scoped PA_14 and PA_15. Both are normally 3.3V (pullup as required by I2C). When I push the reset button, SDA dips down a few millivolt, but only when I hold the button, it’s not sending data. SCL doesn’t budge.
I tried using STM32CubeMX to generate some code using their HAL by specifying these pins, and it works fine.
Am I doing something wrong or did I find a bug? Is there any way to get I2C working with mbed on these pins? I’d rather not write in ST’s HAL and I’d rather not cut traces on my board.