Hey Nordic,
Currently, I am working on a project based on "ble_app_uart" and "ble_app_uart_c". You can download the projects below:
- Central (nRF52833-DK):1462.ble_app_uart_c_copy.zip
- Peripheral (nRF52840-Preview-DK):5756.char_lorem.zip
I am using:
- VSCODE as IDE, and SDK 17.1.0
The central device currently connects to the peripheral one when the filter below is matched:
static ble_uuid_t const m_scan_uuid[] = {{BLE_UUID_OUR_CHARS_SERVICE, BLE_UUID_TYPE_VENDOR_BEGIN}/* ,
{BLE_UUID_NUS_SERVICE, BLE_UUID_TYPE_VENDOR_BEGIN} */};
Also, I have two flags:
static uint8_t flag_connected = 0; static uint8_t flag_discovered = 0;
I set them to 1 to detect both BLE_GAP_EVT_CONNECTED happened and the characteristic with the UUID that I am looking for is discovered in db_disc_handler(). Then I use both in idle_state_handle() as below:
/**@brief Function for handling the idle state (main loop).
*
* @details Handles any pending log operations, then sleeps until the next event occurs.
*/
static void idle_state_handle(void)
{
if (NRF_LOG_PROCESS() == false)
{
nrf_pwr_mgmt_run();
}
if(flag_connected == 1 && flag_discovered == 1)
{
writeChar(data);
NRF_LOG_INFO("data: %c: 0x%x", data, data);
flag_connected = 0;
flag_discovered = 0;
}
}
I do this in order to write some value into that specific discovered characteristic at the peripheral side. But BLE_GATTS_EVT_WRITE is not triggered and I cannot see the printout of the following block in PuTTY:
case BLE_GATTS_EVT_WRITE:
printf("BLE_GATTS_EVT_WRITE");
for(charIndex = 0; charIndex < NO_OF_CHARACTERISTICS; charIndex++)
{
if(p_ble_evt->evt.gatts_evt.params.write.uuid.uuid == BLE_UUID_OUR_CHARACTERISTC_UUID + charIndex)
{
NRF_LOG_INFO("16-bit UUID: 0x%x", p_ble_evt->evt.gatts_evt.params.write.uuid.uuid);
NRF_LOG_INFO("value = 0x%x%x%x%x", (p_ble_evt->evt.gatts_evt.params.write.data[0]),
(p_ble_evt->evt.gatts_evt.params.write.data[1]),
(p_ble_evt->evt.gatts_evt.params.write.data[2]),
(p_ble_evt->evt.gatts_evt.params.write.data[3]));
}
}
On the other hand, when I connect the peripheral with my phone on nRF Connect, I write some value into that characteristic, and then I can see the printout of the just-above block. Do you have any idea for resolving this issue?
I hope I have done a good job while explaining the issue.
Edit1: I have found an event called "BLE_GATTC_EVT_WRITE_RSP" from here. I used it at the central side under ble_evt_handler(). This is the RTT Viewer logging at the central side:
00> <info> app_timer: RTC: initialized. 00> 00> <info> app: NRF_BLE_SCAN_EVT_FILTER_MATCH 00> 00> <info> app: BLE_GAP_EVT_CONNECTED 00> 00> <info> app: ************************ 00> 00> <info> app: p_evt->evt_type: 0x0 00> 00> <info> app: srv_uuid.uuid: 0xF00D 00> 00> <info> app: srv_uuid.type: 2 00> 00> <info> app: char_count: 1 00> 00> <info> app: chars[0].char.uuid.uuid: 0xBEEF 00> 00> <info> app: write_params.len: 1 00> 00> <info> app: (custom_conn_handle: 0x0) Error: 0x5 00> 00> <info> app: sd_ble_gattc_write() returned: NRF_SUCCESS 00> 00> <info> app: data= U, 0x55 00> 00> <info> app: BLE_GATTC_EVT_WRITE_RSP 00> 00> <info> app: p_ble_evt->evt.gattc_evt.params.write_rsp.len= 0 00>
"BLE_GATTC_EVT_WRITE_RSP" occurs but since the data length is zero, I think the write operation couldn't be done successfully.
Edit2: Somehow, uploaded project files seemed to me not downloadable. Anyway, I uploaded them again, the change I did in Edit1 is also included at the central side.
Thanks in advance,
Omer