I've managed to get data in both directions using enhanced shockburst with the auto-ack enabled. The PTX sends to the PRX which in turn activates the TX function and sends back to the PTX and so on.
I notice that on the datasheet, they whisper about the W_ACK_PAYLOAD command. This should allow the Receiver to send a payload with the ACK packet back to the transmitter.
If this is possible, then it would most likely allow a bidirectional link without the receiver having to put itself specifically into transmit mode and then send a regular packet. There would be a lot less overhead in theory and there would be a higher data rate. It would not be as reliable a link as with both specifially sending and receiving with ACK's but it would be good enough to get data back from the receiver with the packet.
So I've been trying to figure out how to use the excellent library by Brennen to add in the W_ACK_PAYLOAD part.
So far I've come up with these additions:
nrf24l01.h
#define nrf24l01_W_ACK_PAYLOAD 0xA8
#define nrf24l01_W_TX_PAYLOAD_NACK 0xB0
#define nrf24l01_ACTIVATE 0x50
#define nrf24l01_DYNPD 0x1C
#define nrf24l01_FEATURE 0x1D
main unit:
//setup the dynamic packets and put the data into the W_ACK_PAYLOAD to send with the next ACK
nrf24l01_write_register(nrf24l01_ACTIVATE,0x73,1,false);
nrf24l01_write_register(nrf24l01_ACTIVATE,0x73,1);
nrf24l01_write_register(nrf24l01_DYNPD,0x01,1);
nrf24l01_write_register(nrf24l01_FEATURE,0x06,1);
nrf24l01_clear_csn();
nrf24l01_execute_command(nrf24l01_W_ACK_PAYLOAD,&data[1], 32, true);
nrf24l01_set_csn();
nrf24l01_write_register(nrf24l01_ACTIVATE,0x73,1);
nrf24l01_set_as_rx(true);
for(count = 0; count < 2000; count++) //a 2000 timeout to stop the chip from waiting forever if there is no received data.
{
if (nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active())
{
nrf24l01_read_rx_payload(&data[1], 32); //get the payload into data
nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01
break; //data came in so exit this loop
}
}
Now my questions:
1. Is it correct to be using the write_register() function to put the data into the registers?
2. Am I writing the correct data to the registers?
3. Is the order correct?
4. In the transmitter code, how do I read it? I am currently just using the nrf24l01_read_rx_payload(&data[1], 32); after I send the packet - i.e. after the ACK is received from the Receiver