Loading...
 

System Workbench for STM32


Need help with RTC from LSE and exit from stop mode when SLEEPDEEP bit set

//
void rtc_isr(void){
bitclr(GPIOA->ODR,GPIO_ODR_ODR3); //led off
bitclr(RTC->CRL,RTC_CRL_ALRF);
bitset(EXTI->PR,EXTI_LINE_RTCALARM);
}

//use HSI default
int main(void) {

// led
//PORTA
bitset(RCC->APB2ENR,RCC_APB2ENR_IOPAEN);
//GPIOA3 push-pull 10Mhz
GPIOA->CRL= (GPIOA->CRL&(~(GPIO_CRL_CNF3_1 | GPIO_CRL_CNF3_0 |GPIO_CRL_MODE3_1))) |
(GPIO_CRL_MODE3_0);
bitset(GPIOA->ODR,GPIO_ODR_ODR3); //led on

// rtc init
RCC->APB1ENR|=(RCC_APB1ENR_BKPEN|RCC_APB1ENR_PWREN);
bitset(PWR->CR,PWR_CR_DBP);

//Enable the LSE clock
bitset(RCC->BDCR,RCC_BDCR_LSEON);
while ((RCC->BDCR&RCC_BDCR_LSERDY) == 0);

//Select LSE as the RTC clock source
if (((RCC->BDCR)&0x300)!=0x100) {
bitset(RCC->BDCR,RCC_BDCR_BDRST);
bitclr(RCC->BDCR,RCC_BDCR_BDRST);
bitset(RCC->BDCR,0x100);
}

while ((RTC->CRL&RTC_CRL_RTOFF) == 0);
bitset(RTC->CRL,RTC_CRL_CNF);

//Set the RTC prescaler value
while ((RTC->CRL&RTC_CRL_RTOFF) == 0);
RTC->PRLL=0x7fff;
while ((RTC->CRL&RTC_CRL_RTOFF) == 0);
RTC->PRLH=0x0;

//clear alarm
while ((RTC->CRL&RTC_CRL_RTOFF) == 0);
RTC->ALRH=0;
while ((RTC->CRL&RTC_CRL_RTOFF) == 0);
RTC->ALRL=0;


bitclr(RTC->CRL,RTC_CRL_CNF);
while ((RTC->CRL&RTC_CRL_RTOFF) == 0);

//Enable RTC
bitset(RCC->BDCR,RCC_BDCR_RTCEN);





// rtc alarm init
bitset(EXTI->PR,EXTI_LINE_RTCALARM);
//not masked
bitset(EXTI->IMR,EXTI_LINE_RTCALARM);
//masked
bitclr(EXTI->EMR,EXTI_LINE_RTCALARM);
//rising trigger enabled
bitset(EXTI->RTSR,EXTI_LINE_RTCALARM);
//falling trigger disabled
bitclr(EXTI->FTSR,EXTI_LINE_RTCALARM);


// Enable RTC interrupts
NVIC_SetPriority(RTC_IRQn, 0);
NVIC_EnableIRQ(RTC_IRQn);



//set alarm curtime + 2 sec
uint32_t alarmcnt=(RTC->CNTHCRL&RTC_CRL_RTOFF) == 0);
bitset(RTC->CRL,RTC_CRL_CNF);

bitclr(RTC->CRH,RTC_CRH_ALRIE);
bitclr(RTC->CRL,RTC_CRL_ALRF);

while ((RTC->CRL&RTC_CRL_RTOFF) == 0);
RTC->ALRH=alarmcnt>>16;
while ((RTC->CRL&RTC_CRL_RTOFF) == 0);
RTC->ALRL=alarmcnt&0xFFFF;

bitset(RTC->CRH,RTC_CRH_ALRIE);
bitclr(RTC->CRL,RTC_CRL_CNF);
while ((RTC->CRL&RTC_CRL_RTOFF) == 0);

// stop
PWR->CR = (PWR->CR & (~ (PWR_CR_PDDS | PWR_CR_LPDS))) | PWR_CR_CWUF;
SCB->SCR=(SCB->SCR & (~(SCB_SCR_SLEEPONEXIT_Msk | SCB_SCR_SEVONPEND_Msk))) | SCB_SCR_SLEEPDEEP_Msk;
__WFI();

 

Newest Forum Posts

  1. Write option bytes by Just1M, 2019-04-24 11:34
  2. Write option bytes by ihouses, 2019-04-24 08:26
  3. Update vs. install version discrepency by christelle.burguera, 2019-04-23 10:06
  4. Variables by anthony@churchillnavigation.com, 2019-04-22 16:52
  5. Symbol 'SysTick_IRQn' could not be resolved by bart@engine27.be, 2019-04-22 12:56
  6. Update vs. install version discrepency by gbabecki, 2019-04-19 19:41
  7. failed to install drivers while tried to install STM32 workbench on windows 8.1 pro by saidattu32, 2019-04-19 19:13
  8. STemWin Trainning Video - Can't find lab file by agiles chroms, 2019-04-19 18:53
  9. System Workbench for STM32 v2.9.0 release by vionf, 2019-04-19 10:06
  10. Update vs. install version discrepency by dautrevaux, 2019-04-19 08:45

Last-Modified Blogs