Jump to content

Recommended Posts

Posted

Hi All,

 

I would appreciate if someone can guide me on how to change the I2C speed?

I'm using a OPI PC+ and the default speed is 400Khz when using the "IOCTL" method and would like to change to the standard 100Khz speed.

 

Thank you

Posted
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);

Hi Martinayotte,

Thanks for your reply.

 

I tried "100000",  "200000" and "400000"  for speed which gives the same return value of -1. Any idea why? 

BTW, may i know why "SPI_IOC_WR_MAX_SPEED_HZ" is used for i2c instead of SPI ?

Posted

Sorry for confusion, I was thinking about SPI and answer too fast.

 

For I2C, the speed is configured in the DT and/or FEX, I don't think there is any IOCTL parameter for it.

Posted

Just to clarify, DT is for Mainline kernels while FEX is for Legacy kernel.

 

In DT, there is a property named "clock-frequency = <400000>;", so it is pretty easy to change.

 

For Legacy FEX, I couldn't find any ways to do, so it seems hard coded in drivers/i2c/busses/i2c-sunxi.h

Posted

Hi. Where is this file i2c-sunxi.h located ? Can I make changes on working distro, I have many items installed and I don't want to install it from begining. Do I must extract image file of armbian, and next find there this file, make change int this file and make image from modified content ? Please help/

Posted

It is mentioned above that the path is <kernel_tree>/drivers/i2c/busses/i2c-sunxi.h, but you have to compile the whole kernel, which needs more expertises.

 

Posted

Thanks for reply. Could You give some tutorial how to compile kernel on armbian ? May I compile on this working distro, or must I use other compilation ?

Posted

Update:  I compiled kernel like in this description : https://docs.armbian.com/Developer-Guide_Build-Preparation/ and next i found i2c-sunxhi.h and changed in this area : 

/* Transfer speed. */
   
  #define SUNXI_TWI_SPEED_200K (200000)
  #define SUNXI_TWI_SPEED_400K (400000)
  #define SUNXI_TWI_SPEED(ch) (ch == SUNXI_TP_CHAN ? SUNXI_TWI_SPEED_400K : SUNXI_TWI_SPEED_200K)

 

 

to 

 

#define SUNXI_TWI_SPEED_200K (100000)

  #define SUNXI_TWI_SPEED_400K (100000)

 

So I changed (I think so) 200 and 400KHz to 100KHz

 

Next I ran "./compile.sh ignore_updates=yes"  with ignore_updates to avoid replace "my modified" i2c-sunxhi.h by original one. I choose sd card installation. 

i ran this compilation on my opi pc, I installed i2c-tools. When I type i2cdetect -y 1 I can see:

 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- 0b -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
.... but when I'm trying to read actual battery voltage which should be read by command : i2cget -y 1 0x0b 0x09 w ,

I see Error: Read failed, but maybe 1 of 30 read some values but they are wrong, example: 0xff8c, and sometimes I'm getting good read, but chance is 1 to 100 or worse.

Could You help me ?

P.S. Maybe I'm trying to do impossible. Maybe exist some usb to i2c adapter which works with armbian and which I could use for my purposes ? Could someone suggest some ? 
 

Posted

Connect a 2k2 (2200 ohm) resistor between the 3.3V connection and the SDA pin, and another one between the 3.3V and SCL pin.

Yes, they are required.

Posted

I used pull up resistors 2k2 and i think nothing changed. I tried also 4k, no change. I have maybe 5-6 read error, next I have one read but wrong, one of 10 maybe is good read. I must say that I tried also distro without i2-sunxi.h changes but with 2k2 resistors. It seems that changes in i2c-sunxi.h file bring nothing, or maybe I must make changes in other files ? Someone tried ? Maybe better way is use arduino for this purpose ?

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines