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

Regarding adding two characteristics one for sending data to mobile and another receiving data from mobile.

Hello,

I am working on nRF52832, In my application I have added base UUID, service UUID and two characteristic UUIDs.

Please send me any example code for adding two characteristics, one for sending data from nRF52 board to mobile and one for receiving data from mobile to nRF52 device.

I would like to know how and from which variable can I read data received from mobile.

tags: nrf52832, BLE, adding characteristics, adding different UUID, custom profile creation.

  • Hi,

    Have you seen the ble_app_uart example in the SDK? You can find a description of it here. This uses the Nordic Uart Service (NUS) that has two characteristics, one for TX and one for RX, and is used to emulate a serial connection over BLE. Nordic apps like nRF connect and nRF toolbox that you can download on your smartphone can talk to this service.

    Ole

  • Hi Ole Bauck,

    Thanks for your reply.

    I have seen that example. It is very usefull for me. I would like to know, how to process the data received from mobile in BLE. From which variable i have to take data for processing. For example:

    In the UART project in write characteristics I have written a value as 0xFF. The data is sent over the air. I would like to know where the value is stored and how can I take that value for further processing.

    Thanks & Regards, Murali. M

  • The data received from the phone is handled in this function:

    static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
    {
        for (uint32_t i = 0; i < length; i++)
        {
            while (app_uart_put(p_data[i]) != NRF_SUCCESS);
        }
        while (app_uart_put('\r') != NRF_SUCCESS);
        while (app_uart_put('\n') != NRF_SUCCESS);
    }
    

    The code in this function sends the data over the UART using app_uart_put(..) for every character received. Just change the content of the function to match your needs.

    For reference this is the data handler function added when the NUS service is initialized:

    static void services_init(void)
    {
        uint32_t       err_code;
        ble_nus_init_t nus_init;
    
        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);
    }
    
  • Hi Ole Bauck,

    Thanks for your replay. I have tested the code which you mentioned in the last replay. It is working and I have take data sent from mobile to device.

    Thanks and Regards, Murali.

Related