I have written a code that transmits data over the I2C channel, The device ID and every other stuff is working fine. The only issue being that my code gets stuck at Wire.endTrasnmission().

I found the issue using Serial debug messages.

Strange thing:

When i disconnect the SCL line (A5 on arduino Pro Mini), the hang disappears and the code starts to function again.

A search brought me to this forum http://forum.arduino.cc/index.php?topic=66353.0

where a guy talks about the code snippet


is this possible, if yes where do i place it?

Observation: The hang goes away if i disconnect the SCL line on either of the arduinos communicating, the sam edoes not happen if i disconnect the SDA.

  • The only place some code to fix the problem could go is where code is still running during the hang: inside the twi library. Dec 5, 2014 at 20:53
  • i tried changing the buffer size as pointed in some forums, but still it does not work.
    – ArunMKumar
    Dec 6, 2014 at 4:00
  • Look into the watchdog timer. You can set it up to reset the chip if the timer hasn't been reset for e.g. 2 seconds. Just call wdt_reset() in every loop.
    – Gerben
    Dec 6, 2014 at 16:20

1 Answer 1


The device ID and every other stuff is working fine. The only issue being that my code gets stuck at Wire.endTransmission().

  • Nothing is transmitted until you call Wire.endTransmission() so that is where it will hang.

  • You should not try to do Wire transmissions inside an ISR (if you are doing that).

  • There is an alternative to the Wire library which times-out rather than hanging. It is at: Arduino I2C Master Library.

  • Make sure you have pull-up resistors on SDA and SCL. Typically 4.7 k from both to +5 V.

  • If none of that helps, please post your code.

  • Arduino I2C Master Library link is dead. It's now on GitHub: github.com/rambo/I2C
    – Casey
    Oct 21, 2020 at 0:40
  • @Casey (sigh) Let's hope that link doesn't go down. Amended answer. Thanks.
    – Nick Gammon
    Oct 21, 2020 at 6:29
  • 1
    @Casey With a bit more reputation (like, 1000) you will be able to edit answers and fix things like that up, which is perfectly acceptable to do, providing you don't change the intention of the answer.
    – Nick Gammon
    Oct 21, 2020 at 6:32
  • I think you can suggest edits with fairly low rep, I'm not sure exactly what that threshold is.
    – Nick Gammon
    Oct 21, 2020 at 6:34
  • Thanks for that. I'll have to learn how to do edits if SE ever gives me some big boy pants. It's worth noting that the original DSS Circuits I2C library is on github (github.com/DSSCircuits/I2C-Master-Library), but it died 8 years ago and was forked and carried forward by rambo (github.com/rambo/I2C) which has some activity this year.
    – Casey
    Oct 21, 2020 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.