Nrf52840 and Enchanced Shock Burst.

I have the following setup, master (Nrf24L01) and several clients (Nrf52840), the clients listen, the master sends a message to one client and switches to listen. When the user presses a button the client sends a message to the master and goes back to listen. The client change from listener to sender (described below) and back seems complicated. Is there simpler way to do it.
Listener setup


uint32_t esb_txrx_init( void )
{
    uint32_t err_code;

    nrf_esb_config.protocol                 = NRF_ESB_PROTOCOL_ESB; //NRF_ESB_LEGACY_CONFIG;
    nrf_esb_config.payload_length           = 21;
    nrf_esb_config.retransmit_delay         = 600;
    nrf_esb_config.bitrate                  = RADIO_MODE_MODE_Nrf_1Mbit;
    nrf_esb_config.crc                      = RADIO_CRCCNF_LEN_Two;
    nrf_esb_config.event_handler            = nrf_esb_event_handler;
    //mode defined in main //nrf_esb_config.mode                     = NRF_ESB_MODE_PRX;
    nrf_esb_config.selective_auto_ack       = false;
    nrf_esb_config.tx_output_power          = NRF_ESB_TX_POWER_4DBM;
    err_code = nrf_esb_init(&nrf_esb_config);
    VERIFY_SUCCESS(err_code);
    err_code = nrf_esb_set_rf_channel(2);
    VERIFY_SUCCESS(err_code);
    err_code = nrf_esb_set_base_address_0(rx_addr);
    VERIFY_SUCCESS(err_code);
    err_code = nrf_esb_set_base_address_1(tx_addr);
    VERIFY_SUCCESS(err_code);
    err_code = nrf_esb_set_prefixes(rx_addr_pref, NRF_ESB_PIPE_COUNT);
    VERIFY_SUCCESS(err_code);
    tx_payload.length  = 21;
    tx_payload.pipe    = 1;
    return err_code;
}

The change from listener to sender and back is as follows

void send_msg()
{
    uint32_t err_code;
    dprintf("Send..");

    /**** enchanced shock burst ESB TX start ***/
    nrf_esb_stop_rx();
    err_code =  nrf_esb_disable();
    APP_ERROR_CHECK(err_code);
    nrf_esb_config.mode  = NRF_ESB_MODE_PTX;
    err_code = esb_txrx_init();
    APP_ERROR_CHECK(err_code);


    strcpy(tx_payload.data, "12345678901234567890");
    tx_payload.data[1] = tx_cnt++;

    err_code = nrf_esb_write_payload(&tx_payload);
    APP_ERROR_CHECK(err_code);
    dprintf("..OK \r\n");
    nrf_delay_ms(2);
    
    /**** enchanced shock burst ESB RX start ***/
    dprintf("Receive..");
    err_code =  nrf_esb_disable();
    APP_ERROR_CHECK(err_code);
    nrf_esb_config.mode  = NRF_ESB_MODE_PRX;
    err_code = esb_txrx_init();
    APP_ERROR_CHECK(err_code);
    err_code = nrf_esb_start_rx();
    APP_ERROR_CHECK(err_code);
    
}


 

Parents
  • Hi,

     

    When the user presses a button the client sends a message to the master and goes back to listen. The client change from listener to sender (described below) and back seems complicated. Is there simpler way to do it.

     It depends on what you want to do here. If you need to switch roles for a longer time-period to drive the communication from one side, or if you can use ACK payloads to get your data from the PRX to the PTX device.

    You can either do it like you have it now, by switching PRX->PTX (and vice-versa on the other side), or you can implement bi-directional data using ACK payloads. Example in the SDK sends ACK payload (\esb_low_power_prx and \esb_low_power_ptx)

     

    Kind regards,

    Håkon

Reply Children