[Icc-avr] TWI problem in Atmega128

John Baraclough j_baraclough at zetnet.co.uk
Tue Sep 30 02:59:06 PDT 2008


You probably can't transpose this equation because your parentheses are 
in the wrong position. It should be:

Fscl = Fcpu / (16 + (2 * TWBR * (4^TWPS)))

which gives:

TWBR = ((Fcpu / Fscl) - 16) / (2 * (4^TWPS))



Ashoka wrote:
> Hi,
>
> I'm interfacing DS1307 with Atmega 128.
>
> 1)
> Pls guide me how to calculate the TWBR value. using fallowing equation
> which is necessary to load on TWBR to generate SCL(100k)
> CPU Clock frequency is 11.0592 MHz
>
> SCL frequency =  ((CPU Clock frequency) / 16 + 2(TWBR) ⋅ 4TWPS)


I have also attached a zip file with some working I2C code. You will 
need to adapt it slightly as it is for a different RTC chip.

HTH

John
-------------- next part --------------
A non-text attachment was scrubbed...
Name: I2c.zip
Type: application/octet-stream
Size: 1470 bytes
Desc: not available
Url : http://dragonsgate.net/pipermail/icc-avr/attachments/20080930/3088ab4b/I2c.obj


More information about the Icc-avr mailing list