Main Site Documentation

Trouble using 3rd channel for I2C with custom STM32F4 board


I’m trying to use the 3rd I2C channel on my custom STM32F4 board.

I changed my platform_selector.h to use Port 3 (I also wish this was changed to read Channel instead of Port)…

#define STM32F4_I2C_PORT 3
#define STM32F4_I2C_SCL_PIN {8} // PA8
#define STM32F4_I2C_SDA_PIN {41} // PC9

Reading in “STM32F4_i2c_functions.cpp” I noticed I should be using PC9 and PA8…

#elsif STM32F4_I2C_PORT == 3
#define I2Cx I2C3
#define I2Cx_EV_IRQn I2C3_EV_IRQn
#define I2Cx_ER_IRQn I2C3_ER_IRQn
#if !defined(STM32F4_I2C_SCL_PIN)
#define STM32F4_I2C_SCL_PIN 8 // PA8
#if !defined(STM32F4_I2C_SDA_PIN)
#define STM32F4_I2C_SDA_PIN 41 // PC9

I have a scope connected to SDA/SCL and I’m not seeing anything when I execute my I2C code. Any thoughts?

If I manually set the pins high or low of course I see the activity I expected on the scope.

My C# code is this simple…

I2CDevice.Configuration config = new I2CDevice.Configuration(0x51, 50);
I2CDevice ic2Device = new I2CDevice(config);

buffer = new byte[] { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
readBuffer = new byte[] { 0x00, 0x00 };
I2CDevice.I2CWriteTransaction write = I2CDevice.CreateWriteTransaction(buffer);
I2CDevice.I2CReadTransaction read = I2CDevice.CreateReadTransaction(readBuffer);
r = ic2Device.Execute(new I2CDevice.I2CTransaction[] { write, read }, 1000);
if (r != 0)
//Never happens


Worth mentioning, this triggers my scope all day long…

SoftwareI2C s = new SoftwareI2C(CPU.Pins.GPIO_PIN_A_8_AKA_SCL, CPU.Pins.GPIO_PIN_C_9_AKA_SDA, 50);
while (true)
       s.Transmit(true, true, (byte)0x50);

But I want to use the hardware class (I2CDevice). So far I haven’t done any bit-banging and I don’t want to start now.