[Icc-avr] TWI problem in Atmega128

Ashoka ashok.alal at gmail.com
Mon Sep 29 22:54:55 PDT 2008


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)

2)
In write mode, i'm able to write only 0(zero) at zeroth bit of all registers
of DS1307.
Ex: 1.)
  TWDR = 0x00;
  TWCR = BIT(TWINT) | BIT(TWEN);
  while (!(TWCR & BIT(TWINT)))
    ;

  2.)
  TWDR = 0x02;
  TWCR = BIT(TWINT) | BIT(TWEN);
  while (!(TWCR & BIT(TWINT)))
    ;

   so on....

works fine. and also getting acknowledgment from DS1307.
(i. e. TWSR value is $28)

where as
3.)
  TWDR = 0x01;
  TWCR = BIT(TWINT) | BIT(TWEN);
  while (!(TWCR & BIT(TWINT)))
  ;

4.)
  TWDR = 0x03;
  TWCR = BIT(TWINT) | BIT(TWEN);
  while (!(TWCR & BIT(TWINT)))
  ;

so on
in this case acknowledge bit is not coming.
(i. e. TWSR value is $30)

*here is my code*

TWCR = BIT(TWINT) | BIT(TWSTA) | BIT(TWEN);

  while (!(TWCR & BIT(TWINT)))
    ;

 TWSR value is $08     // A START condition has been transmitted

  TWDR = RTC_SLA_W;
  TWCR = BIT(TWINT) | BIT(TWEN);

  while (!(TWCR & BIT(TWINT)))
    ;

    TWSR value is $18     // SLA+W has been transmitted ACK has been
received

   TWDR = 0x00;                                // pointing to DS1307
register address
   TWCR = BIT(TWINT) | BIT(TWEN);
   while (!(TWCR & BIT(TWINT)))
    ;

  TWDR = 0x00;                                   // WRITING 00 at seconds
REGISTER of DS1307
  TWCR = BIT(TWINT) | BIT(TWEN);
  while (!(TWCR & BIT(TWINT)))
    ;

TWSR value is $28                             // Data byte has been
transmitted  ACK has been received

TWDR = 0x01;                                    // WRITING 01 at minutes
REGISTER of DS1307
TWCR = BIT(TWINT) | BIT(TWEN);
while (!(TWCR & BIT(TWINT)))
   ;
TWSR value is $30                               // Data byte has been
transmitted NOT ACK has been received



please giude me ......


Sincerely,

Ashok
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20080930/1ecdb746/attachment.html


More information about the Icc-avr mailing list