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
I2C Clock Speed
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
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
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
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
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
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
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
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
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.
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
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
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; } ;)