You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Which one are you trying, the RFM12B?

    The info you need will be in the datasheet and the arduino library

    You can follow the steps that the library uses to initialise: https://github.com/LowPowerLab/RFM12B/blob/master/RFM12B.cpp#L114

    Looks like the XFER function's equivalent in Espruino is just:

    function XFER(cmd) {
     SPI1.send([cmd>>8,cmd], cs_pin);
    }
    

    so you can start off with:

    var C = {
     RF_SLEEP_MODE : 0x8205,
     RF_WAKEUP_MODE : 0x8207,
     RF_TXREG_WRITE : 0xB800
    };
    
    function init() {
     // setup spi
     // then...
      XFER(0x0000); // intitial SPI transfer added to avoid power-up problem
      XFER(C.RF_SLEEP_MODE); // DC (disable clk pin), enable lbd
      
      // wait until RFM12B is out of power-up reset, this takes several *seconds*
      XFER(C.RF_TXREG_WRITE); // in case we're still in OOK mode
      while (digitalRead(RFM_IRQ) == 0)
        XFER(0x0000);
     // ...
    }
    

    So if the function finishes then at least you've had some success in talking to the chip and getting it to lower the IRQ line.

    That last bit is nasty though, and if it works I'd consider re-writing it as:

    if (!digitalRead(RFM_IRQ)) {
      console.log("IRQ shouldn't be low right now!");
      return;
    }
    var interval = setInterval(function() {XFER(0x0000);}, 10);
    setWatch(function() {
      clearInterval(interval);
      console.log("IRQ lowered");
      // do next stuff
    }, RFM_IRQ, {edge:"falling", repeat:false});
    
About

Avatar for Gordon @Gordon started