1.在sdk_config.h中加入宏
// <e> COMP_ENABLED - nrf_drv_comp - COMP peripheral driver
//==========================================================
#ifndef COMP_ENABLED
#define COMP_ENABLED 1
#endif
// <o> COMP_CONFIG_REF - Reference voltage
// <0=> Internal 1.2V
// <1=> Internal 1.8V
// <2=> Internal 2.4V
// <4=> VDD
// <7=> ARef
#ifndef COMP_CONFIG_REF
#define COMP_CONFIG_REF 1
#endif
// <o> COMP_CONFIG_MAIN_MODE - Main mode
// <0=> Single ended
// <1=> Differential
#ifndef COMP_CONFIG_MAIN_MODE
#define COMP_CONFIG_MAIN_MODE 0
#endif
// <o> COMP_CONFIG_SPEED_MODE - Speed mode
// <0=> Low power
// <1=> Normal
// <2=> High speed
#ifndef COMP_CONFIG_SPEED_MODE
#define COMP_CONFIG_SPEED_MODE 2
#endif
// <o> COMP_CONFIG_HYST - Hystheresis
// <0=> No
// <1=> 50mV
#ifndef COMP_CONFIG_HYST
#define COMP_CONFIG_HYST 0
#endif
// <o> COMP_CONFIG_ISOURCE - Current Source
// <0=> Off
// <1=> 2.5 uA
// <2=> 5 uA
// <3=> 10 uA
#ifndef COMP_CONFIG_ISOURCE
#define COMP_CONFIG_ISOURCE 0
#endif
// <o> COMP_CONFIG_INPUT - Analog input
// <0=> 0
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7
#ifndef COMP_CONFIG_INPUT
#define COMP_CONFIG_INPUT 7
#endif
// <o> COMP_CONFIG_IRQ_PRIORITY - Interrupt priority
// <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// <0=> 0 (highest)
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7
#ifndef COMP_CONFIG_IRQ_PRIORITY
#define COMP_CONFIG_IRQ_PRIORITY 7
#endif
2.导入nrfx_comp.c到工程
3.comp事件处理函数
#include "nrf_drv_comp.h"
void comp_event_handler(nrf_comp_event_t evt)
{
printf("\r\ncomp_event_handler\r\n");
}
4.comp初时化使用
uint32_t err_code;
nrf_drv_comp_config_t comp_config = NRF_DRV_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_7);
comp_config.isource = NRF_COMP_ISOURCE_Ien5uA;
err_code = nrf_drv_comp_init(&comp_config, comp_event_handler);
nrf_drv_comp_start(NRF_DRV_COMP_EVT_EN_CROSS_MASK ,NRF_DRV_COMP_SHORT_STOP_AFTER_DOWN_EVT);