Forum

Please consider registering
guest

Log In Register

Register | Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

   

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
How to set i2c speed to 400k?
2016 年 05 月 24 日
18:02:52
pongraczi
Hungary
Moderator
Forum Posts: 20
Member Since:
2015 年 02 月 11 日
Offline

Hi,
Are there any elegant way, how to set i2c speed to 400k, instead of 100k?

I look into the code and I found, I can force it to set 400k by changing
twi_init() into twi_init(400000L) in line 60 of this file: hardware/86duino/x86/libraries/Wire/Wire.cpp

The question is, am I miss something or the library does not provide other way to change the speed of the i2c bus?

Thanks,
István

2016 年 05 月 24 日
21:53:52
pongraczi
Hungary
Moderator
Forum Posts: 20
Member Since:
2015 年 02 月 11 日
Offline

Here is a video about the speed test:

It is an SSD1306 based i2c oled display (128x64 monochrome) with i2c interface.
There is no extra pull-up resistor between Vss and SCL/SDA.

Test results:
I2C speed Display refresh
100k 110 msec
400k 35-36 msec
500k 31-32 msec

Above 500k without pull-up resistor the display does not work as expected, but it seems up to 500k it has no problem.

2016 年 05 月 25 日
10:12:37
Android_Lin
Moderator
Forum Posts: 211
Member Since:
2014 年 04 月 01 日
Offline

Hi, pongraczi,

The Wire library provide a Wire.begin(speed, address) to do this and the speed parameter can be set as 400K, and the address can be ignored by default. We can set the I2C speed to 400K using following:

void setup()
{
uint32_t i2c_speed = 400000; // the type of speed parameter must be uint32_t
Wire.begin(i2c_speed);
}

Then the Wire library will work under 400K :)

Android Lin

2016 年 05 月 26 日
17:58:14
pongraczi
Hungary
Moderator
Forum Posts: 20
Member Since:
2015 年 02 月 11 日
Offline

Thanks!

I was not sure about the 'address' parameter, but your solution is much better than the hardcoded way :)
Bye,
István

Forum Timezone: Asia/Taipei

Most Users Ever Online: 66

Currently Online:
2 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Dinosaur: 27

leutenecker: 13

mrZagg: 10

lukeross: 8

tomka: 8

smeezekitty: 8

hippy: 8

Ekkehard: 8

UIdahoCIT: 8

blaxxun: 7

Member Stats:

Guest Posters: 0

Members: 1535

Moderators: 14

Admins: 5

Forum Stats:

Groups: 2

Forums: 10

Topics: 239

Posts: 1082

Newest Members: Woodrowcercraby, Robertnalty, Homerwoppy, RonaldLew, JesusMycle, Georgerek, wholesalewholes, involy, Anthonyprity, BruceTum

Moderators: Glaux: 70, uaa: 11, guigra: 17, asian55: 22, Android_Lin: 211, bcarroll: 12, cucubutter: 84, recycled-air: 12, stevemork: 16, zerozaber: 52, pongraczi: 20, George Andrews III: 56, poto: 11, garpastym: 20

Administrators: eveshih: 1, anthony: 31, viky6: 0, roboard: 135, hcl: 0