Go Down

Topic: Faster I2C on Atmega328? (Read 103 times) previous topic - next topic

robinson01

Greetings my fellow makers!

I am into an arduino promini based project, that will utilize 3 different I2C devices, and normally this takes a bunch of runtime, about 40 frames/loop, worst case. Of course I would like to keep the project at the lowest possible runtime, with fixed looptime.

For this reason, I began to look for a way to increase I2C clock of the board, but I was not satisfied with 400kHz, so I searched further. After a while I did find a way, that seems too simple to be true.

There is a register called TWI Bit Rate Register, that is used by the atmega to set I2C clock frequency, in the following context:

Quote
FSCL =  Fclock/(16+2*TWBR*Prescaler)
I have hooked up a quick test circuit with a cheapo 24MHz logic analizer and a PFC8574 based LCD driver board, because I did not have anything else laying around. However PFC8574 is sold as a 100 kHz IIC device, it did not seem to have any problem with handling higher clock frequencies. The test code is very simple, I was sending a constant LCD.print("0").

My experiences are summarized in the following chart:
TWBRSCLFrame timeACK
72100kHz209usYes
12400kHz63,5usYes
8500kHz53usYes
6571kHz48,75usYes
4667kHz43,75usYes
3727kHz41,375usYes
2800kHzNAKNO
1889kHzNAKNO


I have also created a dump of the signals, and compared the 100kHz, most reliable signal, to the 727kHz, least reliable acknowledged one. They show 100% match.

However 41,3us frame time is almost 80% progress compared to the original 100kHz one, and about 35% compared to the required time for a single package at 400 kHz, I am realy interrested if this speed is only limited by the PFC8574 to 727kHz, and if it can be increased with a better slave.

I have a few more advanced I2C devices on the way, with 1MHz I2C support, and I will do the same test with those, to see if the Arduino meets the 1MHz absolute limit for the atmega328.

In the mean time let me know, what do you think about this whole "fight for I2C overclocking"? Are there any possible sideeffects?

srnet

However PFC8574 is sold as a 100 kHz IIC device 

.................

In the mean time let me know, what do you think about this whole "fight for I2C overclocking"? Are there any possible sideeffects?
Of course; there are very obvious 'possible sideeffects'. If you exceed the data sheet specifications then the I2C device could stop responding or the Arduino could lock up.

Whether its worth the risk depends on whether the project needs to be reliable. 
$50SAT is now Silent (but probably still running)
http://www.50dollarsat.info/
http://www.loratracker.uk/

pylon

Quote
I have also created a dump of the signals, and compared the 100kHz, most reliable signal, to the 727kHz, least reliable acknowledged one. They show 100% match.
Take a look at the signals with a scope. I'm quite sure you'll see differences. I2C is a bus that is passively pulled high. Sure you can lower the resistor values of the pull-ups but most chips can sink about 3mA at most so you are quite limited in increasing the speed anymore. If you can keep the bus capacitance low (you used just one device on the bus additionally to the master) this might work for some time but if you have 3 or 4 devices on the bus the capacitance will be significantly higher and the edges smoother. I'll bet at some value you will loose the signal completely.

robtillaart

+1 for Pylon.

If you use a higher speed you should consider using smaller pull up resistors so the signal has sharper edges.
(e.g. 4K7 iso 10K) Many devices can work above spec, but it can happen that different batches behave differently.


You can do quick testing with my multiSpeedI2CScanner found here

- https://github.com/RobTillaart/Arduino/tree/master/sketches/MultiSpeedI2CScanner
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up