This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

[ble_app_uart__saadc_timer_driven__scan_mode] Enter/exit sleep mode using bluetooth input

Hello 

I am still relatively new to microcontroller development with the NRF52 DK. I am currently running a modified version of ble_app_uart__saadc_timer_driven__scan_mode using 8 inputs instead of just 4.

From what I can tell, the program uses the board's buttons to put the microcontroller into sleep mode and wake it up. I was wondering if it is possible to modify this function so it can be controlled via a Bluetooth app on an Android phone, such as the Blinky app used with the BLE Blinky example. If sleep mode is not feasible (which I believe should disconnect the BLE connection), stopping the SAADC temporarily is also an alternative.

The idea of my project is that the microcontroller would scan data from sensors and transmit it to the Android app. The Android app would control when the scanning is active.

Any guidance would be appreciated. Thank you very much.

Parents
  • Hi,

    You are correct that the buttons are used for putting the device into sleep mode. This is handled by the BSP BLE Button Module. Depending on the state, the module might put the chip into system off sleep mode. It is not possible to wake up from this mode using BLE, as all radio and clock peripherals are disabled in this mode. You can put the chip into system on sleep mode using BLE, but this mode is normally used between all events/interrupts anyway. 

    You can stop SAADC/sampling from BLE. You can do things based on received commands in nus_data_handler, instead of passing the string to UART. To pause SAADC sampling, simply disable the PPI channel between the timer and sample event, or disable/pause the timer triggering the sampling. If you want to save power you should also uninitialize the SAADC when not sampling, as shown in the SAADC low power example.

    Best regards,
    Jørgen

Reply
  • Hi,

    You are correct that the buttons are used for putting the device into sleep mode. This is handled by the BSP BLE Button Module. Depending on the state, the module might put the chip into system off sleep mode. It is not possible to wake up from this mode using BLE, as all radio and clock peripherals are disabled in this mode. You can put the chip into system on sleep mode using BLE, but this mode is normally used between all events/interrupts anyway. 

    You can stop SAADC/sampling from BLE. You can do things based on received commands in nus_data_handler, instead of passing the string to UART. To pause SAADC sampling, simply disable the PPI channel between the timer and sample event, or disable/pause the timer triggering the sampling. If you want to save power you should also uninitialize the SAADC when not sampling, as shown in the SAADC low power example.

    Best regards,
    Jørgen

Children
  • Do you mind recommending me a good example of how nus_data_handler works, particularly how the MCU receives and processes commands? If possible, I would also like to see an Android example that sends the command to the MCU. Would there be something similar in the NRF Toolbox source code.

    Thank you about the advices on how to start/stop SAADC's operation. I can see that the SAADC low power example doesn't use SoftDevice. If my understanding is correct, I need to use SoftDevice to take advantage of the Bluetooth feature. Is there anything I should be aware of when trying to incorporate SAADC low power example's coding into my program? 

  • I don't know of any good examples, but it should be quite straight forward. Remove the for-loop that prints the received string to UART, and replace it with some memcmps that do things if the received string matches a predefined string:

    if(memcmp(p_evt->params.rx_data.p_data,"HELLO",5) == 0)
    {
        NRF_LOG_INFO("HelloWorld!");
    }
    else if(memcmp(p_evt->params.rx_data.p_data,"WORLD",5) == 0)
    {
        NRF_LOG_INFO("WorldHello!");
    }

    This function in the nRF Toolbox app could be used to send data using NUS. You should be able to reuse the UART libraries for your application.

    You do not need to implement all functionality from SAADC low power example. The most simples solution for you would most likely be to call nrf_drv_saadc_uninit when you stop sampling, and call your SAADC init function when you start it again. This should limit the current draw when there is no active sampling.

Related