This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Add NUS to ble_app_blinky (Error 0x4.)

ble_app_blinky_add_NUS.rar

building background :

SDK : 15.0

Development Kit: nrf52832 DK

IDE: Keil C

Softdevice: S132 

----------------------------------------------------------------------------------------------------------------------

Problem Description:

When NUS is added to blinky project , I could find  the UART service and characteristics  on nRF_connect interface.

But , When I sent message to DK, there is something wrong....

----------------------------------------------------------------------------------------------------------------------

Actions:

As title, I'd like to add NUS to ble_app_blinky. So, I took actions below :

1.Add ble_nus.c , include related paths and enable related sdk_configs.

2.Copy " part of "  ble_app_uart / main.c  code  to blinky project.

Copy part is shown below:

Header file and define  part:

Fullscreen
1
2
3
4
5
6
7
8
9
#include "ble_nus.h"
#include "app_uart.h"
#include "app_util_platform.h"
#include "ble_advertising.h"
#include "nrf_uart.h"
#if defined (UARTE_PRESENT)
#include "nrf_uarte.h"
#endif
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
#define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */
#define NUS_SERVICE_UUID_TYPE BLE_UUID_TYPE_VENDOR_BEGIN /**< UUID type for the Nordic UART Service (vendor specific). */
BLE_NUS_DEF(m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT); /**< Context for the Queued Write module.*/
//BLE_ADVERTISING_DEF(m_advertising);
static uint16_t m_ble_nus_max_data_len = BLE_GATT_ATT_MTU_DEFAULT - 3; /**< Maximum length of data (in bytes) that can be transmitted to the peer by the Nordic UART service module. */
static ble_uuid_t m_adv_uuids[] = /**< Universally unique service identifier. */
{
{BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

uart init  / uart Handler / gatt handler / nus handler part:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**@brief Function for handling the data from the Nordic UART Service.
*
* @details This function will process the data received from the Nordic UART BLE Service and send
* it to the UART module.
*
* @param[in] p_evt Nordic UART Service event.
*/
/**@snippet [Handling the data received over 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);
for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
{
do
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

service_init() part:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**@brief Function for initializing services that will be used by the application.
*/
static void services_init(void)
{
ret_code_t err_code;
ble_lbs_init_t init = {0};
nrf_ble_qwr_init_t qwr_init = {0};
// Initialize Queued Write Module.
qwr_init.error_handler = nrf_qwr_error_handler;
err_code = nrf_ble_qwr_init(&m_qwr, &qwr_init);
APP_ERROR_CHECK(err_code);
//MEM ERR
// Initialize LBS.
// init.led_write_handler = led_write_handler;
// err_code = ble_lbs_init(&m_lbs, &init);
// APP_ERROR_CHECK(err_code);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Also, I set the NRF_SDH_BLE_GATT_MAX_MTU_SIZE  to 247 , just like ble_app_uart project:

Fullscreen
1
2
3
4
// <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 23
#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 247
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

----------------------------------------------------------------------------------------------------------------------

I have surveyed on Nordic-devZone for a while, but got nothing. 

I will be appreciate if someone could give me a hand .  


UPDATE 2018/06/08  PM 9:00

I have tried using RTT viewer for recording logs. Here shows the result.


I sent "eee" strings  to DK but only the first "e" showed up .   


UPDATE 2018/06/09  PM 5:00

Uploaded my test project -  ble_app_blinky_add_NUS.rar