Question about TWI and Wire.requestFrom() hanging.


i've been doing tests using 2 wire interface communicate between 2 unos. since i've never used twi before took advantage of "slavesender" , "masterreader" example sketches.

everything worked expected until tried build in robustness handle slave device being unavailable. ran problem wire.requestfrom() hanging indefinitely.

here section of code of interest (running on master device). code runs once each time press push button btw.
code: [select]

    if (wire.requestfrom(8, 6)) {    // request 6 bytes slave device #8
      (int k=0; k<6; k++) {
        char c = wire.read();
        serial.print(c);
      }
    }
    else serial.print("twi slave not responding");


the slave device programed respond "hello ", works if "slave" uno board , running. hit push button , masterreader requests data, slave sends data, , "hello " gets printed.

if power off slave board masterreader sketch hangs indefinitely @ wire.requestfrom() statement when press button. further, after restore power slave board (the master) remains unresponsive. can reset slave still no response. after reseting master come life.

btw. i've done debugging trace point hangs , i'm 100% @ wire.requestfrom() statement , not anywhere else.

no other failures causing problems (apart 1 slave loses power). here summary of failures i've tested.

1. hold reset on slave while requesting data: prints "twi slave not responding".

2. disconnect scl , request data: prints "twi slave not responding".

3. disconnect sda , request data: prints "twi slave not responding".

4. disconnect both scl , sda request data: prints "twi slave not responding".

5. slave power off , request data: master hangs indefinitely , not recoverable (after power restored) combination of events other master reset.

quote
until tried build in robustness handle slave device being unavailable.
you planned deal function blocks until request amount of information had been returned, when never happen because unplugged device, how, exactly?


Arduino Forum > Using Arduino > Programming Questions > Question about TWI and Wire.requestFrom() hanging.


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor