i'm finding that calls to I2C routines are not returning while testing code to control model railroad tortoise switch machines. The arduino controls boards with an MPC23017 and LM324 op-amps. Two op-amp outputs control the polarity to a stall motor in the switch machine that consumes < 20 ma. power and I2C connections are daisy chained between boards.
i've been able to isolate the problem to I2C routine calls. i've further isolated the cause by avoiding any I2C operations by waiting some period (4 sec) for all motors to reach their travel limits.
I see an infinite loop in twi_readFrom()
while(TWI_READY != twi_state){
continue;
}
as an embedded firmware developer, we would never write such a loop without some timeout/count-out mechanism.
i've seen another thread from 2011 that never discussed a solution but mentioned noise as a potential cause. I realize the way I wired the board may be an issue and the I2C wiring and power wiring easily separated from one another.
of course i'm interested in a software fix, but interested in better understanding how noise could be the problem.