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 Reply Children
Related