consider fix for RFM12B senACK() endless loop

Started by woelfs, July 16, 2014, 05:39:40 PM

woelfs

FYI

I ran into an endless loop while adding a SD card to my ATTiny based node, which uses the LowPowerLab RFM12B library.
Every time I connected the SD card on the SPI bus my code hung within sendACK().

I had a look inside jeelib and found so following link within canSend()

thread http://openenergymonitor.org/emon/node/1051?page=3.

The following code fix it for me, so maybe you should consider the patch.

bool RFM12B::CanSend() {
  // need interrupts off to avoid a race (and enable the RFM12B, thx Jorg!)
  // see http://openenergymonitor.org/emon/node/1051?page=3
  if (rxstate == TXRECV && rxfill == 0 && (Control(0x0000) & RF_RSSI_BIT) == 0) {
    Control(RF_IDLE_MODE); // stop receiver
    rxstate = TXIDLE;
    return true;
  }
  return false;
}

Best,
Wolfgang

Felix

Thanks Wolfgang for the tip,
But I don't see how it's much different from the current code (https://github.com/LowPowerLab/RFM12B/blob/master/RFM12B.cpp) .. ?

woelfs

Sorry, I should have posted a patch ...

The difference is that it uses Control() instead of Byte() or XFER, which disables interrupts and is the actual fix as far as I understood. Didn't read the whole thread so.

Wolfgang