I am trying out the nRF24L01 with manicbug library RF24: Driver for nRF24L01(+) 2.4GHz Wireless Transceiver. I am wondering if my expectations are wrong (rather than a coding issue... )
I am using the pingpair_pl.pde as the basis for this test although I have also rewritten the PDE as a simple state machine just to get a different perspective on the issue but get the same results.
The essence of the supplied example PDE is that a message is sent from a ‘sender’ to a ‘listener’ and the listener then responds with an acknowledgement that it has received the message. The sender waits for this acknowledgement immediately after sending .
Suspicious chap that I am, I replaced the data sent from sender to receiver with a simple counter that increments for each send. The receiver simply echoes this number back in the acknowledgement.
I expect that when I send out the numbers 1, 2, 3, 4 etc the reply would be the same BUT it isn’t.
After sending anything, except the first send, the acknowledgment is the previous number. So sending 6 I get back 5, sending 7 I get back 6 and so on. Only the first send doesn't match this pattern. If the receiver has been doing its job on a previous ‘run’, and say it was just about to return 32 when it stopped, that will be the value in the first acknowledgement to the sender in the next test run. It seems to have been floating in the air somewhere...
I would expect to send 16, get 16 back and then be onto sending 17 etc not send 16 get back 15, send 17 get back 16 and so on.
I’m not looking for advice on how to recode/redesign or to check my code to avoid this - I’m looking for opinions and ideally someone who has already experienced this or not.
I have also been tracing the internals of the library to assist in understanding and have made all methods and properties public so I can add them to debug output in the PDE. Internal flags such as ack_payload_available seem to flip/flop correctly...
The only interesting thing I can find is in bool RF24::write( const void* buf, uint8_t len ) method at line 488 in RF24.cpp where it says if ( ack_payload_available ) so almost seems to be expecting the acknowledgement immediately after sending (IMMEDIATLEY?!?!) but doesn't subsequently apeear do anything that looks ‘useful’.
I have read the data sheets and my weekend brain hasn't worked it out. I've looked inside three other libraries and they haven't helped me ‘see the light’.
What should happen on an acknowledgment?