Hi. I will make clock.
I use RTC2 + Softdevice. (PCA10040 , NRF52832 , s132_nrf52_2.0.0_softdevice.hex )
Base Source code = nRF5_SDK_11.0.0_89a8197\examples\ble_peripheral\ble_app_uart
const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(2);
static void appRTCHandler(nrf_drv_rtc_int_type_t int_type)
{
if(int_type == NRF_DRV_RTC_INT_TICK)
{
LEDS_INVERT(BSP_LED_1_MASK);
}
}
void appRTCInit(void)
{
uint32_t err_code;
//Initialize RTC instance
err_code = nrf_drv_rtc_init(&rtc, NULL, appRTCHandler);
APP_ERROR_CHECK(err_code);
//Enable tick event & interrupt
nrf_drv_rtc_tick_enable(&rtc, true);
//Power on RTC instance
nrf_drv_rtc_enable(&rtc);
}
int main(void)
{
uint32_t err_code;
bool erase_bonds;
// Initialize.
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
uart_init();
buttons_leds_init(&erase_bonds);
LEDS_ON(BSP_LED_3_MASK);
ble_stack_init();
gap_params_init();
services_init();
advertising_init();
conn_params_init();
appRTCInit();
err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);
// Enter main loop.
for(;;)
{
power_manage();
}
}
LED0 Toggle is success.
but... not 125 msec.
tick time = 125.01ms or 125.21ms or 125.12ms ...(measurement by oscilloscope)
Why a such a result?
I need accurate time.
How do make accurate 125ms. or accurate 1sec.