cjctan Posted December 6, 2016 Posted December 6, 2016 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
martinayotte Posted December 6, 2016 Posted December 6, 2016 ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
cjctan Posted December 6, 2016 Author Posted December 6, 2016 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 ?
martinayotte Posted December 7, 2016 Posted December 7, 2016 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.
cjctan Posted December 8, 2016 Author Posted December 8, 2016 No problem. I spent some time reading on the FEX (http://linux-sunxi.org/Fex_Guide) but couldn't find any related info. As for Device Tree, I'm totally clueless, needs to dig more info....
martinayotte Posted December 8, 2016 Posted December 8, 2016 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
cjctan Posted December 9, 2016 Author Posted December 9, 2016 Thanks again,MatinayotteI change the value in i2c-sunxi.h as I'm using legacy kernel
kris85pl Posted April 5, 2017 Posted April 5, 2017 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/
martinayotte Posted April 5, 2017 Posted April 5, 2017 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.
kris85pl Posted April 6, 2017 Posted April 6, 2017 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 ?
martinayotte Posted April 6, 2017 Posted April 6, 2017 Tutorial is already detailed here : https://docs.armbian.com/Developer-Guide_Build-Preparation/
kris85pl Posted April 10, 2017 Posted April 10, 2017 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 ?
kris85pl Posted April 10, 2017 Posted April 10, 2017 No, I have none. Do You meane pull up resistors, or some pull up command ? How to do that ? Are they necessary ?
pzw Posted April 10, 2017 Posted April 10, 2017 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.
kris85pl Posted April 13, 2017 Posted April 13, 2017 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 ?
Recommended Posts