natevw / node-nrf

Pure-JavaScript nRF24L01 driver library
117 stars 31 forks source link

Ack Payload not working #47

Open wuyuanyi135 opened 8 years ago

wuyuanyi135 commented 8 years ago

Hi, I recently switched to this project to communicate my RPI2 with one nrf chip. It seems everything works except for ack payload from PRX.

Please refer to the code below. If you look at the line with comment <---look at this line, it failed the tx code. The PTX failed with MAX_RT. If I comment out this line, the PRX does receive the transmitted data.

I forked your project and add the FIFO_STATUS in printDetails, which confirmed that the ack payload has been written (TX not empty).

My guess is that the register is not configured properly. After terminate the program, the registers maintain the values. If I remove the line, the TX can still work (before the RX FIFO is full). If I leave this line here, the PTX fails directly.

I wonder, should I configure any extra options for PTX or PRX, if I need to use ack payload?

The receiver code:

var spiDev = "/dev/spidev0.0",
    cePin = 25,
    irqPin = 24

var nrf = require('nrf').connect(spiDev, cePin, irqPin);
nrf.reset(function(){

    nrf.channel(0x4c).dataRate('1Mbps').crcBytes(2).autoRetransmit({count:15, delay:4000});

    nrf.begin(function () {
        var rx = nrf.openPipe('rx', 0xF0F0F0F0E1);

        rx.on('ready', function () {
           printSelf();
           rx.write("helloWorld!");        // <----------- look at this line
        });

        rx.on('data', function(d) {
            console.log("Data:" + d);
        });
    });

    function printSelf() {
        nrf.printDetails();
        setTimeout(printSelf,2000);
    }
});

Receiver Status: (With write payload line)

SPI device:      /dev/spidev0.0
CE GPIO:         25
IRQ GPIO:        24
STATUS:          0xe RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0–1:    0xe7e7e7e7e7 0xf0f0f0f0e1
RX_ADDR_P2–5:    0xc3 0xc4 0xc5 0xc6
TX_ADDR:         0xe7e7e7e7e7
RX_PW_P0–5:      0x0 0x20 0x0 0x0 0x0 0x0
EN_AA:           0x3f
EN_RXADDR:       0x02
RF_CH:           0x4c
FIFO_STATUS:     0x01
RF_SETUP:        0x07
CONFIG:          0x0f
DYNPD/FEATURE:   0x02 0x07
Data Rate:       1Mbps
Model:           nRF24L01+
CRC Length:      16 bits
PA Power:        PA_MAX

Receiver Status: (remove that line)

SPI device:      /dev/spidev0.0
CE GPIO:         25
IRQ GPIO:        24
STATUS:          0xe RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0–1:    0xe7e7e7e7e7 0xf0f0f0f0e1
RX_ADDR_P2–5:    0xc3 0xc4 0xc5 0xc6
TX_ADDR:         0xe7e7e7e7e7
RX_PW_P0–5:      0x0 0x20 0x0 0x0 0x0 0x0
EN_AA:           0x3f
EN_RXADDR:       0x02
RF_CH:           0x4c
FIFO_STATUS:     0x11
RF_SETUP:        0x07
CONFIG:          0x0f
DYNPD/FEATURE:   0x02 0x07
Data Rate:       1Mbps
Model:           nRF24L01+
CRC Length:      16 bits
PA Power:        PA_MAX
Data:hello!

The transmitter:


var spiDev = "/dev/spidev0.0",
    cePin = 25,
    irqPin = 24

var nrf = require('nrf').connect(spiDev, cePin, irqPin);

nrf.channel(0x4c).dataRate('1Mbps').crcBytes(2).autoRetransmit({count:15, delay:4000});

nrf.begin(function () {
//    var rx = nrf.openPipe('rx', 0xF0F0F0F0D2);
      var tx = nrf.openPipe('tx',  0xF0F0F0F0E1/*, {ackPayloads: true, autoAck: true}*/);

   tx.on('data', function (d) {
      console.log("Got Data:" + d.toString());
   });

   tx.on('ready', function() {
      tx.write("hello!");

nrf.printDetails()
      //send();
   });
});

Transmitter status (failing)

SPI device:      /dev/spidev0.0
CE GPIO:         25
IRQ GPIO:        24
STATUS:          0xe RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0–1:    0xf0f0f0f0e1 0xf0f0f0f0d2
RX_ADDR_P2–5:    0xc3 0xc4 0xc5 0xc6
TX_ADDR:         0xf0f0f0f0e1
RX_PW_P0–5:      0x0 0x0 0x0 0x0 0x0 0x0
EN_AA:           0x3f
EN_RXADDR:       0x01
RF_CH:           0x4c
FIFO_STATUS:     0x01
RF_SETUP:        0x07
CONFIG:          0x0e
DYNPD/FEATURE:   0x03 0x07
Data Rate:       1Mbps
Model:           nRF24L01+
CRC Length:      16 bits
PA Power:        PA_MAX
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: Packet timeout, transmit queue flushed.
    at /home/pi/dchost-node/node_modules/nrf/index.js:342:28
    at /home/pi/dchost-node/node_modules/nrf/index.js:81:25
wuyuanyi135 commented 8 years ago

I managed to figure out the problem. This line was commented. But somehow ceHigh does not set in the options. Will submit a PR