cancel
Showing results for 
Search instead for 
Did you mean: 

Two STM32 MCU communication by I2C Issue

Tung Nguyen (晉松)
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

7 REPLIES 7
TDK
Guru

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

If you feel a post has answered your question, please click "Accept as Solution".

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

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.

If you feel a post has answered your question, please click "Accept as Solution".

Dear TDK.

It is great to receive your very clear explanation.

I cannot debug with external pullup resistors immediately now, however, to work with internal pullups, I tried to modify the I2C speed & I2C clock source as some cases below:

TungNguyen_0-1721440169509.png

TungNguyen_1-1721440208436.png

[1] I2C Clock = PCLK1 = 170MHz; I2C Speed = 100kHz ---> (Original) Did not work

[2] I2C Clock = PCLK1 = 170MHz; I2C Speed = 10kHz ---> (Modified) Did not work

[3] I2C Clock = HSI = 16MHz; I2C Speed = 10kHz ---> (Modified) Worked

(different series of pulses are generated)

[4] I2C Clock = HSI = 16MHz; I2C Speed = 16kHz ---> (Modified) Did not work

[5] I2C Clock = HSI = 16MHz; I2C Speed = 12kHz ---> (Modified) Did not work

[6] I2C Clock = HSI = 16MHz; I2C Speed = 9kHz ---> (Modified) Did not work

 

Only case [3] can work. What could be the rules of frequency and speed setting?

I could find a I2C CLK requirement in reference manual but not so sure any things related?

TungNguyen_2-1721440558123.png

Thanks again for very useful suggestions until now. 

Tung

 

You should use an oscilloscope and check the waveform:
You have to see 9 bits clearly (8 bit data/slave-addr plus start and stop bits).
When you just see just 3 clock edges - it cannot be right.

Using the internal pull-ups - way too weak: for 100 ...400 KHz I2C speed you might need something in the range of 2K2 - as external pull-ups. Internal pull-ups for I2C will almost never work (disable those, looks like you have already Open Drain configured - correct).

Good luck.

Dear Tjaekel

Thank you for your suggestion. 

Of course, I have clearly measured the waveforms and also will implement the external pull-up hardware to try.

However following the suggestions from TDK, I already made it work with internal pullup resistor by tuning from PCLK1 170MHz to HSI 16MHz and I2C speed from 100kHz to 10kHz. 

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?

Thank you~

TDK
Guru

> 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.

If you feel a post has answered your question, please click "Accept as Solution".