Skip to content
View in the app

A better way to browse. Learn more.

Armbian Community Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

H3 I2C speed

Featured Replies

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

  • Author
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 ?

  • Author

Thanks again,Matinayotte

I change the value in i2c-sunxi.h as I'm using legacy kernel

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/

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 ?

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 ? 
 

No, I have none. Do You meane pull up resistors, or some pull up command ? How to do that ? Are they necessary ?

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.

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.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.