Trouble Communicating Between STM32 Microcontroller and Raspberry Pi over I2C

Hello,

I’ve been attempting to communicate between a raspberry pi and an STM32 micro-controller (STM32L053) over I2C. At the moment the raspberry pi is using a simple SMbus python script in an attempt to read a few bytes from the microcontroller. I have loaded the given I2CSlave program from mbed’s Documentation in order to sent back a few bytes to the raspberry pi after it has been “readaddressed.”

However my issues start here because when I set the slave address to( 0x42<<1), which is the address the raspberry pi senses on the I2C bus with" i2cdetect," the micro-controller all of a sudden disappears from the bus and no address is sensed from the raspberry pi’s end. However when I change the address to almost anything else, essentially a wrong address, 0x42 shows up again on the I2C raspberry pi bus. Furthermore, even when I do get the program to run on the raspberry pi and I receive a “readaddressed” signal on the micro-controller, the bytes I receive back are incorrect.

I was just curious if anyone has seen a working I2C communication between a raspberry pi and an stm32 microcontroller or have any ideas how to make this communication work. I have found basically zero examples online as everyone seems to be using arduino over the micro-controller I have. I’m not sure if my problem lies in this address issue, a software/hardware compatibility issue, or if I am simply structuring the code wrong.

For additional information, the raspberry pi includes internal pull up resistors (1.8 kohms) on its I2C pins so it was my assumption that I could simply connect the two from GND–>GND, SDA–>SDA, and SCL–>SCL. They are both being powered individually and run at 3.3 volts.

Any help would be greatly appreciated as I am new to embedded programming and I have been stuck for quite a while. Thanks!

Hi Julien,
Could you please give more details about what’s running on your Raspberry Pi? From your description, it doesn’t appear that it is mbed. (Mbed builds are not supported to run on Rpi).

How do you set the slave address? I suppose you are following https://os.mbed.com/docs/latest/reference/i2cslave.html

Your hardware connections seem good.

Please let me know the details so that I can better understand your scenario

Thanks!

Naveen, team mbed.