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

Printf() interrupted; SDK130

Dear all,

I'm using SDk130 and the Software is based on the ble_app_uart_c example. Now I want to scan the advertising data from a peripheral (device name, peer address, raw data etc.) and output it via UART on a terminal programm. The output is always interrupted by the "BLE_GAP_EVT_ADV_REPORT" event. I commented the routine sd_ble_gap_connect to not get an additional event. So, how to handle the output via UART correctly?

this is the code snippet

static void on_ble_evt(ble_evt_t * p_ble_evt)
{
    uint32_t              err_code;
    uint8_t cntData;
    uint8_t devNameBuff[25], AdvData[31];


    const ble_gap_evt_t * p_gap_evt = &p_ble_evt->evt.gap_evt; 
    
    switch (p_ble_evt->header.evt_id)
    {
 case BLE_GAP_EVT_ADV_REPORT:
       
            const ble_gap_evt_adv_report_t * p_adv_report = &p_gap_evt->params.adv_report;
            
            if (is_uuid_present(&m_tb_uuid, p_adv_report))
            {

            	for(cntData=0 ; cntData<31;cntData++)
            	{
            		AdvData[cntData] = p_adv_report->data[cntData];
            	}
            	uint16_t plen;

                printf("Found target %02x%02x%02x%02x%02x%02x\n\tPower: %i\n\t dlen: %02x\n \tscan_rsp: %i\n",
                             p_adv_report->peer_addr.addr[0],
                             p_adv_report->peer_addr.addr[1],
                             p_adv_report->peer_addr.addr[2],
                             p_adv_report->peer_addr.addr[3],
                             p_adv_report->peer_addr.addr[4],
                             p_adv_report->peer_addr.addr[5],
                             
                             p_adv_report->rssi,           

							 p_adv_report->dlen,  
							 p_adv_report->scan_rsp  

                             );

            
                err_code = sd_ble_gap_device_name_get(devNameBuff,&plen);
                printf("device name: ");
                for(cntData=0 ; cntData<25;cntData++)
                               {
                	printf("%02x ",devNameBuff[cntData]);
                               }
                printf("\n");

               for(cntData=0 ; cntData<31;cntData++)
               {

                	printf("AdvData[%i]: %02x\n",cntData,AdvData[cntData]);
              
               }
                

           //     err_code = sd_ble_gap_connect(&p_adv_report->peer_addr,
            //                                  &m_scan_params,
             //                                 &m_connection_param);   


               err_code = 0; 
                if (err_code == NRF_SUCCESS)
                {
                    // scan is automatically stopped by the connect
                    printf("Connecting to target %02x%02x%02x%02x%02x%02x\r\n",
                             p_adv_report->peer_addr.addr[0],
                             p_adv_report->peer_addr.addr[1],
                             p_adv_report->peer_addr.addr[2],
                             p_adv_report->peer_addr.addr[3],
                             p_adv_report->peer_addr.addr[4],
                             p_adv_report->peer_addr.addr[5]
                             );
                } 


            }

      
            break;

...

}

this is the output I receive on the terminal program:

terminal.PNG

the output is always interrupted after 7th byte of data (but this can also differ).

Many thanks for your support!

BR, Robert

btw: Unfortunately, i don't know how to mark code in a question correctly.

Parents
  • You have probably used up the UART TX buffer which is set up to 256 bytes in the ble_app_uart example. When the buffer/fifo is full bytes will be dropped (printf does not care about the NRF_ERROR_NO_MEM return value).

    You are printing alot of text in the event. Remember that sending data over UART actually takes time. Running at 115200 baud with one start bit and one stop bit the data rate is about 11.5 kB/s. Increasing the buffer may fix your problem, but if you get too many events you may experience that the buffer will still be filled up some times. You should consider using RTT instead (with enough buffer set up), or print less text.

Reply
  • You have probably used up the UART TX buffer which is set up to 256 bytes in the ble_app_uart example. When the buffer/fifo is full bytes will be dropped (printf does not care about the NRF_ERROR_NO_MEM return value).

    You are printing alot of text in the event. Remember that sending data over UART actually takes time. Running at 115200 baud with one start bit and one stop bit the data rate is about 11.5 kB/s. Increasing the buffer may fix your problem, but if you get too many events you may experience that the buffer will still be filled up some times. You should consider using RTT instead (with enough buffer set up), or print less text.

Children
No Data
Related