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

52820 COMP interrupt problem

Hi, Friend, 

      I have a light sensor connected to P0.04/AIN2 on 52820, and use COMP to detect the change of voltage. 

      Here is my test code. When light change, the return value of nrfx_comp_sample() is correct (it can change between 0 and 1). 

      But if I channge the params of nrf_drv_comp_start(0, 0) to nrf_drv_comp_start(NRF_DRV_COMP_EVT_EN_DOWN_MASK | NRF_DRV_COMP_EVT_EN_UP_MASK, 0),  the RTT Viewer will printf sample value every 0.5s, but stoped (printing nothing) when AIN2 vlotage changed.  

      I suppose is the interrupt problem. What can I do next? Thank you.

void comp_event_handler(nrf_comp_event_t evt)
{
        NRF_LOG_INFO("VAL=%",evt);
}

void COMP_TEST()
{
        uint32_t err_code;
        nrf_drv_comp_config_t comp_config = NRF_DRV_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_2);

        comp_config.reference = 4; // <0=> Internal 1.2V, <1=> Internal 1.8V, <2=> Internal 2.4V, <4=> VDD, <7=> ARef
        comp_config.ext_ref = NRF_COMP_EXT_REF_0; // Use AIN0 as external analog reference.
        comp_config.main_mode = 0; /* // <0=> Single ended, <1=> Differential */
        comp_config.threshold.th_down = NRFX_VOLTAGE_THRESHOLD_TO_INT(1.0, 3.3);
        comp_config.threshold.th_up = NRFX_VOLTAGE_THRESHOLD_TO_INT(2.0, 3.3);
        comp_config.speed_mode = 2; // <0=> Low power, <1=> Normal, <2=> High speed
        comp_config.hyst = 0; // <0=> No, <1=> 50mV
        comp_config.interrupt_priority = 6;

        NRF_LOG_INFO("#####%d,%d,%d,%d,%d", comp_config.input, comp_config.reference, comp_config.threshold.th_down,
        comp_config.threshold.th_up, comp_config.interrupt_priority);
        err_code = nrf_drv_comp_init(&comp_config, comp_event_handler);
        nrf_drv_comp_start(0, 0);

        while (true)
        {
                NRF_LOG_INFO("VAL:%d", nrfx_comp_sample());
                NRF_LOG_FLUSH();
                nrf_delay_ms(500);
        }
}

Related