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

Custom Service Setup in Central

Hello Nordic Staff,

I am using the NRF52832, SDK 15.3, Keil, and the NRF52 dk dev kits.  I want to modify a program such as the UART central example to recognize my custom peripheral service.  The peripheral application runs on a third party device. It contains one service and about 5 characteristics.  Some of these are reads and others are writes.  They are mostly 8 bits long but one of them is 16 bits long.

I've searched the DEVZone for this information but could not not locate anything suitable to my task.

Here are my questions:

  • Is the ble_app_uart_c project a suitable template for adding code to recognize a custom service?
  • If yes, do I directly modify the ble_nus_c.c file to do this?
  • Which functions, header files, C files and defines specifically should I focus on when making modifications?
  • How do I create handlers for read and write events?
  • Are there any tutorials  or sample code demonstrating the above steps?

Thank you in advance,

Shawn

Parents
  • Hi Gerber,

    Is the ble_app_uart_c project a suitable template for adding code to recognize a custom service?

    You need to modify ble_nus_c.c so that it recognizes your customer UUID: For now you can see that it is designed to work with NUS_BASE_UUID. Also ble_nus_c_on_db_disc_evt is trying to match BLE_UUID_NUS_SERVICE so that it can lock itself to this service handle. NUS_C example gives a good starting template for you to figure how how initializng the central and locking to the service works.

    If yes, do I directly modify the ble_nus_c.c file to do this?

    That is correct.

    Which functions, header files, C files and defines specifically should I focus on when making modifications?
    1. in  ble_nus_c_on_db_disc_evt to listen to your service handle instead of BLE_UUID_NUS_SERVICE
    2. save all the handle values of all 5 characteristics you just discovered. The template example only saves two (BLE_UUID_NUS_RX_CHARACTERISTIC and BLE_UUID_NUS_TX_CHARACTERISTIC)
    3. handle on_hvx if there are any notification enabled in any of your characteristics
    4. ble_nus_c_init needs to be changed to discover your primary service instead of BLE_UUID_NUS_SERVICE
    5. The reset of the functions in ble_nus_c.c are helpers to work with handles on BLE_UUID_NUS_RX_CHARACTERISTIC and BLE_UUID_NUS_TX_CHARACTERISTIC. If you want to handle your writes and reads differently, then you modify these helpers accordingly.

    /Susheel

Reply
  • Hi Gerber,

    Is the ble_app_uart_c project a suitable template for adding code to recognize a custom service?

    You need to modify ble_nus_c.c so that it recognizes your customer UUID: For now you can see that it is designed to work with NUS_BASE_UUID. Also ble_nus_c_on_db_disc_evt is trying to match BLE_UUID_NUS_SERVICE so that it can lock itself to this service handle. NUS_C example gives a good starting template for you to figure how how initializng the central and locking to the service works.

    If yes, do I directly modify the ble_nus_c.c file to do this?

    That is correct.

    Which functions, header files, C files and defines specifically should I focus on when making modifications?
    1. in  ble_nus_c_on_db_disc_evt to listen to your service handle instead of BLE_UUID_NUS_SERVICE
    2. save all the handle values of all 5 characteristics you just discovered. The template example only saves two (BLE_UUID_NUS_RX_CHARACTERISTIC and BLE_UUID_NUS_TX_CHARACTERISTIC)
    3. handle on_hvx if there are any notification enabled in any of your characteristics
    4. ble_nus_c_init needs to be changed to discover your primary service instead of BLE_UUID_NUS_SERVICE
    5. The reset of the functions in ble_nus_c.c are helpers to work with handles on BLE_UUID_NUS_RX_CHARACTERISTIC and BLE_UUID_NUS_TX_CHARACTERISTIC. If you want to handle your writes and reads differently, then you modify these helpers accordingly.

    /Susheel

Children
No Data
Related