Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why hex values are not working with sdk example code "ble_app_uart" .

I am using running "ble_app_uart_c" example in my Central nrf52 DK board and ruuning "ble_app_uart" example in my peripheral nrf52 dk board..

IF I am sending ASCII values  ":16 03 00 00 00 02 E5 CR LF" from central dk , I can able to get in peripheral side like " :160300000002E5"

But if I send same values in hex i.e "16 03 00 00 00 02 C7 2C " from centrak dk , then in peripheral side I get   " Ç,".

I changed the code in central side like this because I want If in uart side it get 8byte it should send it via bluetooth.

'

void uart_event_handle(app_uart_evt_t * p_event)
{
static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
static uint16_t index = 0;
uint32_t ret_val;

switch (p_event->evt_type)
{
/**@snippet [Handling data from UART] */
case APP_UART_DATA_READY:
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 >= 8u)

{
NRF_LOG_DEBUG("Ready to send data over BLE NUS");
NRF_LOG_HEXDUMP_DEBUG(data_array, index);

do
{
ret_val = ble_nus_c_string_send(&m_ble_nus_c, data_array, index);
if ( (ret_val != NRF_ERROR_INVALID_STATE) && (ret_val != NRF_ERROR_RESOURCES) )
{
APP_ERROR_CHECK(ret_val);
}
} while (ret_val == NRF_ERROR_RESOURCES);

index = 0;
}
break;

"

and in peripheral side I change it to 

"

static void nus_data_handler(ble_nus_evt_t * p_evt)
{
static uint8_t index = 0;
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
{
err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
DataPos++;
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);
}*/
}

}

"

Parents Reply Children
No Data
Related