1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #include "rtc.h"
- #include "stm32f4xx_hal.h"
- void RTC_Init()
- {
- /* Peripheral clock enable */
- __HAL_RCC_RTC_ENABLE();
- /* Peripheral interrupt init*/
- HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 7, 0);
- HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
- /* Check if the Initialization mode is set */
- if((RTC->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
- {
- /* Set the Initialization mode */
- RTC->ISR = (uint32_t)RTC_INIT_MASK;
- /* Wait till RTC is in INIT state and if Time out is reached exit */
- while((RTC->ISR & RTC_ISR_INITF) == (uint32_t)RESET);
- }
- /* Clear RTC_CR FMT, OSEL and POL Bits */
- RTC->CR &= ((uint32_t)~(RTC_CR_FMT | RTC_CR_OSEL | RTC_CR_POL));
- /* Set RTC_CR register */
- RTC->CR |= (uint32_t)(RTC_HOURFORMAT_24 | RTC_OUTPUT_DISABLE | RTC_OUTPUT_POLARITY_HIGH);
- /* Configure the RTC PRER */
- RTC->PRER = (uint32_t)(255);
- RTC->PRER |= (uint32_t)(127 << 16);
- /* Exit Initialization mode */
- RTC->ISR &= (uint32_t)~RTC_ISR_INIT;
- RTC->TAFCR &= (uint32_t)~RTC_TAFCR_ALARMOUTTYPE;
- RTC->TAFCR |= (uint32_t)(RTC_OUTPUT_TYPE_OPENDRAIN);
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
- /**Enable the WakeUp
- */
- //HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 59, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
- }
|