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
  • 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. By the way, what's the timer handler function in your side? 

  • 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);
    }

Reply
  • 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);
    }

Children
Related