I have set up communication from chip to chip and it works great but I need to use the writebackack for a new project. Everything is fine accept it does not clear the tx. So I only can use it once. I tried to clear it using start listening but my loop order is prevent it from working at all. I re-ranged my calls in many ways but can not figure this out.
here is my current code.
basic idea is I send a no ack, then a act with 0xff. One send to set data for the return and the second to retrieve it.
#include "nRF24L01.h" // NRF24L01 library created by TMRh20 GitHub - nRF24/RF24: OSI Layer 2 driver for nRF24L01 on Arduino & Raspberry Pi/Linux Devices
#include "RF24.h"
#include "SPI.h"
#include "printf.h"
byte ReceivedMessage[1] = {0};
byte ack[1] = {0x0a};
RF24 radio(9, 10); // CE, CSN0
void setup(void)
{
Serial.begin(9600);
printf_begin();
Serial.println("serial test ...");
Serial.println("1...");
radio.begin(); // Start the NRF24L01
radio.printDetails();
radio.setChannel(2);
const byte add[5] = {0xe7,0xe7,0xe7,0xe7,0xe7};
radio.setPALevel(RF24_PA_MAX);
radio.setCRCLength(RF24_CRC_8);
radio.setDataRate (RF24_2MBPS);
//radio.setAutoAck(true);//default
radio.enableAckPayload();
radio.enableDynamicPayloads();
//radio.spiWriteRegister(NRF24_REG_1D_FEATURE, NRF24_EN_DYN_ACK);
//hack - why not support for this I do not know?
digitalWrite(10, LOW);
SPI.transfer(0x3d);
SPI.transfer(0x07);
digitalWrite(10, HIGH);
radio.setRetries(0,0);
radio.setPayloadSize(1);
radio.openReadingPipe(0, add);
radio.startListening(); // Listen to see if information received
radio.writeAckPayload(0,ack,sizeof(ack));
radio.printDetails();
}
void loop(void)
{
//trying to flush tx here.
radio.startListening();
radio.writeAckPayload(0,ack,sizeof(ack));
//but this makes nothing work. Leaving this out I can send only once. as the TX is full afterwords.
while (radio.available())
{
radio.read(ReceivedMessage,sizeof(ReceivedMessage));
Serial.println(ReceivedMessage[0],HEX);
if (ReceivedMessage[0]==0xff)
{
Serial.print("fetch");Serial.println(ack[0],HEX);
}
else if (ReceivedMessage[0]==1) ack[0] = 0xA1;
else if (ReceivedMessage[0]==2) ack[0] = 0xA2;
else if (ReceivedMessage[0]==3) ack[0] = 0xA3;
}
}