<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to change RX to TX and back on the go on NRF52 esb</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/20592/how-to-change-rx-to-tx-and-back-on-the-go-on-nrf52-esb</link><description>I want to change rx to tx mode and back after recertion my master NRF24l01 packet on NRF52 with esb, how to do it?
I tried this but it doesnt works: 
 void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
{
 switch (p_event-&amp;gt;evt_id)
 {
 case</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 18 Mar 2017 10:20:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/20592/how-to-change-rx-to-tx-and-back-on-the-go-on-nrf52-esb" /><item><title>RE: How to change RX to TX and back on the go on NRF52 esb</title><link>https://devzone.nordicsemi.com/thread/80256?ContentTypeID=1</link><pubDate>Sat, 18 Mar 2017 10:20:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a219c07e-3845-4448-9915-aa47026ced04</guid><dc:creator>Amigo</dc:creator><description>&lt;p&gt;I&amp;#39;ve sovlved it!!! i take a look at an example &lt;a href="https://github.com/NordicSemiconductor/nrf52-esb-broadcaster/blob/master/radio.c"&gt;here&lt;/a&gt;
The error was here:
nrf_esb_config_t nrf_esb_config = NRF_ESB_DEFAULT_CONFIG;
i preinitialised ESB as TX.
After correction this line like   nrf_esb_config_t nrf_esb_config; program starts to work nice.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is property of Nordic Semiconductor ASA.
 * Terms and conditions of usage are described in detail in NORDIC
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 *
 */

#include &amp;quot;nrf_esb.h&amp;quot;

#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;sdk_common.h&amp;quot;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_esb_error_codes.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_error.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;

#define RX 0 
#define TX 1 

uint8_t RX_MODE_FLAG = 0;
uint8_t TX_MODE_FLAG = 0;

const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;
uint8_t led_nr;

nrf_esb_payload_t 				rx_payload;
nrf_esb_payload_t        	tx_payload = NRF_ESB_CREATE_PAYLOAD(0, 0xC1, 0x00, 0x05);

nrf_esb_config_t nrf_esb_config;//  = NRF_ESB_DEFAULT_CONFIG;

/************************Functions prototypes*************************************/
void nrf_esb_error_handler(uint32_t err_code, uint32_t line)
{
    NRF_LOG_PRINTF(&amp;quot;App failed at line %d with error code: 0x%08x\r\n&amp;quot;,
                   line, err_code);
#if DEBUG //lint -e553
    while(true);
#else
    NVIC_SystemReset();
#endif
}

#define APP_ERROR_CHECK(err_code) if(err_code) nrf_esb_error_handler(err_code, __LINE__);
/*********************************************************************************/
void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
{
    switch (p_event-&amp;gt;evt_id)
    {
        case NRF_ESB_EVENT_TX_SUCCESS:
						// Toggle one of the LEDs.
						nrf_gpio_pin_toggle(LED_2);
						RX_MODE_FLAG = 1;
            break;
        case NRF_ESB_EVENT_TX_FAILED:
						nrf_gpio_pin_toggle(LED_3);
						nrf_esb_flush_tx();
						RX_MODE_FLAG = 1;
            break;
        case NRF_ESB_EVENT_RX_RECEIVED:
            if (nrf_esb_read_rx_payload(&amp;amp;rx_payload) == NRF_SUCCESS)
            {
							// Set LEDs identical to the ones on the PTX.
							nrf_gpio_pin_toggle(LED_4);
            }
						nrf_esb_flush_rx();
						TX_MODE_FLAG = 1;
            break;
    }
}
/*********************************************************************************/
void clocks_start( void )
{
    NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;
    while (NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0);
}
/*********************************************************************************/
void gpio_init( void )
{
    LEDS_CONFIGURE(LEDS_MASK);
}
/*********************************************************************************/
uint32_t esb_init( uint8_t state )
{
    uint32_t err_code;
    uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
    uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
    uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
			
		nrf_esb_config.tx_mode									= NRF_ESB_TXMODE_AUTO;
    nrf_esb_config.payload_length           = 32;
		nrf_esb_config.retransmit_delay         = 1000;
		nrf_esb_config.retransmit_count					= 6;
    nrf_esb_config.protocol                 = NRF_ESB_PROTOCOL_ESB;
    nrf_esb_config.bitrate                  = NRF_ESB_BITRATE_2MBPS;
		switch(state){
			case RX:
						nrf_esb_config.mode             = NRF_ESB_MODE_PRX;
			break;
			case TX:
						nrf_esb_config.mode             = NRF_ESB_MODE_PTX;
			break;	
		}
    nrf_esb_config.event_handler            = nrf_esb_event_handler;
		nrf_esb_config.crc											= NRF_ESB_CRC_16BIT;	
    nrf_esb_config.selective_auto_ack       = true;
		
		err_code = nrf_esb_set_rf_channel(14);
		VERIFY_SUCCESS(err_code);
		
    err_code = nrf_esb_init(&amp;amp;nrf_esb_config);
    VERIFY_SUCCESS(err_code);

    err_code = nrf_esb_set_base_address_0(base_addr_0);
    VERIFY_SUCCESS(err_code);

    err_code = nrf_esb_set_base_address_1(base_addr_1);
    VERIFY_SUCCESS(err_code);

    err_code = nrf_esb_set_prefixes(addr_prefix, 8);
    VERIFY_SUCCESS(err_code);

    return err_code;
}
/*********************************************************************************/
int main(void)
{
    uint32_t err_code;

    gpio_init();
    clocks_start();
		esb_init(RX);
		nrf_esb_start_rx();

		while (true)
    {
			if(RX_MODE_FLAG==1)
			{				
				RX_MODE_FLAG = 0;
				// Back to RX
				nrf_esb_disable();
				nrf_esb_config.mode = NRF_ESB_MODE_PRX;
				nrf_esb_init(&amp;amp;nrf_esb_config);
				nrf_esb_start_rx();
			}
			else if(TX_MODE_FLAG==1)
			{     
				TX_MODE_FLAG = 0;	
				
				nrf_esb_stop_rx();					
				// Back to TX
				nrf_esb_disable();
				nrf_esb_config.mode = NRF_ESB_MODE_PTX;
				nrf_esb_init(&amp;amp;nrf_esb_config);
				
				
				
			  tx_payload.length = 32;
				tx_payload.pipe = 0;
				tx_payload.noack = true;
				tx_payload.data[1]++;
				
				nrf_esb_start_tx();
				
        if (nrf_esb_write_payload(&amp;amp;tx_payload) == NRF_SUCCESS)
        {
						nrf_gpio_pin_toggle(LED_1);		
				}	
			}
      //  __WFE();
    }
}
/*********************************************************************************/
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>