I2C Clock Speed

Errol
Hi,

Does anyone know how to set the I2C clock speed? It seems to be set to
1.25KHz.

I would like to set it to 100KHz as at the current speed i'm loosing
samples from my G sensor.

Thank you,
Errol

domdom
Hi Errol, 
Did you try to change RESUME_ACK definition in drv.h file ?
I'm surprised by your 1,25kHz value, how did you measure it ?
According to my SPI measures, PCLK is tuned to 50MHz, then the both
possible rates should be 50/16=3,125MHz and 50/512=97kHz...
domdom

Errol
Hi domdom,

I used my oscilloscope. I did see this morning that the oscilloscope was
still set to X5 on the time base, which i didn't take into account, so i
remeasured and the actual clock is 5.7KHz.

BTW, you are talking about SPI, do SPI and I2C get their clock from the
same source? SPI generally runs at a max of 20MHz, I2C at 100KHz or High
Speed at 400KHz.

I will try to hook it up to my pickit tonight to get a digital plot, then
i'll post it here.

Thanks,
Errol

domdom
Hi Errol, 

Yes, I think that the source clock is the same for SPI and I2C : 
SPI : SPRREx register : baud rate = PCLK/2/(Prescaler value + 1)
I2C : IICCLK = PCLK/16 or 512

Take a look in the s3c2440 datasheet, page 7-8 : 
"PCLK is used for APB bus, which is used by the peripherals such as WDT,
IIS, I2C, PWM timer, MMC interface,
ADC, UART, GPIO, RTC and SPI"

On the same page, you can see how to configure PCLK speed (CLKDIVN
register). I think it would be interesting to see its value.

The other source of problem could be the power management (CLKSLOW
register).

domdom

Errol
Hi domdom,

Apparently in IICCON(0x54000000) there is another prescaler that can divide
the IIC clock by up to 17, thus 100KHz / 17 is 5.88KHz. I think i must go
find where that is set up... :)

I just hoped that there was a simple header file somewhere that defines the
I2C clock, but no such luck. :)

Thank you,
Errol

Errol
Found it! :)

#define RESUME_NO_ACK   0x6F    // clear interrupt pending bit, ACK
disabled, div=512, IICCLK=PCLK/512

The lower 4 bits of that 6F is set, setting the divider to 17, thus
"IICCLK=PCLK/512" should read "IICCLK=PCLK/512/17".

Tx clock = IICCLK/(IICCON[3:0]+1)

Changing that 0x6F to 0x60 will give me 97KHz clock. Maybe this is why the
I2C demo that came with the MINI2440 looked so low, you can see it reading
each char, one by one.



Thank you for the guidance. :)

Thank you,
Errol

domdom
You are welcome, I learned something too, I didn't have seen the prescaler
value in IICCON.
I will add this in my i2c sample tutorial.
domdom

Errol
Thank you for that tutorial by the way. I translated it to C# and it helped
me talk to my G sensor. :)

Thank you,
Errol

Errol
Attachment: I2C.jpg (66.14 KB)
Something is strange.

This is a graph of sending one byte(0x05) to Chip address 0x3A, ram address
0x16. For some reason, some time after the transmission, the bus goes low.
The bus stalls like that for, sometimes, 20ms. Not good.

Any ideas?

Thank you,
Errol

Errol
I have found a work around to this delay.

For some reason, if you close the I2C handle then the bus stalls for 20ms.

Solution? Open the file handle/I2C bus and keep it open.

Still looking into the reason for this is a problem.

domdom
Hi Errol, 

When you call CloseHandle, I think that the I2C_Close function is called by
the system. In this function, the pins GPE15 and GPE14 (IICSDA and IICSCL)
are configured like outputs. There is a delay after.

When you call Createfile, I think that the I2C_Open function is called by
the system. In this function, the pins GPE15 and GPE14 (IICSDA and IICSCL)
are configured like IICSDA and IICSCL). There is a delay after.

Moreover, I heard that using c# is slower than c++, especially when using
stream driver (I nerver made tests).

I don't know it it can explain everything, but you can maybe search in
these directions.

domdom

Errol
Thank you for the info.

Busy doing C# tests as we speak. :)

Thank you,
Errol

paolo
Hi all,

I have a similar issue for Mini 6410. I'd like to modify I2C Clock, but I
can not find where the prescaler is et in the kernel tree. Can anyone tell
me where can I modify IICCLK and IICCON ?

Thank you
Paolo

TruthSeeker
WinCE code for changing I2C clock speed:

UINT32  IICClock = 50000;//100000;
if ( !DeviceIoControl(g_hI2C,
                      IOCTL_IIC_SET_CLOCK, 
                      &IICClock, sizeof(UINT32), 
                      NULL, 0,
                      &bytes, NULL) ) 
{
    dwErr = GetLastError();
    RETAILMSG(TRUE,(TEXT("IOCTL_IIC_SET_CLOCK ERROR: %u \r\n"), dwErr));
    return FALSE;
}       

UINT32  uiIICDelay = Clk_0;
if ( !DeviceIoControl(g_hI2C,
                  IOCTL_IIC_SET_DELAY, 
                  &uiIICDelay, sizeof(UINT32), 
                  NULL, 0,
                  &bytes, NULL) )
{
    dwErr = GetLastError();
    RETAILMSG(TRUE,(TEXT("IOCTL_IIC_SET_DELAY ERROR: %u \r\n"), dwErr));
    return FALSE;
}

;)

Dsantiago
Do you have an example of reading and writing in IIC. I always get error
1460.
Regards