9 years, 9 months ago.

i2c on Nucleo F401RE

Hi,

I have a problem with I2C interface on Nucleo F401RE. I have a simple program to access RTC clock:

I2C i2c(PB_9, PB_8);
DigitalOut myled(LED1);

const int addr = 0x68;

int main() {
    char cmd[1];
    while (1) {
        cmd[0] = 0;
        i2c.write(addr, cmd, 1);
        wait(1);
        myled = 1;
        wait(1);
        myled = 0;
    }
}

It doesn't work and even after attaching to oscilloscope I cannot see any data and clock (I run similar case on Arduino earlier and it worked).

When I debug "mbed" library it exits with "-1" in "i2c_api.c" in:

    // Wait address is acknowledged
    timeout = FLAG_TIMEOUT;
    while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_ADDR) == RESET) {
        timeout--;
        if (timeout == 0) {
            return -1;
        }
    }
    __HAL_I2C_CLEAR_ADDRFLAG(&I2cHandle);

Does I2C work for Nucleo F401RE?

Regards, Rafal

1 Answer

9 years, 9 months ago.

This is the old problem again: I2C addresses on the arduino are given in the 7bit format. The mbed libs uses the 8 bit format. You must shift the arduino address (0x68) to the left by one bit. So the correct mbed address is 0xD0. Also make sure you have the pull up resistors in place. Use 4k7 on SDA and on SCL.

Accepted Answer

I've changed pullups to 4k7 (from 10k), shifted the address and connected to D14/D15 pins and I can see the signal on my oscilloscope. Thanks!

posted by Rafal Kijewski 17 Jul 2014

Thank you !!!

posted by Jer LAS 03 Apr 2015