my transceivers are running fine. i 've written a few code and got them running.then i decided to check the auto acknowledgement feature wherein we can return data back to the sender WITHOUT manually changing the radio modes on both units.but i find that the serial monitor always shows "failed to transmit".why is this happening cause otherwise they work fine.
i am using maniacbug's RF24master library.
the Tx code is-
#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>
int msg[1] = {1};
int rec[1] = {0};
bool stat = true;
RF24 radio(9,10);
const uint64_t pipe[1] = {0xF0F0F0F0E1LL};
void setup()
{
Serial.begin(57600);
radio.begin();
delay(1000);
radio.setAutoAck(true);
radio.enableAckPayload();
radio.openWritingPipe(pipe[0]);
radio.setRetries(15,15);
}
void loop()
{
if(stat)
{
radio.stopListening();
bool ok = radio.write(msg,sizeof(msg));
delay(100);
if(ok)
{Serial.println("transmitted successfully !!");}
else
{Serial.println("faileed to transmit");}
msg[1]++;
if(msg[1]>=200)
{msg[1]=1;}
stat = false;
//delay(20);
}
if(!stat)
{
if(radio.isAckPayloadAvailable())
{
radio.read(rec,sizeof(rec));
Serial.print("received ack payload is : ");
Serial.println(rec[1]);
stat = true;
}
}
}
and the Rx part is -
#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>
const uint64_t pipe = 0xF0F0F0F0E1LL;
RF24 radio(9,10);
int rec[1] = {0};
int ack[1] = {1};
void setup()
{
Serial.begin(57600);
radio.begin();
delay(100);
radio.setAutoAck(true);
radio.enableAckPayload();
radio.openReadingPipe(1,pipe);
radio.startListening();
radio.setRetries(15,15);
}
void loop()
{
if(radio.available())
{
Serial.println("payload available....");
bool ok = radio.read(rec,sizeof(rec));
if(ok)
{
Serial.println("message received !!");
Serial.print("integer got is : ");
Serial.println(rec[1]);
radio.writeAckPayload(1,ack,sizeof(ack));
}
else
{Serial.println("failed to receive the message");}
}
}