Hello,
I am trying to send data obtained from a SAADC port via BLE using the ble_nus_data_send function. This must happen periodically at frequencies within the Gigahertz range, ideally.
I started with the ble_app_uart example, from SDK16. Then, I initialized a timer using PPI to trigger an SAADC sampling event, such as in the saadc example.
Inside the saadc_callback function, I process the data and call the ble_nus_data_send function, as seen bellow:
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;
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
saadc2ble_convert();
uint16_t length = (uint16_t)UART_TX_BUF_SIZE;
err_code = ble_nus_data_send(&m_nus, adc_output, &length, m_conn_handle);
APP_ERROR_CHECK(err_code);
}
}
the saadc2ble_convert function simply converts the data from uint16_t to uint8_t and the length of the data transmitted via ble_nus_data_send function has not been modified from the initial example:
#define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
#define SAMPLES_IN_BUFFER UART_TX_BUF_SIZE/2
static nrf_saadc_value_t adc_buf[SAMPLES_IN_BUFFER]; //!< Buffer used for storing ADC value.
static uint8_t adc_output[UART_TX_BUF_SIZE]; //!< Current battery level.
void saadc2ble_convert(){
int i;
for(i=0; i<SAMPLES_IN_BUFFER; i++){
adc_output[i*2] = adc_buf[i] & 0xff;
adc_output[i*2 + 1] = (adc_buf[i] >> 8) & 0xff;
}
}
I initialize all in the main function as seen in the next code block:
int main(void)
{
bool erase_bonds;
ret_code_t err_code;
// Initialize.
uart_init();
log_init();
timers_init();
buttons_leds_init(&erase_bonds);
power_management_init();
ble_stack_init();
gap_params_init();
gatt_init();
services_init();
saadc_init();
saadc_sampling_event_init();
advertising_init();
conn_params_init();
// Start execution.
printf("\r\nUART started.\r\n");
NRF_LOG_INFO("Debug logging for UART over RTT started.");
advertising_start();
saadc_sampling_event_enable();
// Enter main loop.
for (;;)
{
idle_state_handle();
}
}
Debugging, I see that the SAADC is reading data well, however, I couldn't get any data at the smartphone.
I am getting the error shown on the image:
Could anyone help me to find a way to solve this problem?