DS1337 with XMEGA problem (TWI)

Status
Not open for further replies.

Sharagim

Advanced Member level 4
Joined
Feb 6, 2011
Messages
112
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Visit site
Activity points
2,058
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

  • DS1337.txt
    2 KB · Views: 73

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
while (twiMaster.status != TWIM_STATUS_READY) {
  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
 

Thank you very much for your reply.
No help with Delay.
I think your idea about counter will help. I tried different values for pull-up but nothing happened.
BR,
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…