概述
一、
基础、环境搭建,sdk等仔细看 iini - 博客园
基础、环境搭建,sdk等仔细看 iini - 博客园
基础、环境搭建,sdk等仔细看 iini - 博客园
弃用nRFgo studio Nordic NRF51822 从零开始系列(一)开发环境的搭建_闲人-CSDN博客_nrf51822NRFGO STUDIO无法识别板子 – 电子创客营
关于nRF connect遇到的问题
nRF connect for Desktop 配置_MEMORY_2016的博客
C:Usersusername.nrfconnect-apps username->Administrator apps.json添加
{
"pc-nrfconnect-ble": {
"displayName": "Bluetooth Low Energy",
"description": "General tool for development and testing with Bluetooth Low Energy",
"homepage": "https://github.com/NordicSemiconductor/pc-nrfconnect-ble",
"url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/pc-nrfconnect-ble"
},
"pc-nrfconnect-rssi": {
"displayName": "RSSI Viewer",
"description": "Live visualization of RSSI per frequency for nRF52832",
"homepage": "https://github.com/NordicSemiconductor/pc-nrfconnect-rssi",
"url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/pc-nrfconnect-rssi"
},
"pc-nrfconnect-ppk": {
"displayName": "Power Profiler",
"description": "App for use with Nordic Power Profiler Kits",
"homepage": "https://github.com/NordicSemiconductor/pc-nrfconnect-ppk",
"url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/pc-nrfconnect-ppk"
},
"pc-nrfconnect-programmer": {
"displayName": "Programmer",
"description": "Tool for flash programming of nRF SoCs",
"homepage": "https://github.com/NordicSemiconductor/pc-nrfconnect-programmer",
"url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/pc-nrfconnect-programmer"
},
"pc-nrfconnect-linkmonitor": {
"displayName": "LTE Link Monitor",
"description": "Link monitor and AT command terminal",
"homepage": "https://github.com/NordicSemiconductor/pc-nrfconnect-linkmonitor",
"url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/pc-nrfconnect-linkmonitor"
},
"pc-nrfconnect-tracecollector": {
"displayName": "Trace Collector",
"description": "Capture nRF91 modem trace",
"homepage": "https://github.com/NordicSemiconductor/pc-nrfconnect-tracecollector",
"url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/pc-nrfconnect-tracecollector"
},
"pc-nrfconnect-tracecollector-preview": {
"displayName": "Trace Collector V2 preview",
"description": "EXPERIMENTAL: Capture and convert nRF91 modem traces",
"url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/pc-nrfconnect-tracecollector-preview"
},
"pc-nrfconnect-gettingstarted": {
"displayName": "Getting Started Assistant",
"description": "Guide to set up the nRF Connect SDK",
"homepage": "https://github.com/NordicSemiconductor/pc-nrfconnect-gettingstarted",
"url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/pc-nrfconnect-gettingstarted"
},
"pc-nrfconnect-dtm": {
"displayName": "Direct Test Mode",
"description": "RF PHY testing of Bluetooth Low Energy devices",
"homepage": "https://github.com/NordicSemiconductor/pc-nrfconnect-dtm",
"url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/pc-nrfconnect-dtm"
},
"pc-nrfconnect-toolchain-manager": {
"displayName": "Toolchain Manager",
"description": "Install and manage tools to develop with the nRF Connect SDK (NCS)",
"homepage": "https://github.com/NordicPlayground/pc-nrfconnect-toolchain-manager",
"url": "https://developer.nordicsemi.com/.pc-tools/nrfconnect-apps/pc-nrfconnect-toolchain-manager"
}
}
nRF Connect for Desktop下载程序初探_wxlscm的博客-CSDN博客
但是现在还是在nRF connect中无法检测到Jlink
安装nrf-connect 和 nrf-command-line-tools后 添加nrfjprog路径 C:Program FilesNordic Semiconductornrf-command-line-toolsbin 到系统环境变量 PATH (计算机属性->高级->环境变量->PATH)中
cmd中
nrfjprog --eraseall 擦除芯片
nrfjprog --verify --program your_softdevice_hex_file
keil编译下载应用程序
二、
蓝牙串口透传记录
1) 修改nordic串口透传服务为sig标准服务:
首先设置串口透传服务为sig标准服务
#define BLE_UUID_TYPE_BLE 0x01 // Bluetooth SIG UUID (16-bit) ble_types.h
#define NUS_SERVICE_UUID_TYPE BLE_UUID_TYPE_BLE //main.c
#define NUS_BASE_UUID {{0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}// ble_nus.c
ble_nus.h 中设置服务uuid
ble_nus.c 中设置uuid of tx rx characteristic
#define BLE_UUID_NUS_TX_CHARACTERISTIC 0xffe1 /**< The UUID of the TX Characteristic. */
#define BLE_UUID_NUS_RX_CHARACTERISTIC 0xffe2 /**< The UUID of the RX Characteristic. */
Nordic的NUS服务工程修改UUID为SIG UUID
2)
nrf52832 sdk 排错定位:
使能RTT LOG
keil添加DEBUG宏在J-LINK RTT VIEWER中可以收到debug打印信息
使能串口不使能RTT可以将debug信息打印至串口
debug排错定位参考
协议栈内存分配不够问题
Insufficient RAM allocated for the SoftDevice with Relay Application - Nordic Q&A - Nordic DevZone - Nordic DevZonex
3)
问题:keil下载程序到nrf52810中后有广播可以正常提供蓝牙服务,断电再上电后无蓝牙服务,keil再下载又有
DEBUG 下在jlink rtt viewer中收到打印debug信息报错位置在:
还有报错信息 NRF_ERROR_DATA_SIZE 12
nordic查找APP_UART_COMMUNICATION_ERROR
APP_UART_COMMUNICATION_ERROR
修改uart rx引脚为上拉,在nrfx_uart.c中修改
nrf_gpio_cfg_input(p_config->pselrxd, NRF_GPIO_PIN_PULLUP);
还是报错,发现uart rx 用的是dma,在nrfx_uarte.c中修改
nrf_gpio_cfg_input(p_config->pselrxd, NRF_GPIO_PIN_PULLUP);
程序运行正常,掉电上电后运行正常。分析问题原因是nordic sdk在初始化串口 rx 时设置nopull
在上电nrf52810时会对 rx 造成干扰,引起 APP_UART_COMMUNICATION_ERROR 报错
参考:
nRF52832频繁打印“APP_UART_COMMUNICATION_ERROR”的问题
nRF52832 频繁进入 app_error_fault_handler 定位方法
4)
上电设置ble fast advertising,设置由快速广播切换到慢速再到sleep
static void advertising_init(void)
{
uint32_t err_code;
ble_advertising_init_t init;
memset(&init, 0, sizeof(init));
init.advdata.name_type = BLE_ADVDATA_FULL_NAME;
init.advdata.include_appearance = false;
init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
init.srdata.uuids_complete.p_uuids = m_adv_uuids;
init.config.ble_adv_fast_enabled = true;
init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
init.config.ble_adv_fast_timeout = APP_ADV_DURATION;
init.config.ble_adv_slow_enabled = true;
init.config.ble_adv_slow_interval = APP_ADV_INTERVAL1;
init.config.ble_adv_slow_timeout = 0;// 0不进入sleep,一直慢速广播;任意非0时间代表慢速广播时长
init.evt_handler = on_adv_evt;
err_code = ble_advertising_init(&m_advertising, &init);
APP_ERROR_CHECK(err_code);
ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}
ble_nus.c中添加串口透传 rx tx 的 proprietary
// 添加RX特性
memset(&add_char_params, 0, sizeof(add_char_params));
add_char_params.uuid = BLE_UUID_NUS_RX_CHARACTERISTIC;//特性UUID
add_char_params.uuid_type = p_nus->uuid_type;//UUID类型
add_char_params.max_len = BLE_NUS_MAX_RX_CHAR_LEN;//最大的数据长度
add_char_params.init_len = sizeof(uint8_t);//初始化数据长度
add_char_params.is_var_len = true;//可变数据长度
add_char_params.char_props.write = 1;//写属性
add_char_params.char_props.write_wo_resp = 1;//没有回复的写
add_char_params.read_access = SEC_OPEN;//安全级别
add_char_params.write_access = SEC_OPEN;
err_code = characteristic_add(p_nus->service_handle, &add_char_params, &p_nus->rx_handles);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// 添加TX特性
/**@snippet [Adding proprietary characteristic to the SoftDevice] */
memset(&add_char_params, 0, sizeof(add_char_params));
add_char_params.uuid = BLE_UUID_NUS_TX_CHARACTERISTIC;//特性UUID
add_char_params.uuid_type = p_nus->uuid_type;//UUID类型
add_char_params.max_len = BLE_NUS_MAX_TX_CHAR_LEN;//最大数据长度
add_char_params.init_len = sizeof(uint8_t);//初始化长度
add_char_params.is_var_len = true;//数据长度可变
add_char_params.char_props.notify = 1;//通知
add_char_params.read_access = SEC_OPEN;
add_char_params.write_access = SEC_OPEN;
add_char_params.cccd_write_access = SEC_OPEN;//主机描述符
3个设置参数
#define APP_ADV_INTERVAL 40 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 25 ms). 快速广播*/
#define APP_ADV_INTERVAL1 80//慢速广播间隔
#define SLAVE_LATENCY 0 //从机潜伏时间间隔数
5)
蓝牙连接开灯,断开灭灯,在 处理ble event的回调函数中ble_evt_handler
case BLE_GAP_EVT_CONNECTED:
NRF_LOG_INFO("Connected");
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);//led on
APP_ERROR_CHECK(err_code);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
APP_ERROR_CHECK(err_code);
break;
case BLE_GAP_EVT_DISCONNECTED:
NRF_LOG_INFO("Disconnected");
// LED indication will be changed when advertising starts.
bsp_board_led_off(0);//led off
m_conn_handle = BLE_CONN_HANDLE_INVALID;
break;
6)
关于官方蓝牙透传demo接收完成判断问题:
if ((data_array[index - 1] == 'n') ||
(data_array[index - 1] == 'r') ||
(index >= m_ble_nus_max_data_len))//244字节
是通过接收到回车换行或者接收长度大于244字节来判断接收是否完成
更通用情况修改:
加定时器,超过30ms没接收到数据就判断接收完成
1.定义定时器句柄和超时处理函数
APP_TIMER_DEF(my_timer_id); //定义timer ID
uint16_t my_timer_ms_count;
bool my_timer_running;
static void my_timeout_handler(void *p_context)
{
//add your code here
my_timer_ms_count++;
}
2.创建用户定时器
uint32_t err_code = app_timer_create(&my_timer_id, APP_TIMER_MODE_REPEATED, my_timeout_handler);
APP_ERROR_CHECK(err_code);
my_timer_running = false;
3.串口接收event中处理代码,注意这里app_uart_get读取串口数据一定要放在前面,否则接收不到第一个字节
case APP_UART_DATA_READY://串口接收中断,PC发数据给从机
UNUSED_VARIABLE(app_uart_get(&data_array[index]));
index++;
if(!my_timer_running){
err_code = app_timer_start(my_timer_id, APP_TIMER_TICKS(10), NULL);
APP_ERROR_CHECK(err_code);
my_timer_running = true;
}
my_timer_ms_count = 0;
4.main中循环判断是否接收完成
if ((my_timer_ms_count >= 3) || (index >= m_ble_nus_max_data_len))//244字节
{
err_code = app_timer_stop(my_timer_id);
APP_ERROR_CHECK(err_code);
my_timer_running = false;
if (index > 1)
{
NRF_LOG_DEBUG("Ready to send data over BLE NUS");
NRF_LOG_HEXDUMP_DEBUG(data_array, index);
do
{
uint16_t length = (uint16_t)index;
err_code = ble_nus_data_send(&m_nus, data_array, &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);
}
} while (err_code == NRF_ERROR_RESOURCES);
}
index = 0;
}
7)
添加对串口AT指令AT+ADDR?rn的响应
if(!strncmp("AT+ADDR?rn", (char *)data_array, 10)){
for (uint32_t i = 1; i < sizeof(specific_addr); i++)
{
do
{
err_code = app_uart_put(*((uint8_t *)&specific_addr+i));//PC机打印,主机发过来的数据
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);
}
}
else{
do
{
uint16_t length = (uint16_t)index;
err_code = ble_nus_data_send(&m_nus, data_array, &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);
}
} while (err_code == NRF_ERROR_RESOURCES);
}
memset(data_array, 0, BLE_NUS_MAX_DATA_LEN);
比较函数strstr改为strncmp,严格对比
添加清BUFF函数,避免意外如第一次发AT_ADDR?rn第二次发AT+ADD也能读mac
mac地址设置 服务名设置 等 待补充
最后
以上就是跳跃抽屉为你收集整理的nrf51822 52832学习汇总的全部内容,希望文章能够帮你解决nrf51822 52832学习汇总所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复