ESB library RX acknowledgements


Hi,

I am working with the ESB (Enhanced Shockburst) library using the nRF Connect SDK 2.6.1.
The library seems easy to use and has the main things that I need.

However, I want to get RX acknowledgement with specific payload for each transmission. It should be supported by the library, but I have difficulty to get it working.

The very simple sample code (esb_ptx and esb_prx) does not address this since it only acknowledges the first transmission and nothing after that.
The question is that how to reliably acknowledge every transmission, and not just the first one, or some subset.

My basic use case on the RX side is to flush the ack TX buffer (esb_flush_tx()) and re-write it (esb_write_payload(&tx_payload)) before every expected RX (and subsequent ack TX).
Flushing and rewriting the ack TX buffer ensures that I always have current data waiting as a response, whether previous transmission succeeded or not.
But when I do that, then clearly acknowledgement does not reliably happen. Something about the flush makes it not to work.

This old post is giving some context why flushing and rewriting the ack TX buffer is needed, and it is also suggested in the answer.
https://devzone.nordicsemi.com/f/nordic-q-a/22009/modifying-queued-esb-ack-payload

I found old posts about the same/similar problem. These relate to the old SDK, but the problem is the same: flushing makes ack not to happen.
https://devzone.nordicsemi.com/f/nordic-q-a/74008/problem-with-esb-ack-and-tx-flush/306402
https://devzone.nordicsemi.com/f/nordic-q-a/65016/my-esb-ptx-receives-delayed-duplicate-ack-packets-from-my-prx
https://devzone.nordicsemi.com/f/nordic-q-a/27042/esb-on-nrf52-sdk11-not-sending-ack-payloads

There are many others. The last link above is particularly relevant and it suggests a bug in the old SDK which is acknowledged, even offering a fix.
I tried to compare the old SDK code with the current one, but it is difficult. However, I am not convinced that the problem has been fixed.

My question is: Is it possible that this problem is not yet fixed? Is there still some problem with RX acknowledgements related to flushing the TX buffer?
My work-around is the same that is discussed in the posts above: Initializing the whole ESB library (esb_init(&config)) before every RX, but it seems ridiculous.

  • Hi Petri

    Thanks for the detailed description. I will set aside some time to reproduce this, and get back to you with an update in a day or two. 

    Best regards
    Torbjørn

  • Hi Petri

    I have now had some time to test it, and was easily able to reproduce it. Essentially the esb_flush_tx() function wasn't updated properly when the 'buffer improvement' changes were introduced, and this rendered the flush command more or less unusable in PRX mode. 

    Could you try to replace the implementation of this function in esb.c with the code below? 

    This seems to fix the issue on my side.

    int esb_flush_tx(void)
    {
    	if (!esb_initialized) {
    		return -EACCES;
    	}
    
    	unsigned int key = irq_lock();
    
    	tx_fifo.count = 0;
    	tx_fifo.back = 0;
    	tx_fifo.front = 0;
    
    	if (esb_state == ESB_STATE_PRX) {
    		for (size_t i = 0; i < CONFIG_ESB_TX_FIFO_SIZE; i++) {
    			ack_pl_wrap[i].in_use = false;
    			ack_pl_wrap[i].p_next = 0;
    		}
    
    		memset(rx_pipe_info, 0, sizeof(rx_pipe_info));
    	}
    
    	irq_unlock(key);
    
    	return 0;
    }

    Best regards
    Torbjørn

  • Hi Petri

    Did you have time to test my proposed fix? 

    If this solves your issue I would like to try to push it into the next SDK release. 

    Best regards
    Torbjørn

Related