Hey!
I’ve run into an issue with getting I2C working on my Nucleo STM32F303K8. No matter what I try, I just cannot get my board to output a clock pulse.
I don’t have it connected to a device just yet, I wanted to see if I could first see the clock pulses on my oscilloscope. All I see is the both the SCL and the SDA lines pulled low. I have a serial decoder on my scope and was hoping to see the data being output.
Here is what I’ve tried so far:
- Made a clean build
- Tried different version of Mbed OS. Versions 6.5 and 6.6
- I built a small project in STM32CubeIDE and managed to get the device working using that code. This proves that it’s not something broken inside the chip, that I had the rights pins connected and could see it on my scope. Using that code isn’t an option, I’m trying to add something to an existing project.
- In the Nucleo board docs (Link here), it mentions two jumpers - SB16 and SB18 which are by default bridged. These connect D5 to A5 and D4 and A4 so that the board can be Arduino Nano compatible. It mentions that you need to set the PA5 and PA6 (D5 and D4) as input floating. I tried this by setting them up as DigitalIn pins and setting the mode a few different ways - PullUp, NoPullUp, default.
- Tried the Transfer() function instead of Write()
- Tried just Read() ing to see if I could just see clock pulses
- Tried both Start->Write->Stop methods and the Write with address method (See this post for more info)
- Tried adding 10K pullups to both SCL and SDA lines. Also tried 4.7K pull ups
- Tried probing A4/A5 instead of D4/D5. I noticed that when the board is unplugged I can probe these pins and notice that A4->D4 and A5->D5 are shorted (See the point about about jumpers)
- Tried running this at different speeds
- Had a look at known Limitations on MBed site, nothing listed there under known limitations for this board
Here is the code:
// #define DEVICE_I2C_ASYNCH false // I was curious about this one, set to both true and false to see what it would do
#include "mbed.h"
I2C my_i2c_device(I2C_SDA, I2C_SCL);
const int addr7bit = 0x48; // 7 bit I2C address
const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90
int main()
{
char cmd[2];
int result;
my_i2c_device.frequency(400000); // have tested 100Khz, 400Khz and 1Mhz
while (1) {
cmd[0] = 0x01;
cmd[1] = 0x00;
my_i2c_device.write(addr8bit, cmd, 2);
// also tried this method, which I can see in the source code is implemented differently
// my_i2c_device.start();
// my_i2c_device.write(0xFF);
// my_i2c_device.stop();
ThisThread::sleep_for(1000ms);
cmd[0] = 0x00;
my_i2c_device.write(addr8bit, cmd, 1);
result = my_i2c_device.read(addr8bit, cmd, 2);
printf("Read result: %d\r\n", result);
ThisThread::sleep_for(500ms);
// float tmp = (float((cmd[0] << 8) | cmd[1]) / 256.0); // commenting out, we don't have this sensor connected
// printf("Temp = %.2f\n", tmp);
}
}
Details about my setup:
- Target board: STM32F303K8
- Machine: Windows 10 Pro
- Mbed Studio version: 1.3.1, reporting that everything is up to date
- ST Link firmware was recently updated to latest version
- Mbed OS version: 6.6
- Scope: Rigol DS1074 - plenty of bandwidth to view this sort of signal.
- Device under test: No device, just trying to view the resulting clock pulses on my scope.
It seems there are a few others who have had similar issues in the past, while looking at their post helped me understand the problem a bit better, I couldn’t fully resolve the issue.
- Someone with my exact board with the exact complaint, a user stepped in and advised that this worked with latest Mbed OS, but didn’t say how they got it working: I2C doesn´t work on F303K8? - Question | Mbed