Exploring the Auto-ack feature of the transceiver

Please go to the post whose link is provided after this paragraph and do not try to implement the codes provided here. The link will take you to my latest post where this feature has been explored properly. Although there is no theory on what Ack payload is so you can read the theory part from here and then follow the url to understand the problem and how to tackle that.

https://shantamraj.wordpress.com/2014/11/30/auto-ack-completely-fixed/

An Enhanced ShockBurst™ packet transaction is always initiated by a packet transmission from the PTX, the transaction is complete when the PTX has received an acknowledgment packet (ACK packet)from the PRX. The PRX can attach user data to the ACK packet
enabling a bi-directional data link.The automatic packet transaction handling works as follows:
1. You begin the transaction by transmitting a data packet from the PTX to the PRX. Enhanced ShockBurst™ automatically sets the PTX in receive mode to wait for the ACK packet.
2. If the packet is received by the PRX, Enhanced ShockBurst™ automatically assembles and transmits an acknowledgment packet (ACK packet) to the PTX before returning to receive mode.
3. If the PTX does not receive the ACK packet immediately, Enhanced ShockBurst™ automatically retransmits the original data packet after a programmable delay and sets the PTX in receive mode to wait for the ACK packet.
In Enhanced ShockBurst™ it is possible to configure parameters such as the maximum number of retransmits and the delay from one transmission to the next retransmission. All automatic handling is done without the involvement of the MCU.

Auto acknowledgment is a function that automatically transmits an ACK packet to the PTX after it has received and validated a packet. The auto acknowledgement function reduces the load of the system MCU and can remove the need for dedicated SPI hardware. An ACK packet can contain an optional payload from PRX to PTX. In order to use this feature, the
Dynamic Payload Length (DPL) feature must be enabled. If the ACK packet is not received, nRF24L01+ goes back to TX mode after a delay defined by in the “setRetries(x,x)” function and retransmits the data. This continues until acknowledgment is received, or the maximum number of retransmits is reached.

So after reading the theory you know what ack payloads mean right…..? so heres a question for you…..

Ques: What will be the basic difference b/w a normal program transmitting something and receiving something to a program that uses ack payloads???

Ans: the program dealing with ack payloads will not use radio.startListening(); function to listen for payloads cause the tx automatically switches to rx to listen to ackpaylpoads. Similarly the rx will not use radio.stopListening(); to write an ack payload !.

I have written the code in such a way that the transceivers will stop functioning(basically the tx displays a msg ” status has become false so stop here….” and stops transmitting further data.) as soon as an ack payload is not received.

If u run the code and open both the serial monitors then it is highly probable that the transmission stops with the above msg(if u open the rx serial monitor after the tx one then basically the program will start from the beginning so there will be no ack payload hence the result ). So you will have to press the reset button on the tx part a few times.

The TX code is–

#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>
int msg[1] = {1};
int rec[1] = {5};
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.enableDynamicPayloads();
  radio.openWritingPipe(pipe[0]);
  radio.setRetries(15,15);
 }
void loop()
{
  if(stat)
  {
    radio.stopListening();
    if(radio.write(msg,sizeof(msg)))
    {
      Serial.print( msg[0] );
      Serial.println("  transmitted successfully !!");
      if(radio.isAckPayloadAvailable())
      {
        radio.read(rec,sizeof(rec));
        Serial.print("received ack payload is : ");
        Serial.println(rec[0]);
      }
      else
      {
        stat = false; //doing this completely shuts down the transmitter if an ack payload is not received !!
        Serial.println("status has become false so stop here....");
      }
      msg[0]+=3;;
    if(msg[0]>=100)
    {msg[0]=1;}
    }
    else
    {Serial.println("failed tx...");}
  }
}

The RX code is–

#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>
const uint64_t pipe[1]= {0xF0F0F0F0E1LL};
RF24 radio(9,10);
int rec[1] = {0};
//int ack[1] = {990};
void setup()
{
  Serial.begin(57600);
  radio.begin();
  delay(100);
  radio.setAutoAck(true);
  radio.enableAckPayload();
  radio.enableDynamicPayloads();
  radio.openReadingPipe(1,pipe[0]);
  radio.startListening();
  radio.setRetries(15,15);
}
void loop()
{
  //radio.writeAckPayload(1,ack,sizeof(ack));
  if(radio.available())
  {
    //radio.writeAckPayload(1,ack,sizeof(ack));
    if(radio.read(rec,sizeof(rec)))
    {
      radio.writeAckPayload(1,rec,sizeof(rec));
      Serial.print("integer got is : ");
      Serial.println(rec[0]);
    }
    else
    {Serial.println("failed to receive the message");}
  }
}

now the result in serial monitor will be as follows—

20140718T211931 20140718T212004

Now there are some interesting observations that you can make…..

  1. Every third transmission is a failure.This is the best i could achieve. Inserting some more delays or deleting some worsened the situation.

2. The first transmission is 1 so is the first ack payload.

3. The second transmission is 4 but the second ack payload is again 1. The third transmission is 7 and the corresponding ack payload is 4 , the fourth transmission is 10 and the corresponding ack payload is 7 and so on….

4. I am still to figure out why is this happening. Anyone with the answer please feel free to share, comment or mail me personally.

 

Advertisements

About Shantam Raj

Currently I am a final year B.Tech undergraduate majoring in “Electronics and Communication Engineering” from IIT Guwahati. I am passionate about electronics and robotics. Apart from that I love writing, visit https://medium.com/@shantam_raj for some of my works. I am a die hard soccer fan. I also love to play badminton. I am a hardware hacking enthusiast and a tinkerer !!.
This entry was posted in Arduino, nRF24L01+, wireless communication and tagged , , . Bookmark the permalink.

One Response to Exploring the Auto-ack feature of the transceiver

  1. KT says:

    > The second transmission is 4 but the second ack payload is again 1

    writeAckPayload is used before read, in your case you set the AckPayload for the next transmission.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s