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

the API + sd_ble_gattc_write

my dk board is nrf51422 and nrf 52382,

the central role is nrf51422, and the peripheral role is 52382.

my sdk version of 52422 is 10.0.0 and 0.9.2 for 52382

the project of 51422 is ble_app_uart_c and the project of 52382 is ble_app_uart

i want to send to GATTserver data through uart byte by byte,so i change the project like this:

//51422

void uart_event_handle(app_uart_evt_t * p_event)
{

    static uint8_t mychar;;
    static uint8_t index = 0;

    switch (p_event->evt_type)
    {
        /**@snippet [Handling data from UART] */ 
        case APP_UART_DATA_READY:
            UNUSED_VARIABLE(app_uart_get(&mychar));
			     	printf("mychar :%c\r\n",mychar);
				    {
                while (ble_nus_c_string_send(&m_ble_nus_c, &mychar, 1) != NRF_SUCCESS)			
                {
                    // repeat until sent
                }
					  }
            break;
        /**@snippet [Handling data from UART] */ 
        case APP_UART_COMMUNICATION_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_code);
            break;

        default:
            break;
    }
}

//52382

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('\n') != NRF_SUCCESS);
}

If i send byte by byte ,it can be sent to the perpheral.

And if i send two to bytes at once,it can also be sent to the perpheral

And if i send mor than five bytes at once,it just can be sent four of five,and the uart is dead.

The same thing happened to the notify , too.

i changed the project in 52382, and sent byte by byte.

//52382

void uart_event_handle(app_uart_evt_t * p_event)
{

    static uint8_t mychar;
    uint32_t       err_code;
    switch (p_event->evt_type)
    {
        case APP_UART_DATA_READY:
            UNUSED_VARIABLE(app_uart_get(&mychar));
            {
                err_code = ble_nus_string_send(&m_nus, &mychar, 1);
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
                }
            }
            break;
        case APP_UART_COMMUNICATION_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_communication);
            break;
        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_code);
            break;
        default:
            break;
    }
}

At this time,it can just be sent up to 3 bytes....

Is there anyont know this issue?

thank you very much..

Parents
  • I believe this is related to the number of TX buffers available. Each time you call ble_nus_string_send() you will fill one TX buffer, and when there are no available TX buffers you will get the BLE_ERROR_NO_TX_BUFFERS error. If you follow the APP_ERROR_CHECK() function you will see that this resets the chip.

    You can confirm this by defining DEBUG as a preprocessor symbol and put a breakpoint in app_error_handler().

    The total number of TX buffers depends on what SoftDevice you are using, with the S110 SoftDevice you can add 6 notifications before you get the BLE_ERROR_NO_TX_BUFFERS, and currently with the S130/S132 you can add 2 notifications. We will improve this to be 6 soon.

    So what you need to do is to handle this error, you can call ble_nus_string_send() in a loop until you don't get the error anymore. A better way of handling it is to stop calling ble_nus_string_send() when you get the error, and wait for the BLE_EVT_TX_COMPLETE event. This event will release x number of buffers.

  • Thank you for your patient. I noticed that the source code in the nordic demo have added the handle the error.

                while (ble_nus_c_string_send(&m_ble_nus_c, &mychar, 1) != NRF_SUCCESS)			
                {
    
                    // repeat until sent
                }
    
Reply Children
No Data
Related