Showing results for 
Search instead for 
Did you mean: 

I2C1 stops working over 8MHz STM32F042F6P6

Associate III

Hello all,

I'm having problems with I2C1, i have a code that works perfectly while i configure the HCLK to 8MHz but it stops working when i set any higher frequency. Has anybody faced similar problem?

I am using STM32CubeIDE for setting the project, this microcontroller has a separate clock from HCLK, and i can't understand why I'm having this problem.


Thanks in advance.

Andrew Neil

When you increase the HCLK, do you adjust the I2C to match?

And what, exactly, do you mean by "stops working"?

Have you viewed the I2C signals on a scope? How do they look?

Thank for your fast reply Andrew,


This is the way i configured the project trying to run the microcontroller at 16MHz (this node is working as slave), but with this configuration i can't receive anything on the master. But if i change de HCLK frequency to 8MHz, all works perfectly. 

With "it's not working" i mean that with 8MHz in HCLK the comunication works as i expect but if i put any higher frequency te comunication stops.

I'm not seen the signals on the oscilloscope yet, i'm waiting for a mate to let me use his.

Associate III

I am using STM32F042F6P6

Also show your configuration for 8MHz ...

Associate III

Here it is:




Here it is:





it stops working

> te comunication stops

What exactly is happening that leads you to believe that communication stops? Does something in your code return an error message? Are the read values not as expected?

Are you debugging and stepping through the code or are you just running it and expecting an LED to blink or something, and inferring communcation stops from lack of the LED blinking?

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

Hello again Andrew,

How i have to adjust the I2C to match?

As far as i understand, setting de I2C frequency is enough for STM32CubeMX, and do not change that frequency when de system frequency changes (the STM32 automatically adjust de parameters i mean).

I think that because with the master i tried to change only de system frequency to diferent values and I2C still working on all of them. 


Also i've been able to see the signals in the scope and when I2C works (with HCLK set to 8MHz) they look pretty well, but when i upgrade the frequency (as i explained), SCL drops to 0V and SDA is pulled up.

I attach two pictures of the comunnication working, in green SDA, in yellow SCL.

Imagen de WhatsApp 2024-02-05 a las 14.49.38_73e22a63.jpg

Imagen de WhatsApp 2024-02-05 a las 14.49.38_e660ba68.jpg


Yes, i'm sorry but i'm a beginner and i don't have a lot of knowledge debugging, with " not working" i mean that i'm not receiving the data on the master. 

The code works in an specific frequency only, but in other projects i tried and no matters de frequency if the project is set with STM32CubeIDE or MX, the I2C still working.