NRF52810 transmission rate test

NRF52810 transmission speed test

Recently, there was a project to use the NRF52810 Bluetooth IC, so I bought a board to test. The current demand of the project is not very high, and the transmission speed can reach 1KB/S. The test results of everyone on the Internet are very good. It can be tested to 80KB/S in 1M mode, so I also want to try and learn from others' methods,
The preliminary test idea is as follows: send 244 bytes every 10ms, and then send them 100 times continuously. In this case, it is just 1 second, and then the transmission speed is 100*244 = 24400B/S. then, just shorten the packet interval to improve the theoretical transmission rate.
So I did it.
I Environment construction
To build a test environment, I mainly refer to this article: Teach you to develop your own BLE
The main idea is to make some changes according to this article. If the environment needs to be changed, when NRF52810 opens the project, open the project under 10040e, and NRF52832 is 10040.
After reading many blogs on the Internet, the main parameters you have modified are:
1. Increase the MTU on the sdk_config.h

// <o> NRF_SDH_BLE_GATT_MAX_MTU_SIZE - Static maximum MTU size. 
#ifndef NRF_SDH_BLE_GATT_MAX_MTU_SIZE
#define NRF_ SDH_ BLE_ GATT_ MAX_ MTU_ Size 247 / / MTU size
#endif

2. Increase the DLE on the sdk_config.h

// <i> Requested BLE GAP data length to be negotiated.

#ifndef NRF_SDH_BLE_GAP_DATA_LENGTH
#define NRF_ SDH_ BLE_ GAP_ DATA_ Length / / length
#endif

3. Open CLE in main The following code is added to C and initialized behind the Bluetooth protocol stack

//When status is true, open CLE
void conn_evt_len_ext_set(bool status)
{
    ret_code_t err_code;
    ble_opt_t  opt;

    memset(&opt, 0x00, sizeof(opt));
    opt.common_opt.conn_evt_ext.enable = status ? 1 : 0;

    err_code = sd_ble_opt_set(BLE_COMMON_OPT_CONN_EVT_EXT, &opt);
    APP_ERROR_CHECK(err_code);
}

4. Definition of connection event length. Here, I set 800 on the sdk_config.h

// <o> NRF_SDH_BLE_GAP_EVENT_LENGTH - GAP event length. 
// <i> The time set aside for this connection on every connection interval in 1.25 ms units.

#ifndef NRF_SDH_BLE_GAP_EVENT_LENGTH
#define NRF_SDH_BLE_GAP_EVENT_LENGTH 800     

5. Adjust the connection time interval in main C medium

#define MIN_CONN_INTERVAL               MSEC_TO_UNITS(8, UNIT_1_25_MS)             /**< Minimum acceptable connection interval (20 ms), Connection interval uses 1.25 ms units. */
#define MAX_CONN_INTERVAL               MSEC_TO_UNITS(12, UNIT_1_25_MS)             /**< Maximum acceptable connection interval (75 ms), Connection interval uses 1.25 ms units. */

II Hardware and software preparation
1. Hardware preparation
One NRF52810 module.
Support Bluetooth 1M mode and one mobile phone with 2M mode. I use HUAWEI P40 PRO here.
2. Software preparation
Open the official routine_ app_ UART, modify and add the code snippet in Chapter 1.
Create a test timer in main Add the following code to C

/**@brief CreateTestTimer
 */
void CreateTestTimer(void)
{
  app_timer_create(&s_testTimer, APP_TIMER_MODE_REPEATED, timer_testCallback);
	app_timer_start(s_testTimer, APP_TIMER_TICKS(10), NULL);   // 10ms timer
}

Add timer callback function in main Add the following code to C

/**
 @brief 
 @param 
 @return 
*/
static void timer_testCallback(void *arg)
{
	UNUSED_PARAMETER(arg);
	nrf_ble_speed_test();   // Transmission speed test
}

Add speed test function in main Add the following code to C

/**
 @brief 
 @param 
 @return 
*/
void nrf_ble_speed_test(void)
{
	static uint16_t DEBUG_CNT1 =0,DEBUG_CNT2 = 0;
	uint32_t   err_code;
	uint16_t   length = 244;  // Data length of each packet
	static uint8_t   head_data =0;
	uint8_t buf[255];
	DEBUG_CNT1 ++;
	if(1){
	    // Head and tail data amplitude
		head_data ++;
		if(head_data == 254)head_data = 0;
		buf[0]=head_data;
		buf[length-1]=head_data;
		// send data
		err_code = ble_nus_data_send(&m_nus, buf,&length, m_conn_handle);
		if ((err_code != NRF_ERROR_INVALID_STATE) &&
				(err_code != NRF_ERROR_RESOURCES) &&
				(err_code != NRF_ERROR_NOT_FOUND))
		{
				APP_ERROR_CHECK(err_code);
		}
		// Judge whether the data is sent successfully. If it is successful, the number of successful times will be increased by one
		if(err_code == NRF_SUCCESS){
			DEBUG_CNT2 ++;
		}
	}
	// Enter every 10ms and calculate the theoretical transmission speed and actual transmission speed within 1s
	if(DEBUG_CNT1 == 100){
		NRF_LOG_INFO("SUCCES Num = %d Theoretical speed = %d B/s Actual speed = %d B/s",DEBUG_CNT2,(DEBUG_CNT1*length),(DEBUG_CNT2*length));
		DEBUG_CNT1 = 0;
		DEBUG_CNT2 = 0;
	}
}

Overview of main functions

/**@brief Application main function.
 */
int main(void)
{
//	bool erase_bonds;
	uint8_t int_stu = 0;
	// Initialize.
	uart_init();                        // Serial port initialization
	log_init();                         // LOG print initialization optional UART/RTT
	timers_init();                      // timer initialization is used to generate low-power timers
	buttons_leds_init(&erase_bonds);  // Key and LED initialization, defining key and LED functions
	power_management_init();            // The low-power management module initializes and enables the device to automatically enter the low-power mode through software
	ble_stack_init();                   // Protocol initialization, Bluetooth protocol stack and its configuration
	conn_evt_len_ext_set(1);            // Enable CLE function
	gap_params_init();                  // GAP parameter initialization is used to modify the broadcast name and connection interval
	gatt_init();                        // GATT parameter initialization is used to modify the underlying packet length
	services_init();                    // Add Bluetooth SERVER and CHARACTERISTIC
	advertising_init();                 // Broadcast parameter initialization is used to modify broadcast content, broadcast interval and broadcast timeout
	conn_params_init();                 // Used to request update connection interval
	// by maozhi 20220127
	CreateTestTimer();     // Initialization timer
	// Start execution.
//	printf("\r\nUART started.\r\n");
	NRF_LOG_INFO("Debug logging for UART over RTT started.");
	advertising_start();

	// Enter main loop.
	for (;;)
	{
		idle_state_handle();
	}
}

III Test and results
Download the code to the development board and start printing the following LOG

As shown in the figure above, when the mobile phone is not connected, the number of successful packets sent is 0, the theoretical speed is 24400B/S, and the actual speed is 0. Open the mobile phone and connect the module with BLE debugging assistant. When BLE software is opened for the first time, it defaults to 1M mode, and then the following results are measured
It can be seen that the number of successful sending is about 60 times per second, and the maximum rate is about 16KB/S. however, there is still a gap between the theory that 100 packets should be sent, and the rate is 24400B/S, indicating that many packets are not sent successfully.
Then I try to turn on the 2M mode of BLE and click three points in the upper right corner

Check LE 2M, then click SET, and then open the notification. The following test results are obtained


It can be seen that the maximum actual speed has reached 24156B/S, and the number of packets successfully sent has reached 99, but packets are still lost. The average speed is about 23KB/S. indeed, packet loss in 2M mode is less than that in 1M mode.
The current test results are like this, and the results measured by different mobile phones will be different. I used another mobile phone of different models to test, but the speed is much slower.
Finally, due to the problem of time, I won't go deep into it first. The boss should fire me. If you have had a test in a similar environment and the test results are very close to the theoretical value of Bluetooth, please comment below. I will share the corrected test results and methods one day in the future.
The first blog, welcome to correct, thank you.

Keywords: C Single-Chip Microcomputer IoT

Added by Ekate on Sat, 29 Jan 2022 21:42:07 +0200