|
void init_timers(void) {
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
NRF_CLOCK->TASKS_HFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
{
}
NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;
NRF_TIMER1->PRESCALER = TIMER_PRESCALER;
NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
NRF_TIMER1->TASKS_CLEAR = 1; // Clear the timer
NRF_TIMER1->CC[2] = 0x01; //
NRF_TIMER1->INTENSET = TIMER_INTENSET_COMPARE2_Enabled << TIMER_INTENSET_COMPARE2_Pos;
NVIC_EnableIRQ(TIMER1_IRQn);
NRF_TIMER1->TASKS_START = 1;
}
void TIMER1_IRQHandler(void) {
if (NRF_TIMER1->EVENTS_COMPARE[2] == 1)
{
NRF_TIMER1->EVENTS_COMPARE[2] = 0; //clear interrupt
}
}
#define SOFTDEVICE_HANDLER_INIT(CLOCK_SOURCE, \
USE_SCHEDULER) \
do \
{ \
static uint32_t EVT_BUFFER[CEIL_DIV(MAX( \
MAX(BLE_STACK_EVT_MSG_BUF_SIZE, \
ANT_STACK_EVT_STRUCT_SIZE), \
SYS_EVT_MSG_BUF_SIZE \
), \
sizeof(uint32_t))]; \
uint32_t ERR_CODE; \
ERR_CODE = softdevice_handler_init((CLOCK_SOURCE), \
EVT_BUFFER, \
sizeof(EVT_BUFFER), \
(USE_SCHEDULER) ? softdevice_evt_schedule : NULL); \
APP_ERROR_CHECK(ERR_CODE); \
} while (0)
开启timer1的话,ERR_CODE返回1001,无法开启蓝牙服务
关闭TIMER1的话,蓝牙服务就正常了。
但是单独运行timer的话又是正确的。
求解
|
|