Changing I2C frequency broke I2C

03 Feb 2010

I have a program that handles a lot of i2c accesses on a LPC1768.  Today, I decided to modify the frequency by adding the line:

i2c.frequency(400000);

Now, the ic2 no longer works.  I've tried lowering the frequency, even taking the new line of code out, then power cycling the mbed, but to no avail.  It's still broken.  Is the value of the i2c frequency non-volatile?

Any advice would be appreciated.

...kevin

03 Feb 2010

Hi Kevin,

The value of the I2C is volatile, so after powercycling (and even just reset), you are back to the defaults. I'd assume driving whatever chip at too higher frequency wouldn't zap it, but may be worth checking you are resetting whatever it is correctly? I suspect something else.

You could try the I2CU app I wrote to see if the mbed can find any I2C devices (make sure it is refering to the correct I2C port!) That might help eliminate some causes.

Simon

03 Feb 2010

I found my problem, sorry.  Along with changing the frequency to 400000, I also had moved variables around in the code to clean it up a bit.  Even though it compiled correctly, whatever I did to move the variables broke the i2c.  I went back to an older version, changed to 400k i2c frequency and all is HAPPY again.

thanks Simon,

...kevin

BTW: I had previously incorporated I2CU into my code to discover devices at power-up.  It's a really neat tool.

18 Dec 2014

Hi People,

I have a pair of simple code for two ST Nucleo boards, one is set as I2C Master-transmitter and the other one is Slave-receiver. the codes are working fine together, and I have verified results both on oscilloscope and also on PC terminal with default I2C frequency (100KHz).

I tried to increase the I2C Frequency to 300KHz, with frequency() function. The problem arises when I try to use "i2c.frequency(300000)" for master, and "slave.frequency(300000)" for slave. Even with default 100000 value, the communication won't establish.

Am I missing something with frequency() function?

I appreciate any help with this.

18 Dec 2014

Hi People,

I have a pair of simple code for two ST Nucleo boards, one is set as I2C Master-transmitter and the other one is Slave-receiver. the codes are working fine together, and I have verified results both on oscilloscope and also on PC terminal with default I2C frequency (100KHz).

I tried to increase the I2C Frequency to 300KHz, with frequency() function. The problem arises when I try to use "i2c.frequency(300000)" for master, and "slave.frequency(300000)" for slave. Even with default 100000 value, the communication won't establish.

Am I missing something with frequency() function?

I appreciate any help with this.

18 Dec 2014

100000 should work, I have no explanation why that fails.

However some STM targets only implement the default clock speeds of I2C: 100k, 400k, and depending on target 1000k. All other frequencies, including 300k, result in an error. Other targets, including some of the other STM targets, can accept any frequency.

18 Dec 2014

Hi Erik,

Thanks for the tip, this has been a great help. you are right.

Although STM32F030x8 datasheet indicates that it has to work with 0-100 KHz for SCL frequency in Normal Mode and 0-400 KHz in Fast Mode, in Mbed it only works with 100KHz and 400KHz, and no other values!

One more question, Do I have to use slave.frequency() function at the slave side? it seems when ever I add this to slave-receiver code, slave doesn't acknowledge that. Do you have any idea about this?

18 Dec 2014

I have never uses I2C slave, but I don't see how it should be used: it receives a clock and will never have to generate its own clock.

18 Dec 2014

I agree with you, since it's master providing the clock, there is no need to slave know about clock speed.

However this slave.frequency() function is part of I2CSlave.h header file, therefore I thought maybe based on the SCL frequency, slave might change its configuration to adopt the speed using mentioned function.