# DS1337 with XMEGA problem (TWI)

Status
Not open for further replies.

#### Sharagim

Hi,
I am trying to use ds1337 with Xmega, but I can't get proper result.
Sometimes the code stuck in loop(Below) at startup (even flashing or reboot).
When it pass the the Stratup sequence it is working ok. I want to know if this is normal on Startup or not?

Code:
while (twiMaster.status != TWIM_STATUS_READY) {}

#### Attachments

• 2 KB Views: 3

#### Kurenai_ryu

Maybe you need to add some delay (about 100ms) before accessing the I2C bus (after the init)...

also this kind of problem arise when you don't check properly the TWI status value, maybe a too high pull up value? (I usually don't have problems with a 4.7k or 10k pull up, but it's said that you can lower it more) maybe noise interference? (I had a circuit that when you touched the SCK line with a finger it halted in the same kind of loop)

finally, the best way is to implement a counter or some way to exit the loop for example:

Code:
long int count;

...

//in code

count=0; //always clear the counter before the while
if(++count>100000) break;// this 100000 should be aprox 10ms which I think is enough time for any twi operation
}
if(count>100000){/*do something here in case of twi failure... check your doc if you need to reset the module in some sort of way*/}
//else, continue with the original program