Skip to main content
Explorer II
July 19, 2024
Solved

Two STM32 MCU communication by I2C Issue

  • July 19, 2024
  • 2 replies
  • 1669 views

Hi guys.

I am using the guide below for starting communication between two MCU. 

Getting started with I2C - stm32mcu

The code is simple, but it did not work.

Master code:

TungNguyen_0-1721388115478.png

TungNguyen_1-1721388154059.png

I checked the SDA and SCL with different transferred data Txdata and Txdata2.

But two consecutive pulses series are totally same. 

TungNguyen_2-1721388241124.png

There is any idea about this problem.

Thank you.

Of course, I also cannot receive data at slave MCU too.

    This topic has been closed for replies.
    Best answer by TDK

    Your I2C pullups looks insufficient, especially on the SDA line. Are you using external pullups around 1-5 kOhm?

    2 replies

    TDKAnswer
    Super User
    July 19, 2024

    Your I2C pullups looks insufficient, especially on the SDA line. Are you using external pullups around 1-5 kOhm?

    Explorer II
    July 19, 2024

    Thank you for your answer. 
    Yeah, you are right, I did not use the external pullup (only use the internal pullup). However, the problem seems to be not only pull-up.

    [1] The master MCU could transmit the data because I could get the waveform, and each series of pulses is generated at each 5ms (see code).
    [2] In code, I try to transmit two different data (Txdata = "A" and Txdata1 = {0x04, 0x05, 0x06}) each 5ms however the two consecutive series of pulse are 100% same. Why? any idea? So, it looks like the root cause does not only come from pull-up technique but also may from some others.  

    Thank you

    Super User
    July 19, 2024

    The first byte of data will contain the slave address. That byte will be the same regardless of the data bytes being sent. It looks like the peripheral only gets a few bits into the transaction before giving up. Looks like it's waiting for SDA to rise or something.

    You need to solve the external pullup issue before going further. You could also slow down the clock speed by a factor of 100x or so to get it to work with the internal pullups.

    Super User
    July 21, 2024

    > My previous question is regarding to why, when I use internal pull-up, only case [3] worked normally, but case [4], [5], [6] did not?

    I'm sure there's an answer. Likely you could dig into the settings it chooses, specifically the TIMINGR register, and couple that with a look at the SDA/SCL signals to understand why some work and some other do not. Probably just a view of the SDA/SCL signals would be enough. However, not sure that would be very useful in the long run.

    You don't have to treat it as a black box. We already know the issue here--no external pullups. Look at the signals at the slower speeds to verify if the internal pullup is enough.

    Given your extremely slow rising edge on SDA, I would guess a 10 kHz bus speed is still too fast.