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);
        }
}

Parents
  • And I found that, in nrfx_prs.c, NRF_COMP not define for NRF52820. 

    #elif defined(NRF52820_XXAA)
    // SPIM0, SPIS0, TWIM0, TWIS0, SPI0, TWI0
    #define NRFX_PRS_BOX_0_ADDR NRF_SPIM0
    // SPIM1, SPIS1, TWIM1, TWIS1, SPI1, TWI1
    #define NRFX_PRS_BOX_1_ADDR NRF_SPIM1
    // UARTE0, UART0
    #define NRFX_PRS_BOX_2_ADDR NRF_UARTE0

    #elif defined(NRF52832_XXAA) || defined(NRF52832_XXAB) || \
    defined(NRF52833_XXAA) || defined(NRF52840_XXAA)
    // SPIM0, SPIS0, TWIM0, TWIS0, SPI0, TWI0
    #define NRFX_PRS_BOX_0_ADDR NRF_SPIM0
    // SPIM1, SPIS1, TWIM1, TWIS1, SPI1, TWI1
    #define NRFX_PRS_BOX_1_ADDR NRF_SPIM1
    // SPIM2, SPIS2, SPI2
    #define NRFX_PRS_BOX_2_ADDR NRF_SPIM2
    // COMP, LPCOMP
    #define NRFX_PRS_BOX_3_ADDR NRF_COMP
    // UARTE0, UART0
    #define NRFX_PRS_BOX_4_ADDR NRF_UARTE0

Reply
  • And I found that, in nrfx_prs.c, NRF_COMP not define for NRF52820. 

    #elif defined(NRF52820_XXAA)
    // SPIM0, SPIS0, TWIM0, TWIS0, SPI0, TWI0
    #define NRFX_PRS_BOX_0_ADDR NRF_SPIM0
    // SPIM1, SPIS1, TWIM1, TWIS1, SPI1, TWI1
    #define NRFX_PRS_BOX_1_ADDR NRF_SPIM1
    // UARTE0, UART0
    #define NRFX_PRS_BOX_2_ADDR NRF_UARTE0

    #elif defined(NRF52832_XXAA) || defined(NRF52832_XXAB) || \
    defined(NRF52833_XXAA) || defined(NRF52840_XXAA)
    // SPIM0, SPIS0, TWIM0, TWIS0, SPI0, TWI0
    #define NRFX_PRS_BOX_0_ADDR NRF_SPIM0
    // SPIM1, SPIS1, TWIM1, TWIS1, SPI1, TWI1
    #define NRFX_PRS_BOX_1_ADDR NRF_SPIM1
    // SPIM2, SPIS2, SPI2
    #define NRFX_PRS_BOX_2_ADDR NRF_SPIM2
    // COMP, LPCOMP
    #define NRFX_PRS_BOX_3_ADDR NRF_COMP
    // UARTE0, UART0
    #define NRFX_PRS_BOX_4_ADDR NRF_UARTE0

Children
Related