2018年11月27日 星期二

nRF51/nRF52 Runs BLE Peripheral and ESB Protocol Concurrently


   The code for this post is here.   

  Continue my previous post about Nordic's Enhanced Shockburst™(ESB)  reliable transceiving, In this post I would like to discuss how to combine ESB with Bluetooth low energy(BLE).

       BLE protocol is widely adopted on the consumer mobile devices, ALL mainstream mobile operation systems support that, and ALL device have been implemented the function. If is extremely easy to find out a device supporting BLE at hand. The BLE network topology is point to point, it is very straightforward and intuitive. For the simplest topology, the connection setting is quick and instinct, easy to be accepted by dummy consumer. Thus, lots mobile peripherals use this protocol connecting with mobile to transfer data or fetch command.
     In most case, one to one structure is enough for the personal device, lots  sporting wrist/belt products have existed in the market.
     However, in home or small commercial cases, one to one structure is not enough, even enough, it is only adequate. You could try to consider a user scenario :  there is a large busking,  several installation separated in an performance stage, ,the performer needs to interactive those device. The controller needs to use phone or computer to ignite fire, spray gas.. etc. Besides, It is better for the stuffs that they could use phone to control those devices, because their working space is limited.

     WIFI is a solution for the small performance issue, but WIFI might be not a good solution, It is because the setting of WIFI is troublesome, and once the phone connect to a router which is not on internet, the phone is not able to access internet either (even the phone's LTE function running).

     ESB protocol provides star and mesh  topology, but the phones do not support ESB.  However, nRF51/nRF52chip is able to  run the two protocols at the same time, that fills the gap to use phone controlling or receiving data from multi-devices.

   In this demonstration, there is a nRF51/nRF52 device conveying BLE data to ESB and vice versa. For demonstrating the transfer in detail,  I also provide a device based on nRF24LE1 for sending/receiving ESB packets.

 
※ My code is based on nRF5X SDK 11, you could download that from here.

   零. Download the code from Github.
Place the whole folder under nRF5X_SDK11_ROOT\examples\ble_peripheral. The project files are as the same as SDK default examples, in pca10028 (nRF51) and pca10040 (nRF52) repectively. All projects are for Keil-C 5.
       nRF24LE1 device code is in under folder nRF24LE1, in this folder,  all required files have been included, you do not need to download nRFgo SDK.
        UART are in baudrate 38400 in all device.

 一. About the nRF5x code : 

   The main.c is based on ble_app_template, macro _INTACT denotes where I modified. I added:

    UART function for print output.
    A timer, to print time series per second.
    A BLE service, providing to send/receive data  to/from BLE central (phone).

 
   The code under esb and esb_timeslot folder I downloaded from here. notice that the code in esb folder is not the same as SDK default containing (nRF5X_SDK11_ROOT\components\properitary_rf\esb), the adopted IRQs have been changed. And the esb_timeslot\esb_timeslot.c and esb_timeslot\esb_timeslot.h have been modified for my application.

   Due to the IRQs collision might bring the ESB function hanging. Hance, as this thread mentioned, about line 467, esb_timeslot\esb_timeslot.c should be modified:


void nrf_esb_event_handler(nrf_esb_evt_t const * p_event)
{
    :
    :
    if (p_event->evt_id & NRF_ESB_EVENT_RX_RECEIVED)
    {
#if !defined(_INTACT)   
    fetch_esb_rx_data();
#else   
        /* Data reception is handled in a lower priority interrup. */
        /* Call UESB_RX_HANDLE_IRQHandler later. */
        NVIC_SetPendingIRQ(UESB_RX_HANDLE_IRQn);
#endif   
    }
}


The nrf_esb_event_handler function is called by function ESB_EVT_IRQHandler (esb/esb.c, line 909), which is a software IRQ. But UESB_RX_HANDLE_IRQn is the re-used of WDT_IRQ.  It is not appropriate to manipulate the other IRQ inside a non-software IRQ. Thus, it is necessary to modify the code for directly fetching ESB data  in the function nrf_esb_event_handler.


 二. The code nRF24LE1 :
  The code is copied from folder txrx of my previous post's repository. Note that function, about 100 of file esb_app.c :
 

hal_nrf_enable_dynamic_ack(false);

It should be consisted with  nRF5X code esb_timeslot/esb_timeslot.c, about line 523:


nrf_esb_config.selective_auto_ack = false;

If you set that as false in nRF24LE1 but leave that as true in nRF51 the UART output of nRF24LE1  would display rf_max_retry_count_reached  but the packet indeed delivered.  Disable dynamic_ack/auto_ack means you need to manually sendback ack packet(zero length packet) to sender.

  Result :

  In BLE scanner,  the peripheral name shows as "NRF51 ESB to/from ":
※ the device name in code has been changed as "ESB to/from BLE" for the original name was "NRF51 ESB to/from BLE", which is too long to display completely(over 20 bytes). But below images were captured before the fixing .





After the phone connected with the nRF5x and set notification(subscribing). the values would be received periodically and vary with time.
 



I sent a data as to the nRF5x:



And the nRF24LE1 would received this data, as its UART showing:




Reference :

Make Nordic Enhanced ShockBurst™ (ESB) Transceivers as Multiceiver and Reliable

Migration from µESB to nrf_esb

Running micro-ESB concurrently with BLE



沒有留言:

張貼留言