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

Send sensor SAADC data over BLE

Hey , i'm using nrf52832 with SDK 14.2 . I'm trying to send 3-axis accelerometer data through BLE . Is there any example for SDK 14.2 to achieve this ?

  • Hello,

    Sorry. I read the error wrong. It is of course 0x13 = 19, not 13.

    The return message is NRF_ERROR_RESOURCES.

    This means that the buffer is full. You have already queued the maximum amount of messages. 

    This is perfectly fine. You can add this to the if-check.

    if (err_code != NRF_ERROR_INVALID_STATE && err_code != NRF_ERROR_RESOURCES)
    {
        APP_ERROR_CHECK(err_code);
    }

    You should just be aware that the time that you call ble_nus_string_send() and it returns NRF_ERROR_RESOURCES, the message is not queued. At this point, you must wait for a BLE_GATTS_EVT_HVN_TX_COMPLETE event, which means that a message has been ACKed, and you can queue another message.

     

    So the issue is that you are trying to send data too fast. If it is ok to miss some packets, then you can ignore this. If you need to send this message, you can try to decrease the conn_interval, or increase the att_mtu size.

     

    You have already queued some packets. If you don't see them on the phone, it is because they didn't have time to be sent before the error handler kicked in.

     

    Best regards,

    Edvin

  • Thanks Edvin it worked . 
    Here there is one more problem . I am getting Garbage values in the array , where the data from the sensor is stored . 

    void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
    {
        if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
        {
            ret_code_t err_code;
            uint8_t value[BLE_NUS_MAX_DATA_LEN];
            static uint8_t index = 1;
    
            err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
            APP_ERROR_CHECK(err_code);
    
            int i;
    //        NRF_LOG_INFO("ADC event number: %d", (int)m_adc_evt_counter);
    
         for (i = 0; i < SAMPLES_IN_BUFFER; i++)
           {
    
                   value[0] = p_event->data.done.p_buffer[0] ;
                   printf(value);
                   
                
            }
                              
                                    uint16_t length = (uint16_t)index;
    
    				ble_nus_string_send(&m_nus, value, &length);
    //				if (err_code != NRF_ERROR_INVALID_STATE) 
    //				{
    //						APP_ERROR_CHECK(err_code);
    //				}
    						
            m_adc_evt_counter++;
        }
    }

    Screenshot :

  • Thanks Edvin , It worked.

    Here there is one more problem . When i print the value from sensor , it prints corrects . But when i store the data in array  , garbage value is stored . Here is the code and screenshot 

    void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
    {
        if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
        {
            ret_code_t err_code;
            uint8_t value[BLE_NUS_MAX_DATA_LEN];
            static uint8_t index = 1;
    
            err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
            APP_ERROR_CHECK(err_code);
    
            int i;
    //        NRF_LOG_INFO("ADC event number: %d", (int)m_adc_evt_counter);
    
         for (i = 0; i < SAMPLES_IN_BUFFER; i++)
           {
    
                  printf("x == %d\r\n", p_event->data.done.p_buffer[i]);
                   value[0] = p_event->data.done.p_buffer[0] ;
                   printf(value);
                   NRF_LOG_HEXDUMP_DEBUG(value, index);
                
            }
    
                                    uint16_t length = (uint16_t)index;
    
    				ble_nus_string_send(&m_nus, value, &length);
    //				if (err_code != NRF_ERROR_INVALID_STATE) 
    //				{
    //						APP_ERROR_CHECK(err_code);
    //				}
    						
            m_adc_evt_counter++;
        }
    }

  • Hello,

    I think you are trying to read the data in ascii format, while you send hexadecimal-values in the ADC handler.

    I would suggest that you try to convert the value into a string, if that is the way you would like to read it. You may also want to combine all the values from one event (SAMPLES_IN_BUFFER) to one string before sending, to avoid filling your buffer too fast.

     

    BR,

    Edvin

Related