I2C communication reliability

luke1i1

  • Newbie
  • *
    • Posts: 2
    • View Profile
Hi all

This is my first post so please be kind!  I'm completely new to programming but trying my best to learn :)

Apologies if this is in the wrong section, I'll move the post if an admin can advise.

I'm currently designing a watch using the TinyDuino LED Matrix and the 1339 RTC module connected via I2C.  In short I'm concerned with the reliability of I2C (purely due to seeing other posts on various forums claiming lost data packets etc.) which has set my paranoia going!

I am using the wire.h library, in combination with the DSRTCLib.h RTC library.  I have programmed my board and it works really well (much better then I expected in fact).  However it concerns me that if the I2C does lose communication or data packets somewhere down the line I'm not going to know.  I've read up on I2C and have a reasonable grasp of it's functioning but I'm by no means an expert in it's operation. 

I suppose what I'm looking for is some way of knowing that the I2C has successfully transmitted all data packets so the time displayed on the LED Matrix is accurate. 

In addition if the I2C did suddenly lose connection mid way through sending data what would the 328P processor do?  does it simply hang waiting for the ACK and the STOP command or does it just take whatever data it has received and assume the rest is value 0 and ends communication?

Sorry for the long post, I'm really close to finishing my project but I'm concerned that I'll never know if the time displayed on my watch is accurate - obviously a pretty important thing for a watch!

Many thanks

Luke


lennevia

  • Administrator
  • Sr. Member
  • *****
    • Posts: 87
    • View Profile
Hello Luke,

Welcome to the forum! I'll try to answer your questions and provide information where I can!

Quote
In addition if the I2C did suddenly lose connection mid way through sending data what would the 328P processor do?  does it simply hang waiting for the ACK and the STOP command or does it just take whatever data it has received and assume the rest is value 0 and ends communication?

"Acknowledge bit is a ninth bit of every byte sent. The receiver always has to confirm successful receive with ACK by pulling SDA low or in case receiver cannot accept data it will leave SDA high (NACK), so master could stop transmitting and do another scenario if needed." This page some more information that picks apart the bits in each I2C signal.

Some things can definitely go wrong when using I2C, but these issues usually only occur when you are using a lot of different devices with different addresses - since I2C uses mainly two wires for communication, things could get a little hectic in a scenario with 20 I2C devices and trying to pull data from each device as quickly as possible.

That being said, while it is possible, it is unlikely you will have any issues. It sounds like you are using only one I2C device (the RTC). And while there is a small chance some signals could be lost - the RTC will continue to send and be read correctly for the time originally set. So while a signal could be lost, correct signals will continuously be sent - which should effectively correct any issues along the way.

All in all, I wouldn't worry too much! To put your mind at ease, I would recommend doing some tests with the hardware you have. You could set a time in respect to a trustworthy clock - like your phone - and then leave it over night or for a few days to see if there is any difference in the time.

I hope that helps!

Best,

Laveréna


luke1i1

  • Newbie
  • *
    • Posts: 2
    • View Profile
Hi Laveréna

Thank you for your very informative and quick response!

That's brilliant :) you've helped confirm my suspicions and hopefully I won't have too many issues with the I2C connectivity.  I have set the clock to the same time as my computer and it keeps very accurate time (+/- 1 sec a day) (it's been running from last night to tonight and no issues whatsoever!). 

Thank you once again, I'll post the final project on here once done  ;D ;D

Best wishes

Luke 


lennevia

  • Administrator
  • Sr. Member
  • *****
    • Posts: 87
    • View Profile
Hey Luke,

Happy to hear my response helped, and that you're not seeing any issues in the accuracy of the time!

Excited to see the final project!

Best,

Laveréna



 

SMF spam blocked by CleanTalk