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 Reply Children
  • 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;

  • I assume you tested and got the event BLE_NUS_EVT_TX_RDY when you send data from UART and it send a notification via BLE ? Could you try to test with the stock example (ble_app_uart) and see if you have the same error, I don't see that here.

    I assume you called BLE_NUS_DEF(m_nus) at the beginning of your main.c file.

  • Hi, and Happy new year,

    Thank you for your two answer.

    The BLE_NUS_EVT_TX_RDY event does not send a notification to the ble. It comes from it. When this event is received, in your exemple, the system should call a second callback defined when the initialization of NUS exemple is done.

    I Defined the BLE_NUS_DEF(m_nus) at the beginning of my main file.

    Thank you very much.

  • Yes, I meant you receive it when you send something via BLE, a notification. So you need to send something before you can receive it. Have you tried to test with the stock example ?

  • No I did not. In Reality I received the event. this is the work flow I have done.

    - Init Nus                      : OK
    - Wait a msg                 : OK
    - Get event RX              : OK
    - Execute Callback        : OK
    - Reply                         : OK
    - send data onver ble    : OK
    - get the Event BLE_NUS_EVT_TX_RDY : OK
    - execute line p_nus->data_handler(&evt); : NOK as data_handler is NULL 
    

    When I try to send something I have got this problem.

    On solution is to replace this line directly by a global function pointer, it is enough for my application, but it is dirty and I really want to understand why when I send something over ble it does not work.

Related