当前位置:网站首页>Nrf52832 -- official routine ble_ app_ UART adds the LED feature to enable the computer UART and mobile app to control the LED on and off of the development board
Nrf52832 -- official routine ble_ app_ UART adds the LED feature to enable the computer UART and mobile app to control the LED on and off of the development board
2022-06-12 05:46:00 【m0_ seven thousand seven hundred and eighty-eight】
Hardware :nrf52832 Development board
Software : Compile environment :keil, SDK edition :nRF5_SDK_17.1.0_ddde560, Protocol stack version :s132_nrf52_7.2.0_softdevice
Realization function : In the official serial port routine ble_app_uart Add a feature based on , Used to control the led.
1. adopt nRF Connect official APP Of RX Characteristic Write 1, control led2 bright , Write 0 control led destroy
2.win Computer serial assistant custom communication protocol ,TX Hair 16 Base number aa01 control led2 bright ,16 Base number aa00 control led destroy
stay nodic official ble_app_uart There is no need to add other driver component libraries in , The above functions can be achieved by adding at the following location ( Bold is the new part ).
#define BLE_UART_LED
services_init register NUS,nus_init.data_handler = nus_data_handler;
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("nus_data_handler: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);
****#ifdef BLE_UART_LED
if (p_evt->params.rx_data.p_data[0] == '1') // Custom communication protocol on
{
bsp_board_led_on(LED_2);
NRF_LOG_INFO("led2 is open");
}
else if(p_evt->params.rx_data.p_data[0] == '0') // Custom communication protocol off
{
bsp_board_led_off(LED_2);
NRF_LOG_INFO("led2 is close");
}
#endif //BLE_UART_LED****
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);
}
}
}
uart_init Of APP_UART_FIFO_INIT call uart_event_handle,
void uart_event_handle(app_uart_evt_t * p_event)
{
static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
static uint8_t index = 0;
uint32_t err_code;
switch (p_event->evt_type)
{
case APP_UART_DATA_READY:
//data_array[index] Get the data sent from the computer serial port
UNUSED_VARIABLE(app_uart_get(&data_array[index]));
index++;
if ((data_array[index - 1] == '\n') ||
(data_array[index - 1] == '\r') ||
(index >= m_ble_nus_max_data_len))
{
if (index > 1)
{
NRF_LOG_DEBUG("uart_event_handle:Ready to send data over BLE NUS");
NRF_LOG_HEXDUMP_DEBUG(data_array, index);
****#ifdef BLE_UART_LED
if (data_array[0] == 0xaa && data_array[1] == 0x01) // Custom communication protocol on
{
pte_led_on(LED_3);
}
else if(data_array[0] == 0xaa && data_array[1] == 0x00) // Custom communication protocol off
{
pte_led_off(LED_3);
}
#endif //BLE_UART_LED****
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; // Clear the array subscript after sending data . To continue caching subsequent serial port data .
}
break;
case APP_UART_COMMUNICATION_ERROR:
APP_ERROR_HANDLER(p_event->data.error_communication);
break;
case APP_UART_FIFO_ERROR:
APP_ERROR_HANDLER(p_event->data.error_code);
break;
default:
break;
}
}
边栏推荐
- C语言-数组的定义方式
- FPGA语法的细节
- Laravel8 when search
- Nature | make an account of the new crown casualties in the world
- Towards End-to-End Lane Detection: an Instance SegmentationApproach
- Go interface implementation principle [advanced level]
- 按键精灵的简单入门
- Redis cache data consistency and problems
- CODIS long link test
- Conversion of Halcon 3D depth map to 3D image
猜你喜欢

Available RTMP and RTSP test addresses of the public network (updated in March, 2021)

POI, easyexcel framework use

Details of FPGA syntax

DMA RDMA technology details

分公司负责人需要承担的法律责任

登录验证过滤器

RTMP streaming +rtmp playback low delay solution in unity environment

Chapter 7 - pointer learning

CCF noi2022 quota allocation scheme

What is the difference between ArrayList and LinkedList?
随机推荐
Lock and reentrankload
China embolic coil market trend report, technical innovation and market forecast
38. 外观数列
AddUser add user and mount hard disk
Introduction to Internet Protocol
Chapter 7 - pointer learning
About architecture (in no particular order)
Word frequency statistics using Jieba database
Is the individual industrial and commercial door a legal person enterprise
Role and understanding of proc/cmdline
Lesson 5: data warehouse construction (III)
Mysql笔记
Halcon 3D 1 读取3d数据
tkinter使用WebView2网页组件(续篇)
[daily question on niuke.com] two point search
arp timer and arptables
How Wireshark decrypts WiFi data packets
[GPIO] 如何通过adb shell 修改/显示 GPIO 状态
March 23, 2021
[untitled]