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

Parents Reply Children
  • I wonder that you had encoded the hrs heart rate data in TX side. So that the RX char notify received the encoded data are difference with TX

    I didn't check that.. I'll study again..

    This is my handler.. 

    static void data_level_meas_timeout_handler(void * p_context)
    {
        static uint32_t cnt = 0;
        ret_code_t      err_code;
    
        UNUSED_PARAMETER(p_context);
    
    //    heart_rate = (uint16_t)sensorsim_measure(&m_heart_rate_sim_state, &m_heart_rate_sim_cfg);
    
        cnt++;
        err_code = ble_nus_data_send_s(&m_nus, m_conn_handle);
        
        if ((err_code != NRF_SUCCESS) &&
            (err_code != NRF_ERROR_INVALID_STATE) &&
            (err_code != NRF_ERROR_RESOURCES) &&
            (err_code != NRF_ERROR_BUSY) &&
            (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
           )
        {
            APP_ERROR_HANDLER(err_code);
        }
    
        // Disable RR Interval recording every third heart rate measurement.
        // NOTE: An application will normally not do this. It is done here just for testing generation
        // of messages without RR Interval measurements.
        m_rr_interval_enabled = ((cnt % 3) != 0);
    }

  • Hi! Lyrics:

    Meet you again. I share the experience with you very usual. Your timer handler is okay. Howerver, it's not encoded data, if you apply ble_nus_data_send() function. But,...I don't know how may central or perpherial nodes you are. maybe there are more than on connection handle? How about the timeout period? 

  • Hi, Henry

    Howerver, it's not encoded data, if you apply ble_nus_data_send() function.

    So, do you mean I have to encode in the middle of the process to send the value I want?
    (as the hrs used the hrm_encode?)

    But,...I don't know how may central or perpherial nodes you are. maybe there are more than on connection handle? How about the timeout period? 

    I'm not sure I can understand. I just added a few things to the example of uart.. :) 

  • No.. you don't need to encode your heart rate data, But the data are quite different in TX & RX side. So that I suppose that maybe there are many centrals. Difference central will be the difference connect handle ID. If you send the data through NUS by timer, I think the data would be the same as the TX event.  

  • 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. :)

Related