项目的硬件说明
此工程 SDK的版本为 nRF5_SDK_17.0.2_d674dde
以下工程都是以IAR for arm V8.32.1
以下的电流分析仪为:PM132A
BLE Beacon 项目(nRF52840)
官方工程的功耗
Beacon 关Log
Beacon 广播间隔
//#define NON_CONNECTABLE_ADV_INTERVAL MSEC_TO_UNITS(100, UNIT_0_625_MS) /**< The advertising interval for non-connectable advertisement (100 ms). This value can vary between 100ms to 10.24s). */ #define NON_CONNECTABLE_ADV_INTERVAL MSEC_TO_UNITS(500, UNIT_0_625_MS) /**< The advertising interval for non-connectable advertisement (500 ms). This value can vary between 100ms to 10.24s). */
Beacon的发射功率
static void advertising_init(void) { ... err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params); APP_ERROR_CHECK(err_code); //设置 tx db err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, 0,8); APP_ERROR_CHECK(err_code); }
发射功率总结:
DCDC
ble_stack_init(); //在 stack 的 初始化后,立马打开。 sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE); sd_power_dcdc0_mode_set(NRF_POWER_DCDC_ENABLE);
32.768K 晶体功耗
BLE Uart 工程 (nRF52832)
官方工程广播功耗
官方工程连接功耗
串口功耗优化
int main(void) { bool erase_bonds; // Initialize. //uart_init(); //注释了uart log_init(); timers_init(); buttons_leds_init(&erase_bonds); power_management_init(); ble_stack_init(); gap_params_init(); gatt_init(); services_init(); advertising_init(); conn_params_init(); // 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(); } }
//BLE 接收 static void nus_data_handler(ble_nus_evt_t * p_evt) { if (p_evt->type == BLE_NUS_EVT_RX_DATA) { uint32_t err_code; NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART."); NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length); #if 0 //关闭BLE接口转串口的代码 for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++) { do { err_code = app_uart_put(p_evt->params.rx_data.p_data[i]); if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY)) { NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code); APP_ERROR_CHECK(err_code); } } while (err_code == NRF_ERROR_BUSY); } if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r') { while (app_uart_put('\n') == NRF_ERROR_BUSY); } #endif } }
广播间隔与关闭Log的优化
#define APP_ADV_INTERVAL MSEC_TO_UNITS(300, UNIT_0_625_MS) //广播间隔300ms
power_management_init(); ble_stack_init(); //sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE); //由于硬件无法支持DCDC,所以无法打开进行测试。
连接间隔的设置
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(200, UNIT_1_25_MS) /**< Minimum acceptable connection interval (200 ms), Connection interval uses 1.25 ms units. */ #define MAX_CONN_INTERVAL MSEC_TO_UNITS(500, UNIT_1_25_MS) /**< Maximum acceptable connection interval (500 ms), Connection interval uses 1.25 ms units. */
3个广播通道的广播电流
标签:
#NRF52840#