Is there a way to turn off the BLE NUS service once we are done with and turn it back on when we need it? I tried
NRF_UART0->TASKS_STOPTX = 1;
NRF_UART0->TASKS_STOPRX = 1;
NRF_UART0->ENABLE = 0;
Seems to have had no effect. I am using the BLE NUS service here, as you can see I turn off my ADC when done with it, I want to do the same to BLE NUS.
void saadc_callback(nrf_drv_saadc_evt_t const *p_event) {
////NRF_LOG_INFO("SAADC callback\r\n");
if (p_event->type == NRF_DRV_SAADC_EVT_DONE) //Capture offset calibration complete event
{
ret_code_t err_code;
LEDS_INVERT(BSP_LED_1_MASK); //Toggle LED2 to indicate SAADC buffer full
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER); //Set buffer so the SAADC can write to it again. This is either "buffer 1" or "buffer 2"
APP_ERROR_CHECK(err_code);
static uint16_t adc_value;
static uint16_t adc_len;
for (uint8_t i = 0; i < p_event->data.done.size; i++) {
adc_value = p_event->data.done.p_buffer[i];
adc_len = sizeof(adc_value);
err_code = ble_nus_data_send(&m_nus, (uint8_t *)&adc_value, &adc_len, m_conn_handle);
if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) &&
(err_code != NRF_ERROR_NOT_FOUND)) {
APP_ERROR_CHECK(err_code);
}
}
nrf_drv_saadc_uninit(); //Unintialize SAADC to disable EasyDMA and save power
NRF_SAADC->INTENCLR = (SAADC_INTENCLR_END_Clear << SAADC_INTENCLR_END_Pos); //Disable the SAADC interrupt
NVIC_ClearPendingIRQ(SAADC_IRQn); //Clear the SAADC interrupt if set
m_saadc_initialized = false; //Set SAADC as uninitialized
}
}
Or maybe I should just make a notify characteristic to send out my values instead of using UART? I mean does BLE NUS UART use less power than a characteristic e.g. heart rate?