Hello.
I'm using nrf52840 to sample the voltage from the wireless board and then send the data to the PC via Bluetooth.
With the help of DevZone, it was able to construct a fundamental system, so I'm trying to add some additional features.
I tested whether I can transmit some messages while the 20 kHz sampled data are transmitted through Bluetooth. And the result seems it works which means the PC can control the wireless board with commands.
For now, I want to control the SAADC channel with a simple command. To be more specific, I want to change which SAADC channel to sample. The current version of the code samples pre-determined single channel and I have to re-upload the code to change the channel.
My idea is that if I send '7' from the PC, then the AIN5 channel is sampled continuously. Similarly, '9' for the AIN7 and '4' to stop sampling.
To do so, I modified a nus_data_handler function that is used to handle BLE data in the ble_peripheral\ble_app_uart example. Following is the modified code.
static void nus_data_handler(ble_nus_evt_t * p_evt) { if (p_evt->type == BLE_NUS_EVT_RX_DATA) { uint32_t err_code; switch (p_evt->params.rx_data.p_data[0]) { case '4': // Stop recording err_code = nrf_drv_saadc_channel_uninit(0); APP_ERROR_CHECK(err_code); break; case '7': // Record channel 1 err_code = nrf_drv_saadc_channel_uninit(0); APP_ERROR_CHECK(err_code); nrf_saadc_channel_config_t channel_config7 = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5); // Pin 10 //channel_config.acq_time = NRF_SAADC_ACQTIME_10US; // Default is 10us err_code = nrf_drv_saadc_channel_init(0, &channel_config7); APP_ERROR_CHECK(err_code); break; case '9': // Record channel 2 err_code = nrf_drv_saadc_channel_uninit(0); APP_ERROR_CHECK(err_code); nrf_saadc_channel_config_t channel_config9 = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN7); // Pin 12 err_code = nrf_drv_saadc_channel_init(0, &channel_config9); APP_ERROR_CHECK(err_code); break; } } }
I thought the nrf_drv_saadc_channel_uninit function stops sampling and I can change the channel by initiating the SAADC with a changed config.
But when I run this code and send a command from the PC, it stops.
If I send '1' or 'a', the board gets '1' or 'a' and the code keeps running. But when I send '4', '7', '8', the code is rebooted.
I'm not sure why this happens and how can I get what I deserve. Is there any way to do that?