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

How can I merge the Csense_drv and saadc application together?

Hello,

I am trying to sample capacitance change as well as voltage change from sensors. I combined the simplified sample codes from Csense_drv and saadc sample. If I only enable either csense_drv or saadc, I can read value. But if I combine them together, I always get "fatal" error. I understand csense_drv also use saadc (I disable COMP) but don't know where the conflict/problem is.

Can anybody take a look at my [source] file?

Thanks a lot! -Lei

Parents
  • You are initializing the saadc driver, then starting a repeating timer that does sampling, and then you uninitialize the saadc driver. When the timer times out, it will try to sample the saadc, but the saadc driver is not initialized, which is why you get the NRF_ERROR_INVALID_STATE (from call to nrf_drv_saadc_sample() in saadc_timeout_handler(). Csense is not initialized in this code at all, but if it was, initialization of saadc would return an error, as the csense driver have already initialized the saadc driver. You need to init the drivers before each sampling and uninit when sampling is done, to get this to work.

    You could init the saadc once and use this for both csense and other sampling, the problem is to keep track of what sampled value is for which use case. The csense driver is not written for supporting this, meaning you would have to modify the driver to do this.

Reply
  • You are initializing the saadc driver, then starting a repeating timer that does sampling, and then you uninitialize the saadc driver. When the timer times out, it will try to sample the saadc, but the saadc driver is not initialized, which is why you get the NRF_ERROR_INVALID_STATE (from call to nrf_drv_saadc_sample() in saadc_timeout_handler(). Csense is not initialized in this code at all, but if it was, initialization of saadc would return an error, as the csense driver have already initialized the saadc driver. You need to init the drivers before each sampling and uninit when sampling is done, to get this to work.

    You could init the saadc once and use this for both csense and other sampling, the problem is to keep track of what sampled value is for which use case. The csense driver is not written for supporting this, meaning you would have to modify the driver to do this.

Children
No Data
Related