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

duplicate and dropped packets on uart characteristic

I'm trying to move data over the uart characteristic. I followed the guidelines here devzone.nordicsemi.com/.../

In the main loop I am calling sd_ble_gatts_hvx until it returns buffers full, careful not to increment the buffer pointer until after it returns NRF_SUCCESS.

I am seeing that groups of 2-3 later packets are copied over some preceding packets. This causes some packets to be duplicated and some packets to be dropped. I tried making hvx_params into a static array so each time sd_ble_gatts_hvx gets a different copy that won't be overwritten or go out of scope. There isn't any other ble transmission outside of moving this data in the main loop.

The only way I can get this to work is to send 1 packet, wait for BLE_EVT_TX_COMPLETE, and then send the next packet. This way is unusable at 300 bytes per second. Getting 4kb/s doing it the other way with dup/dropped packets.

Heres my code, trying to send 51 packets, BLE_EVT_TX_COMPLETE event clears ble_busy and the char* pointer is to flash data that isn't changing or going out of scope. How could I be getting duplicate/dropped packets? I edited out other error handling in this code, I have not seen any kind of error except for buffers-full error.

void ble_send_buffer(char* buf)
{
	uint32_t err_code;
	char* bp = buf;
	uint16_t nsent = 0;
	while(nsent < 51)
	{
		ble_busy = 1;
		while(1)
		{
			err_code = ble_nus_string_send(&m_nus, (uint8_t*)bp, 20);
			if (err_code == BLE_ERROR_NO_TX_BUFFERS )
			{ 
                            break;
			} else if(err_code == NRF_SUCCESS)
			{
				nsent++;
				bp += 20;
				if(nsent == 51) break;
			}
		}
		while(ble_busy); //wait for tx complete after breaking
	}
}
Parents
  • I don't have the hardware to do a sniffer trace, but here is my ble file transfer demo made from the keil ble uart demo for the nrf514 dev kit. file transfer demo code This code functions the same as the example but on receiving "Play" it sends over ble uint32_t values sequentially from 1 to 4096. The IOS demo code is created from the IOS-nRF-Toolbox-master with the only changed file being UARTViewController.m This file sets a ble_state var to 1 an initializes a uint32_t buffer for receiving the test data. Then it fills up that buffer with the test data and prints the results. For me, transfer speed is 4kb/s but each data slot is either correct or it is overwritten with a value that should come a little later with many slots duplicated.

Reply
  • I don't have the hardware to do a sniffer trace, but here is my ble file transfer demo made from the keil ble uart demo for the nrf514 dev kit. file transfer demo code This code functions the same as the example but on receiving "Play" it sends over ble uint32_t values sequentially from 1 to 4096. The IOS demo code is created from the IOS-nRF-Toolbox-master with the only changed file being UARTViewController.m This file sets a ble_state var to 1 an initializes a uint32_t buffer for receiving the test data. Then it fills up that buffer with the test data and prints the results. For me, transfer speed is 4kb/s but each data slot is either correct or it is overwritten with a value that should come a little later with many slots duplicated.

Children
No Data
Related