Pages: [1]   Go Down
Author Topic: Set I2C speed  (Read 833 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear all,

how can set the speed of I2C communication using the wire library? In wire.begin() there is no parameter to set it.

Cheers Lodo2609
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 64
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't set I2C speed through the Wire library. If you want to change the speed to something other than 100kHz, you'll need to twiddle with registers. Check the data sheet for these guys.


EDIT:
Oh, bugger. I hate searching for problems and not getting an answer, so I'll post more to help you, and those to come after out. (:

The frequency of the SCL is controlled by two registers: TWI Bit rate Register (TWBR) and the prescaler bits in the TWI Status Register (TWSR). The end frequency of SCL is calculated as follows:

SCL frequency = CPU Clock frequency / (16 + 2 * (TWBR) * (Prescaler)

TWBR is at 0xB8
TWSR is at 0xB9 and the prescaler bits are 0 and 1. The prescaler value is as follows:

TWSR 1TWSR 0Prescaler value
001
014
1016
1164


So. Assuming a 16 MHz clock, if you wanted to have the TWI run at 100kHz, you could use the prescaler value of 4, and a bit rate register value of 18. If you wanted to jack that up to 400kHz, you could quadruple the value of TWBR, or you could use the next prescaler value. Just make sure that whatever you're talking to supports the speed you're wanting to run it at.

... But don't just take this info and run. It's still a very good idea to check the data sheet anyway, in case I've screwed something up.
« Last Edit: March 06, 2008, 02:25:16 am by MysteriousAges » Logged

Pages: [1]   Go Up
Jump to: