need slower I2C spped

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
HyperUniverse
Posts: 282
Joined: 17 Jun 2009 10:42

need slower I2C spped

#1 Post by HyperUniverse » 14 Sep 2022 11:00

Hi,

How can I select a slower speed for my I2C?
say I'd like just 50KHz,
not 100kHZ as the default slowest.

And this is especially for a remappable I2C on PIC18F27K40.

Code: Select all

I2C1_Remappable_Init(100000);     // Initialize I2C communication
If I simply put the desired frequency

Code: Select all

I2C1_Remappable_Init(50000);     // Initialize I2C communication
in the initialization routine, it comes back with the error of:
Argument is out of range
Thanks.

hexreader
Posts: 1785
Joined: 27 Jun 2010 12:07
Location: England

Re: need slower I2C spped

#2 Post by hexreader » 14 Sep 2022 11:44

You do not say what value of processor clock you are using, but I am guessing it is 64MHz

If I read the datasheet correctly, then with a 64MHz Fosc, then minimum value of I2C clock is 62501 Hz
This corresponds to the highest possible value of 255 in register SSP1ADD.
It is a limitation of the hardware when using Baud Rate Generator.

The only way I can think of for I2C clock less than 62501 Hz is to use a lower processor clock speed

By the way.... 100 kHz is the lowest standard speed for I2C clock. By my understanding, there should be no commercial device that cannot handle at least 100 kHz.
Start every day with a smile...... (get it over with) :)

hexreader
Posts: 1785
Joined: 27 Jun 2010 12:07
Location: England

Re: need slower I2C spped

#3 Post by hexreader » 14 Sep 2022 12:48

Just noticed that software I2C is available and runs at 20 kHz - according to the help utility.

Interrupts cannot be used with software I2C and there are other restrictions.

Never tried software I2C. Never want to try it :(
Start every day with a smile...... (get it over with) :)

HyperUniverse
Posts: 282
Joined: 17 Jun 2009 10:42

Re: need slower I2C spped

#4 Post by HyperUniverse » 14 Sep 2022 13:56

hexreader wrote:
14 Sep 2022 11:44
. . . there should be no commercial device that cannot handle at least 100 kHz.
thanks hexreader

yes I was running it at 64MHz
I have picked a 75kHz speed and is compiling OK,
I'll reprogram the board to see if that improves my problem.

I've got 1 meter cable between an airflow sensor and the pic

Most of the time the I2C between them work fine, but once in a while is failing.
Lowering the I2C speed will improve reliability over distance . . . or so I think.

thanks again

Post Reply

Return to “mikroC PRO for PIC General”