The ESB receiver sends problems

Hi Q&A My keyboard chip is NRF52832, and the program uses ESB 2.4G communication. The receiver dongle uses NRF52833. Now there is a problem that when the CAPSLOCK is clicked with the keyboard, the receiving dog correctly returns the information of CAPSLOCK. When I click CAPSLOCK with another keyboard at the same time, the receiving dongle cannot return information. My understanding is that when ESB, as the sender, sends out a round of data and waits for a while to receive a response type of data, it will close the reception, and if the time exceeds, it cannot receive data. I don't know if my understanding is correct or how I should solve this problem?

Parents
  • Hi, 
    Please correct me if I'm wrong, what you have is one PRX and 2 PTX connect to it act as keyboards. And when you press CAPSLOCK on 2 keyboards at the same time only one get responded ? If you press caplock on only one keyboard, do you see the other keyboard has letter in capital ? What I'm think of here is that the PC only has one CAPSLOCK status, when you turn on the CAPSLOCK on one keyboard, both get enabled (but the CAPSLOCK status LED will not turn on on the other keyboard as it didn't receive the command to turn on the LED). 

    Regarding your question about ESB, you can take a look here: 
    docs.nordicsemi.com/.../esb_users_guide.html

    If the ACK doesn't come the packet will be retransmitted after a few attempt packet will be marked as missing. 

  • Hi Hung Bui

    Thank you for your reply,

    This is the dual-mode communication keyboard program that I wrote.

    I used NRF52832 to send data. The code is as follows.

    static nrf_esb_payload_t  tx_payload = NRF_ESB_CREATE_PAYLOAD(0, 0x01, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00);  //2.4g数据发送缓冲器
    		static uint8_t * p_key = data_array;
    		
    void clocks_start( void )
    {
        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_HFCLKSTART = 1;
        while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    }
    
    
    void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
    {
        switch (p_event->evt_id)
        {
            case NRF_ESB_EVENT_TX_SUCCESS:
    				    NRF_LOG_INFO("TX SUCCESS EVENT");
    				    esb_tx_success = true;              
                break;
            case NRF_ESB_EVENT_TX_FAILED:
    				    NRF_LOG_INFO("TX FAILED EVENT");
                (void) nrf_esb_flush_tx();
                (void) nrf_esb_start_tx();
    				    if(keyboard_send)
    						   {
    								esb_tx_failed = true;
    							 }
                break;
            case NRF_ESB_EVENT_RX_RECEIVED:
    				     NRF_LOG_INFO("RX RECEIVED EVENT");
    				     while (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS)
                 {
                    if (rx_payload.length > 0)
                    {
    									if((rx_payload.data[1]&2)==2)
    									   {
    										  m_caps_on = true;
    										 }
                      else 
    									 {
    										m_caps_on =  false;
    									 }
    								   Send_data_stm32(3);             //caps_lock STM32									
    									
                    }
                 }
                break;
          }
    }
    
    
    static uint32_t esb_init( void )
    {
         uint32_t err_code;
    
        static  uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
        static  uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
        static  uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
    		
        nrf_esb_config_t nrf_esb_config         = NRF_ESB_DEFAULT_CONFIG;
        nrf_esb_config.protocol                 = NRF_ESB_PROTOCOL_ESB_DPL;
        nrf_esb_config.retransmit_delay         = 200;                        //600
        nrf_esb_config.bitrate                  = NRF_ESB_BITRATE_2MBPS;   //NRF_ESB_BITRATE_1MBPS NRF_ESB_BITRATE_2MBPS
        nrf_esb_config.event_handler            = nrf_esb_event_handler;
        nrf_esb_config.mode                     = NRF_ESB_MODE_PTX;
        nrf_esb_config.selective_auto_ack       = false ;                     // true; //
        nrf_esb_config.payload_length   = 32;                                 // 
    		nrf_esb_config.tx_output_power  = NRF_ESB_TX_POWER_3DBM;
        err_code = nrf_esb_init(&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, NRF_ESB_PIPE_COUNT);
        VERIFY_SUCCESS(err_code);
    
        return err_code;
    }
    
    //---------------------------2.4G
    void esb_initial(void)
    {  
        ret_code_t err_code;
    
        clocks_start();
        err_code = esb_init();
        APP_ERROR_CHECK(err_code);
    
    }
    ....   //----Serial port receiving data--------
    else if(receive_temp[1] == 0xfd)            //It's keyboard data
    	{											 										 
    		keyboard_send = true; 
    		if(running_mode == BLE_MODE){    
    		if(m_conn_handle != BLE_CONN_HANDLE_INVALID)
    			{	         
    			memcpy(data_array,receive_temp+2,8); 
    			* p_key = data_array[0];
    			keys_send(sizeof(data_array), p_key);    //
    			//NRF_LOG_INFO("ble-keyboard-send");
    			}
    		}
    		else {
    				tx_payload.length = 9;     
    				tx_payload.noack = false; 
    				memset(tx_payload.data,0,sizeof(tx_payload.data));
    				memcpy(tx_payload.data ,receive_temp+1,9); 
    				tx_payload.data[0]=REPORT_ID_KEYBOARD;     
                    nrf_esb_write_payload(&tx_payload);
                    // NRF_LOG_INFO("esb-keyboard-send");
    				}
    	}	
    ....

    The following is NRF52833 the receiving code

    static void clocks_start( void )
    {
        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_HFCLKSTART = 1;
    
        while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    }
    
    
    static void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
    {
      static nrf_esb_payload_t rx_payload;
      switch (p_event->evt_id)
        {
            case NRF_ESB_EVENT_TX_SUCCESS:
                NRF_LOG_INFO("TX SUCCESS EVENT");
                break;
            case NRF_ESB_EVENT_TX_FAILED:
                NRF_LOG_INFO("TX FAILED EVENT");
                break;
            case NRF_ESB_EVENT_RX_RECEIVED:
                NRF_LOG_INFO("RX RECEIVED EVENT");
                if (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS)
                {
                       if(rx_payload.data[0] == REPORT_ID_KEYBOARD)   
                         {
          		          uint8_t i,x;
                          static report_keyboard_t  key_report={0}; 
                          key_report.mods=rx_payload.data[1];  
                          for(i=0,x=3;i<6;i++,x++)
                          {
                             key_report.keys[i]=rx_payload.data[x];
                             NRF_LOG_INFO("Rx[%02X]", key_report.keys[i]); 
                          }  
                          usb_kbd_keys_send(&key_report);                
                         } 
                       else {;}                                                  // Nothing to do
                    
                }
                break;
        }
    }
    
    
    static uint32_t esb_init( void )
    {
        uint32_t err_code;
        static uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
        static uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
        static uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
        nrf_esb_config_t nrf_esb_config = NRF_ESB_DEFAULT_CONFIG;
        nrf_esb_config.protocol         = NRF_ESB_PROTOCOL_ESB_DPL;
        nrf_esb_config.mode             = NRF_ESB_MODE_PRX;
        nrf_esb_config.event_handler    = nrf_esb_event_handler;
        nrf_esb_config.bitrate          = NRF_ESB_BITRATE_2MBPS;
        nrf_esb_config.payload_length   = 32;        
        nrf_esb_config.crc              = NRF_ESB_CRC_16BIT;
        nrf_esb_config.tx_output_power  = NRF_ESB_TX_POWER_0DBM;   //NRF_ESB_TX_POWER_0DBM;
        nrf_esb_config.selective_auto_ack = false;
    
        err_code = nrf_esb_init(&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 NRF_SUCCESS;
    }
    
    //---------------------------2.4G------------------------------------
    void esb_initial(void)
    {
      
       uint32_t err_code;
    	
        clocks_start();  
    
        err_code = esb_init();
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_esb_start_rx();
        APP_ERROR_CHECK(err_code);
        USB_READY = false;
    
    }
    

    The ESB seems to experience occasional data loss. Sometimes it can receive the data when a key is pressed, but it fails to receive the data when the key is released. But Bluetooth doesn't have this problem and it works very well.

Reply
  • Hi Hung Bui

    Thank you for your reply,

    This is the dual-mode communication keyboard program that I wrote.

    I used NRF52832 to send data. The code is as follows.

    static nrf_esb_payload_t  tx_payload = NRF_ESB_CREATE_PAYLOAD(0, 0x01, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00);  //2.4g数据发送缓冲器
    		static uint8_t * p_key = data_array;
    		
    void clocks_start( void )
    {
        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_HFCLKSTART = 1;
        while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    }
    
    
    void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
    {
        switch (p_event->evt_id)
        {
            case NRF_ESB_EVENT_TX_SUCCESS:
    				    NRF_LOG_INFO("TX SUCCESS EVENT");
    				    esb_tx_success = true;              
                break;
            case NRF_ESB_EVENT_TX_FAILED:
    				    NRF_LOG_INFO("TX FAILED EVENT");
                (void) nrf_esb_flush_tx();
                (void) nrf_esb_start_tx();
    				    if(keyboard_send)
    						   {
    								esb_tx_failed = true;
    							 }
                break;
            case NRF_ESB_EVENT_RX_RECEIVED:
    				     NRF_LOG_INFO("RX RECEIVED EVENT");
    				     while (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS)
                 {
                    if (rx_payload.length > 0)
                    {
    									if((rx_payload.data[1]&2)==2)
    									   {
    										  m_caps_on = true;
    										 }
                      else 
    									 {
    										m_caps_on =  false;
    									 }
    								   Send_data_stm32(3);             //caps_lock STM32									
    									
                    }
                 }
                break;
          }
    }
    
    
    static uint32_t esb_init( void )
    {
         uint32_t err_code;
    
        static  uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
        static  uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
        static  uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
    		
        nrf_esb_config_t nrf_esb_config         = NRF_ESB_DEFAULT_CONFIG;
        nrf_esb_config.protocol                 = NRF_ESB_PROTOCOL_ESB_DPL;
        nrf_esb_config.retransmit_delay         = 200;                        //600
        nrf_esb_config.bitrate                  = NRF_ESB_BITRATE_2MBPS;   //NRF_ESB_BITRATE_1MBPS NRF_ESB_BITRATE_2MBPS
        nrf_esb_config.event_handler            = nrf_esb_event_handler;
        nrf_esb_config.mode                     = NRF_ESB_MODE_PTX;
        nrf_esb_config.selective_auto_ack       = false ;                     // true; //
        nrf_esb_config.payload_length   = 32;                                 // 
    		nrf_esb_config.tx_output_power  = NRF_ESB_TX_POWER_3DBM;
        err_code = nrf_esb_init(&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, NRF_ESB_PIPE_COUNT);
        VERIFY_SUCCESS(err_code);
    
        return err_code;
    }
    
    //---------------------------2.4G
    void esb_initial(void)
    {  
        ret_code_t err_code;
    
        clocks_start();
        err_code = esb_init();
        APP_ERROR_CHECK(err_code);
    
    }
    ....   //----Serial port receiving data--------
    else if(receive_temp[1] == 0xfd)            //It's keyboard data
    	{											 										 
    		keyboard_send = true; 
    		if(running_mode == BLE_MODE){    
    		if(m_conn_handle != BLE_CONN_HANDLE_INVALID)
    			{	         
    			memcpy(data_array,receive_temp+2,8); 
    			* p_key = data_array[0];
    			keys_send(sizeof(data_array), p_key);    //
    			//NRF_LOG_INFO("ble-keyboard-send");
    			}
    		}
    		else {
    				tx_payload.length = 9;     
    				tx_payload.noack = false; 
    				memset(tx_payload.data,0,sizeof(tx_payload.data));
    				memcpy(tx_payload.data ,receive_temp+1,9); 
    				tx_payload.data[0]=REPORT_ID_KEYBOARD;     
                    nrf_esb_write_payload(&tx_payload);
                    // NRF_LOG_INFO("esb-keyboard-send");
    				}
    	}	
    ....

    The following is NRF52833 the receiving code

    static void clocks_start( void )
    {
        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_HFCLKSTART = 1;
    
        while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    }
    
    
    static void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
    {
      static nrf_esb_payload_t rx_payload;
      switch (p_event->evt_id)
        {
            case NRF_ESB_EVENT_TX_SUCCESS:
                NRF_LOG_INFO("TX SUCCESS EVENT");
                break;
            case NRF_ESB_EVENT_TX_FAILED:
                NRF_LOG_INFO("TX FAILED EVENT");
                break;
            case NRF_ESB_EVENT_RX_RECEIVED:
                NRF_LOG_INFO("RX RECEIVED EVENT");
                if (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS)
                {
                       if(rx_payload.data[0] == REPORT_ID_KEYBOARD)   
                         {
          		          uint8_t i,x;
                          static report_keyboard_t  key_report={0}; 
                          key_report.mods=rx_payload.data[1];  
                          for(i=0,x=3;i<6;i++,x++)
                          {
                             key_report.keys[i]=rx_payload.data[x];
                             NRF_LOG_INFO("Rx[%02X]", key_report.keys[i]); 
                          }  
                          usb_kbd_keys_send(&key_report);                
                         } 
                       else {;}                                                  // Nothing to do
                    
                }
                break;
        }
    }
    
    
    static uint32_t esb_init( void )
    {
        uint32_t err_code;
        static uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
        static uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
        static uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
        nrf_esb_config_t nrf_esb_config = NRF_ESB_DEFAULT_CONFIG;
        nrf_esb_config.protocol         = NRF_ESB_PROTOCOL_ESB_DPL;
        nrf_esb_config.mode             = NRF_ESB_MODE_PRX;
        nrf_esb_config.event_handler    = nrf_esb_event_handler;
        nrf_esb_config.bitrate          = NRF_ESB_BITRATE_2MBPS;
        nrf_esb_config.payload_length   = 32;        
        nrf_esb_config.crc              = NRF_ESB_CRC_16BIT;
        nrf_esb_config.tx_output_power  = NRF_ESB_TX_POWER_0DBM;   //NRF_ESB_TX_POWER_0DBM;
        nrf_esb_config.selective_auto_ack = false;
    
        err_code = nrf_esb_init(&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 NRF_SUCCESS;
    }
    
    //---------------------------2.4G------------------------------------
    void esb_initial(void)
    {
      
       uint32_t err_code;
    	
        clocks_start();  
    
        err_code = esb_init();
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_esb_start_rx();
        APP_ERROR_CHECK(err_code);
        USB_READY = false;
    
    }
    

    The ESB seems to experience occasional data loss. Sometimes it can receive the data when a key is pressed, but it fails to receive the data when the key is released. But Bluetooth doesn't have this problem and it works very well.

Children
No Data
Related