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

How to receive data in the correct format when sending data to the app_timer

Hi, all

I'm using nRF52832 pca10040, s132.

Like 'ble_app_hrs' example, I changed the 'ble_app_uart' example to send data using app_timer.

In the example of 'hrs', they changed Hexa to Decimal using 'hrm_encode'. Am I right?

But what I want is.. when I send decimal data, I want 'uart_c' to receive the same decimal data.

'uart_c' successfully receive data but cannot read correctly.

I want to know why.

And I also want to understand things like situations that are transformed in the process of sending and receiving data.

This is uart example. (I added)

uint8_t           heart_rate;

heart_rate = 123;
len = sizeof(heart_rate);

memset(&hvx_params, 0, sizeof(hvx_params));

hvx_params.handle = p_nus->tx_handles.value_handle;
hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
hvx_params.offset = 0;
hvx_params.p_len  = len;
hvx_params.p_data = heart_rate;

err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params);

and I edited 'uart_c' example like this..

static void ble_nus_chars_received_uart_print(uint8_t * p_data, uint16_t data_len)
{
    ret_code_t ret_val;

    NRF_LOG_DEBUG("Receiving data.");
    NRF_LOG_HEXDUMP_DEBUG(p_data, data_len);

    for (uint32_t i = 0; i < data_len; i++)
    {
          printf("%d\r\n", p_data[i]);
//        do
//        {
//            ret_val = app_uart_put(p_data[i]);
//            if ((ret_val != NRF_SUCCESS) && (ret_val != NRF_ERROR_BUSY))
//            {
//                NRF_LOG_ERROR("app_uart_put failed for index 0x%04x.", i);
//                APP_ERROR_CHECK(ret_val);
//            }
//        } while (ret_val == NRF_ERROR_BUSY);
    }
    
    ....
    
}

This is result.

I think this is how it should be done. )

tx_evt

1

2

0

Best Regards,

lyrics

  • I understand.. There is only one connection handle.. 0x0. (ble_app_uart_c)

    I think the data would be the same as the TX event.  

    Does this mean that the central should modify the data encode of the TX side?
    If correct, I modified the ' ble_nus_chars_received_uart_print ' function of uart_c.

    Just like this..

     for (uint32_t i = 0; i < data_len; i++)
        {
              printf("%d \r\n", p_data[i]);
    //        do
    //        {
    //            ret_val = app_uart_put(p_data[i]);
    //            if ((ret_val != NRF_SUCCESS) && (ret_val != NRF_ERROR_BUSY))
    //            {
    //                NRF_LOG_ERROR("app_uart_put failed for index 0x%04x.", i);
    //                APP_ERROR_CHECK(ret_val);
    //            }
    //        } while (ret_val == NRF_ERROR_BUSY);
        }

    Or maybe I'm wrong to make this change.

    Thank you in advance. :)

  • Hello,

    I don't see any data being passed to ble_nus_data_send_s(), only the service structure and connection handle. Can you post your implementation of this function as well?

  • sorry for late reply..

    Is this right what you said,,?

    static void data_level_meas_timeout_handler(void * p_context)
    {
        static uint32_t cnt = 0;
        ret_code_t      err_code;
    
        UNUSED_PARAMETER(p_context);
    
        cnt++;
        err_code = ble_nus_data_send_s(&m_nus, m_conn_handle);
        
        ...
    }

    uint32_t ble_nus_data_send_s(ble_nus_t * p_nus, uint16_t conn_handle)
    {
        uint32_t err_code;
        ble_gatts_hvx_params_t     hvx_params;
        // Send value if connected and notifying
        if (conn_handle != BLE_CONN_HANDLE_INVALID)
        {
            uint8_t          len;
            uint16_t         heart_rate;
    
            heart_rate = 123;
            len = sizeof(heart_rate);
            
            memset(&hvx_params, 0, sizeof(hvx_params));
    
            hvx_params.handle = p_nus->tx_handles.value_handle;
            hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
            hvx_params.offset = 0;
            hvx_params.p_len  = len;
            hvx_params.p_data = heart_rate;
    
    
            err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params);
            return err_code;
        }
    }

  • I solved this problem using hrm_encode function... :)

Related