You are reading a single comment by @StuntMonkeh and its replies. Click here to read the full conversation.
  • WHAT THE HELL!!!! Its stopped working, I unplugged the board for some reason and then had to plug back in and reload the code and now it doesn't work.

    This is what I have. I was simply running spiInit() and it was triggering the IRQ up and down.

    var C = {
      // maximum transmit / receive buffer: 3 header + data + 2 crc bytes
      RF_MAX : (RF12_MAXDATA + 5),
      
      // RF12 command codes
      RF_RECV_CONTROL : 0x94A0,
      RF_RECEIVER_ON : 0x82DD,
      RF_XMITTER_ON : 0x823D,
      RF_IDLE_MODE : 0x820D,
      RF_SLEEP_MODE : 0x8205,
      RF_WAKEUP_MODE : 0x8207,
      RF_TXREG_WRITE : 0xB800,
      RF_RX_FIFO_READ : 0xB000,
      RF_WAKEUP_TIMER : 0xE000,
      
    // RF12 status bits
      RF_LBD_BIT : 0x0400,
      RF_RSSI_BIT : 0x0100,
    
    // bits in the node id configuration byte
      NODE_BAND : 0xC0, // frequency band
      NODE_ID : 0x1F, // id of this node, as A..Z or 1..31
      
      RETRIES : 8, // stop retrying after 8 times
      RETRY_MS : 1000, // resend packet every second until ack'ed
    
    };
    
    var RFM_IRQ = B9;
    var SPI_CS = B8;
    var SPI_MOSI = B5;
    var SPI_MISO = B4;
    var SPI_SCK = B3;
    
    var nodeid; // address of this node
    var group; // network group
    var frequency; // Frequency within selected band
    var rxfill; // number of data bytes in rf12_buf 
    var rxstate; // current transceiver state
    var ezInterval; // number of seconds between transmits
    var ezSendBuf = new Array(RF12_MAXDATA); // an empty array of length 100
    var ezSendLen; // number of bytes to send
    var ezPending; // remaining number of retries
    var ezNextSend = new Array(2); // when was last retry [0] or data [1] sent
    var rf12_crc; // running crc value
    var rf12_buf = new Array(RF_MAX); // recv/xmit buf, including hdr & crc bytes
    var rf12_seq; // seq number of encrypted packet (or -1)
    var rf12_fixed_pkt_len; // fixed packet length reception
    var seqNum; // encrypted send sequence number
    var cryptKey = new Array(4); // encryption key to use
    //void (*crypter)(uint8_t); // does en-/decryption (null if disabled)
    
    function XFER(cmd) {
      SPI1.send([cmd>>8,cmd], SPI_CS);
    }
    
    function spiInit() {
      SPI1.setup({sck:B3,miso:B4,mosi:B5}); // setup SPI
      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
      XFER(0x80C7 | (band << 4)); // EL (ena TX), EF (ena RX FIFO), 12.0pF 
      XFER(0xA000 + frequency); // 96-3960 freq range of values within band 
      XFER(0xC606); // approx 49.2 Kbps, i.e. 10000/29/(1+6) Kbps
      XFER(0x94A2); // VDI,FAST,134kHz,0dBm,-91dBm 
      XFER(0xC2AC); // AL,!ml,DIG,DQD4 
      if (group !== 0) {
          XFER(0xCA83); // FIFO8,2-SYNC,!ff,DR 
          XFER(0xCE00 | group); // SYNC=2DXX; 
      } else {
          XFER(0xCA8B); // FIFO8,1-SYNC,!ff,DR 
          XFER(0xCE2D); // SYNC=2D; 
      }
      XFER(0xC483); // @PWR,NO RSTRIC,!st,!fi,OE,EN 
      XFER(0x9850); // !mp,90kHz,MAX OUT 
      XFER(0xCC77); // OB1,OB0, LPX,!ddy,DDIT,BW0 
      XFER(0xE000); // NOT USE 
      XFER(0xC800); // NOT USE 
      XFER(0xC049); // 1.66MHz,3.1V
    }
    
    setWatch(function() {
      console.log("IRQ State");
      // do next stuff
    }, RFM_IRQ, {edge:"both", repeat:true});
    
About

Avatar for StuntMonkeh @StuntMonkeh started