cancel
Showing results for 
Search instead for 
Did you mean: 

How to reduce I2C frequency from 100Khz to 20KHz

DJ1
Associate III

Hi, i am using STM32F401RE Nucleo board and i want am using I2C channel in standard mode which is upto 100KHz but i due to little long length of communication cable, i want my I2C frequency to be around 20KHz. I am using HSI only as clock source.

This is my function to use I2C channel.

void i2c_init()
{
// I2C3 RCC CLK enable
I2C3_CLK_EN;
// Freq setting 16MHz
I2C3->CR2 |= (16 << 0);
//CCR configuration
I2C3->CCR = 0x50;
// T-Rise configuration
I2C3->TRISE = 0x17;
// Set OAR bit
I2C3->OAR1 |= (1 << 14);
// Peripheral Enable
I2C3->CR1 |= (1 << 0);
}

13 REPLIES 13
LCE
Principal

Anyway, when I hear "cable length" as limiting factor, maybe you should switch data transfer to some differential interface.

Nikita91
Lead II

To adapt the I2C to the length of the cable you also have to play on the value of the pull ups.

Correct. Earlier i was using 4.7K ohms as pull up and now i am using 1K ohms pull-up, usually it works well but sometimes randomly it corrupts the bus. I have 3 slaves connected on the same bus.

DJ1
Associate III

Thanks for the clarity. Well actually i am new to firmware programming and i have just started with STM32F4 and i just could not understand how to identify the frequency of I2C bus. Also i personally prefer register level programming over HAL just for having a better idea of how the things are working in there that is why it takes me a little more to get things done.