This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Several questions about sparkfun nrf52840 BLE connections

Hello Nordic,

I have several questions regarding the BLE connection. I have 2 sparkfun nRF52840 boards and an android phone (android 6.0).

This is my scenario:

    - the android phone connects to nRF1 and transmits some data .

    - then, nRF1 connects to nRF2 and transmits also some data.

    - at the final, nRF2 connects to android phone and transmits other data.

Can you help me, please, telling how to solve this circle of connections? I don't think that my phone supports peripheral mode. So, if my phone can be only in the central mode, that means that the boards have to be in peripheral mode, but being in peripheral, the boards can't talk to each other or do you have an example in the SDK to be able to do this?

Thank you.

  • Hi

    We do have a LESC multirole example, which is an application that can act either as a peripheral or centra, depending on how the connection is set up. Please check it out, as I think this would be very similar to what you want for your application.

    Best regards,

    Simon

  • Thank you Simonr.

    For now, I've tried the ble_app_multiperipheral example, managing to connect all 3 devices.

    I have a problem in the services_init function because I have to integrate NUS Service in this project (the error is caused by the bold lines):

    static void services_init(void)
    {
        ret_code_t         err_code;
        ble_nus_init_t     nus_init;
        ble_lbs_init_t     init;
        nrf_ble_qwr_init_t qwr_init = {0};

        // Initialize Queued Write Module instances.
        qwr_init.error_handler = nrf_qwr_error_handler;

        for (uint32_t i = 0; i < LINK_TOTAL; i++)
        {
            err_code = nrf_ble_qwr_init(&m_qwr[i], &qwr_init);
            APP_ERROR_CHECK(err_code);
        }

        // // Initialize LBS.
         init.led_write_handler = led_write_handler;

         err_code = ble_lbs_init(&m_lbs, &init);
         APP_ERROR_CHECK(err_code);

        // Initialize NUS.
         memset(&nus_init, 0, sizeof(nus_init));

         nus_init.data_handler = nus_data_handler;

         err_code = ble_nus_init(&m_nus, &nus_init);
         APP_ERROR_CHECK(err_code);
    }
    I think I get a reset and no device is connected. Can you tell me which might be the solution? I have to set the nus handler, otherwise it will not be called when I send some data. 
  • What error is it that you're getting? There should be an error code telling you what exactly is wrong. Have you included the necessary files for the NUS to work properly for example?

    Best regards,

    Simon

  • I don't have a debugger or emulator(J-Link) to see the error code, but the problem came from

    err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_nus->uuid_type);

    Fortunately, I solved this problem by modifying:

    static void services_init(void)
    {
        ret_code_t         err_code;
        ble_nus_init_t     nus_init;
        ble_lbs_init_t     init;
        nrf_ble_qwr_init_t qwr_init = {0};

        // Initialize Queued Write Module instances.
        qwr_init.error_handler = nrf_qwr_error_handler;

        for (uint32_t i = 0; i < LINK_TOTAL; i++)
        {
            err_code = nrf_ble_qwr_init(&m_qwr[i], &qwr_init);
            APP_ERROR_CHECK(err_code);
        }
      /* comment these lines */
        // Initialize LBS.
        // init.led_write_handler = led_write_handler;

         //err_code = ble_lbs_init(&m_lbs, &init);
         //APP_ERROR_CHECK(err_code);
     
        // Initialize NUS.
         memset(&nus_init, 0, sizeof(nus_init));

         nus_init.data_handler = nus_data_handler;

         err_code = ble_nus_init(&m_nus, &nus_init);
         APP_ERROR_CHECK(err_code);
    }
    and in advertising_init I've added:
        ble_uuid_t adv_uuids[] = {{BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}};
    instead of 
        //ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.uuid_type}};
    The problem is that now in ble_app_uart_c, in ble_nus_c_evt_handler(), 
    BLE_NUS_C_EVT_NUS_TX_EVT is not called, but
    BLE_NUS_C_EVT_DISCOVERY_COMPLETE is called
    . Do I have to enable something in the peripheral (ble_app_multiperipheral with NUS) to be called that event?
  • Hi

    The BLE_NUS_C_EVT_NUS_TX_EVT should be called to indicate that the central received something from a peer, so when you write something to the central from the peripheral, this event should be called.

    Out of curiosity, how are you flashing the applications onto your boards as you don't use a J-Link debugger of some kind?

    Best regards,

    Simon

Related