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

nrf52 nordic uart services

Hello,

I've got some trouble using Nordic Uart Services,

I correctly add the library to my project.

I can receive data from different devices. But when I want to send data over ble, the soft device Assert and make a hard fault interrupt.

After some investigationn the error comes from this function

ble_nus_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)

in the file ble_nus.c @line 262.

I understood that p_context is the ble_nus_t instance that sent my message over ble.

But when I reach this line after a transmission. The data_handler value is 0 and not the address of my callback.

Could you help me to solve this issue ?

I work on nrf52832 with SDK14.1.0 and SES. I started from free RTOS hrs exemple

Thank You. Geoffrey

Ps : This is my ble_nus_initialization

static void mdw_nus_data_handler(ble_nus_evt_t * p_evt);

void mdw_console_ble_init(void)
{
    mdwConsBleFlagsHandle = xEventGroupCreate();
    ASSERT(NULL != mdwConsBleFlagsHandle);
    mdwConsBleWriteMutexHandle = xSemaphoreCreateMutex();
    ASSERT(NULL != mdwConsBleWriteMutexHandle);
    mdwConsBleReadMutexHandle = xSemaphoreCreateBinary();
    ASSERT(NULL != mdwConsBleReadMutexHandle);
    xSemaphoreGive(mdwConsBleReadMutexHandle);
    xSemaphoreTake(mdwConsBleWriteMutexHandle, portMAX_DELAY);

    ble_nus_init_t nus_init;
    memset(&nus_init, 0, sizeof(nus_init));

    nus_init.data_handler = mdw_nus_data_handler;

    mdwRxEnable = false;
    mdwTxEnable = false;

    uint32_t errCode = ble_nus_init(&m_nus, &nus_init);
    APP_ERROR_CHECK(errCode);

    xSemaphoreGive(mdwConsBleWriteMutexHandle);
}
Parents
  • Hi Geoffrey, What do you have in mdw_nus_data_handler() ? You need to define the function so that p_nus->data_handler(&evt); can be called. In the code you post you just have a declaration, not the definition of the function it self.

    Please have a look at nus_data_handler() function we have in main.c in ble_app_uart example.

  • Hello Hung,

    Indeed, the code written contains just the prototype of mdw_nus_data_handler().

    The function is defined in an another place in the file. To Sum up, it contains a switch with ble_nus_evt and my actions to do for each event.

    Moreover my function (mdw_nus_data_handler) is correctly called when I've got :

    • BLE_NUS_EVT_RX_DATA
    • BLE_NUS_EVT_COMM_STARTED
    • BLE_NUS_EVT_COMM_STOPPED

    But never when BLE_NUS_EVT_TX_RDY is set. As at this moment p_nus->data_handler is NULL;

Reply
  • Hello Hung,

    Indeed, the code written contains just the prototype of mdw_nus_data_handler().

    The function is defined in an another place in the file. To Sum up, it contains a switch with ble_nus_evt and my actions to do for each event.

    Moreover my function (mdw_nus_data_handler) is correctly called when I've got :

    • BLE_NUS_EVT_RX_DATA
    • BLE_NUS_EVT_COMM_STARTED
    • BLE_NUS_EVT_COMM_STOPPED

    But never when BLE_NUS_EVT_TX_RDY is set. As at this moment p_nus->data_handler is NULL;

Children
No Data
Related