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

use Uart sample to TX/RX long data > 20 bytes ?

Hello,

Two issues want to ask, after tried the BLE_NUS example code. From other posts, still does not exist clear solution (example, pictures) ? Sure has an application note, document guide for such problems.

  1. TX character ,received data from client (MCP) want to support get more data > 20 bytes . I tried to use the "Request(queued) write" property for the TX characteristic but still only get data bytes less than 20 bytes ? FW code should be fine (from the sample of ble_app_hrs---LongWrite) , could be the Android or MCP problem ?

  2. RX character, send data to client (MCP), want to support send more data > 20 bytes. I tried to add "Read" property in addition to the notify property of RX characteristic.

It seems the sd_ble_gatts_value_set() will split data to multiple chunk automatically, but it require manual to read data by MCP or APP. I still prefer to use the notify method, but has big problem if many data need to send. Getting the error code 0x3004, and BLE reset(error) because I am transmitting data too quickly ? I tried to use the TX_COMPLETE event to control the in/out data flow but still fail. Here is my test code for the problem:

static volatile bool tx_buffer_is_free=true;                                                         void uart_event_handle(app_uart_evt_t * p_event) {
static uint8_t data_array[BLE_MAX_DATA_LEN];
static uint8_t index = 0;
uint32_t       err_code;

switch (p_event->evt_type)
{
    case APP_UART_DATA_READY:
        if (tx_buffer_is_free)
		UNUSED_VARIABLE(app_uart_get(&data_array[index]));
    else
		break;
        index++;
        // for test each byte notify
        //if ((data_array[index - 1] == '\n') || (index >= (BLE_MAX_DATA_LEN))) 
        {
           
            tx_buffer_is_free=false;
            err_code = ble_nus_string_send(&m_nus, data_array, index);
            if (err_code != NRF_ERROR_INVALID_STATE)
            {
                APP_ERROR_CHECK(err_code);
            }
            if (err_code == NRF_SUCCESS)
                  tx_buffer_is_free=true;

            index = 0;
        }
        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;
}  }   

 static void on_ble_evt(ble_evt_t * p_ble_evt) {
	
uint32_t                         err_code;

switch (p_ble_evt->header.evt_id)
{
	case BLE_EVT_TX_COMPLETE:
		tx_buffer_is_free=true;
		break;
         .......
        .......
}}

When I sent more than 8 bytes of data in one time from Uart console, BLE_NUS will reset. below 8 is ok.

What's the right way to handle such problem (sent as many bytes through notification) over ble_nus ?

Appreciate any response , thanks.

Related