I2Cout/I2Cin speed with I2C_Slow_Bus Off/On - no difference under 16MHz?

Started by trastikata, Dec 15, 2021, 03:29 PM

Previous topic - Next topic

trastikata

Hi all,

I was checking the I2Cout/I2Cin speed with and without I2C_Slow_Bus and noticed that this simple program will produce exactly the same assembler code at and below 16 MHz while in the Manual it is stated as 8MHz?

On a side (main) note - I was trying to increase the software I2C speed because I have an OLED capable of 1MHz I2C transfer when noticed that the delay (bra $ + 2) introduced in the code depends on the main clock speed.

Les is there a "hidden" declare allowing to control the delay so I can adjust the I2C speed to about 1 MHz?

Device = 18F25K22
Declare Xtal = 16                 

Dim SDA_Pin As PORTC.3
Dim SCL_Pin As PORTC.4
Dim a As Byte

Declare I2C_Slow_Bus On

Main:

I2COut SDA_Pin, SCL_Pin, 255, 254, [a]


Craig

Hi Trastikata

I know in the Software_I2C.inc file there is a delay that you can set which slows the bus down
instead of using the Declare.
_______________________________________________________________________________________________________________________________________

' Create a small delay to slow down the I2C interface (if required)
' Input    : None
' Output    : None
' Notes    : An actual delay may not be required here.
'          : If the I2C slave device shows innaccuracies with long leads to it, increase the DelayUs command's value to slow down the I2C interface more
'
Proc I2C_hDelay()
    DelayUS 1
EndProc

___________________________________________________________________________________________________________________________

Regards

Craig

tumbleweed

Even if you crank up the clock setting I don't think you'll ever hit 1MHz using a software bit-banged approach.

The MSSP hardware would let you do it, but I think you'd need to use a clock of 32 or 64MHz.



trastikata

@ Craig
Thank you Craig for the suggestion. I took a look at the INC file - great catch, this will save me the trouble of writing my own software I2C code from scratch.

@ tumbleweed
The PIC is running at 48 MHz and there is no problem using the MSSP module for 1 MHz I2C - everything is working correct but I am redesigning it and need those pins for something else therefore the change.

Les' code is of course most efficient and elegant but it has loops and procedures and few extras. If I make it linear, remove the loops and delays and strip the extras, I think it could get pretty close to 1 MHz with the 48 MHz core clock.