

Sticking the return immediately after the loop closing bracket still makes theĬode flow without hanging so there is nothing bad happening in there. wait until twi is ready, become master receiver When lookingĪt, say, "twi_readFrom()" I saw two while loops (line 129 and 153) where thingsĬould be getting stuck and thought it would be easy to modify them to exitĪfter a timeout had elapsed. The really weird bit is the placing of the "return" statements.

OfĬourse all results are zeros but hey, the code does not hang. Start of "twi_readFrom()" unsnags my code and everything flows perfectly. Again going and sticking a "return 0" at the Same detective work uncovers that "Wire.requestFrom()" in "Wire.cpp" goes andĬalls "twi_readFrom()" in "twi.c". The function, my original code gets past the previous snag, only to get stuck ("utility" folder of "Wire" library) and stick a "return 0" at the very start of Now, it seems that twi_writeTo() is the guilty party so if I go to "twi.c" indicate that we are done transmitting Int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1) So we know that something naughty is happening at: Now, the code hangs if I cut power to the compass after having printed: If you have an I2C device you want to test it with, put the relevant deviceId. Serial.print("Data received, value is: ") Serial.println("About to end transmission") Serial.println("About to begin transmission") Some more info, I chopped up the example sketch of the CMPS03 lib to make theįollowing sketch which runs without need for the lib. I 'm using the 0018 IDE on a kubuntu 64-bit Linux platform. I have managed to remove hanging by sticking "return" statements in various places such as twi_readFrom(), twi_writeTo() or TwoWire::endTransmission() for example, this removes the hanging by always returning 0 so it's useless but it points to these libs as being the hangers. I 'm fairly certain the guilty party is twi.c or perhaps Wire.cpp. Value = value + ((unsigned int) Wire.receive()) Unsigned int value = ((unsigned int) Wire.receive()) << 8 The CMPS03 lib is very simple, here is the read() function. The code hangs if I cut power to the compass and resumes when I restore it. Are you guys sure? I am using the CMPS03 library which adds the following sketch to examples:
