2012-07-18 01:11 PM
Hi I am trying to write date and time to the RTC which I later will read.
But something in my RTC configuration doesn’t work and reading the values in debug mode shows that the RTC registers that I try to set never get the new values.
Here is my code:
void Set_RTC(){/* Enable the PWR clock */RCC_APB1ENR.PWREN = 1;/* Allow access to RTC */PWR_CR.DBP = 1;/* LSE used as RTC source clock */RCC_BDCR.LSEON = 1; //External low-speed oscillator enable /* Wait till LSE is ready */while(RCC_BDCR.LSERDY != 1){}/* Select the RTC Clock Source to LSE */RCC_BDCR.F8 = 1;RCC_BDCR.F9 = 0;/* Wait for RTC APB registers synchronisation */while(RTC_ISR.RSF != 1){}RCC_BDCR.RTCEN = 1; //Enable RTC clock <<<RTC_WPR = 0xCA; //unlock write protectionRTC_WPR = 0x53; //unlock write protection/* Configure the RTC prescaler */RTC_PRER = 0x7f00ff; // set SynchPrediv to FF and AsynchPrediv to 7F//RCC_BDCR.RTCEN = 1; //Enable RTC clock <<<RTC_ISR.INIT = 1; //enter initialization mode <<<<<< THIS REGISTER NEVER GETS THE NEW VALUEwhile(RTC_ISR.INITF != 1) //poll INITF{}/* Configure the RTC PRER */ RTC_PRER = 0x7F; RTC_PRER |= 0xFF << 16; RTC_TR = 0x123500; //setting time to 12.35.00 RTC_DR = 0x126718; // set date to 2012-07-18 RTC_CR.F6 = 0; // set FMT 24H format RTC_ISR.INIT = 0; //exit initialization mode /* Enable the write protection for RTC registers */ RTC_WPR = 0xFF;}I am using a STM32F407 @ 140Mz internal HSI oscillator.
What am I doing wrong?
2015-09-25 05:25 AM
Does the same problem occur if you use the LSI clock?
You can't put a scope probe directly on LSE, you'll alter the characteristics of the circuit too much, you must observe indirectly, either via the TAMPER pin, or measuring it with a timer, there's an example of that in the firmware library. The LSE is very fussy, it needs a 6-7pF crystal, not the more common 9 to 12pF ones.2015-09-25 06:10 AM
I changed from LSE to LSI
void RTC_Config(void){ unsigned char ErrorStatus; /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Reset RTC Domain */ RCC_BackupResetCmd(ENABLE); RCC_BackupResetCmd(DISABLE); /* Enable the LSI OSC */ RCC_LSICmd(ENABLE); /* Wait till LSI is ready */ while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) { } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); /* Configure the RTC data register and RTC prescaler */ RTC_InitStructure.RTC_AsynchPrediv = 0x7F; RTC_InitStructure.RTC_SynchPrediv = 0xCB; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; ErrorStatus=RTC_Init(&RTC_InitStructure); /* Set the time to 01h 02mn 00s AM */ RTC_TimeStruct.RTC_H12 = RTC_H12_AM; RTC_TimeStruct.RTC_Hours = 0x01; RTC_TimeStruct.RTC_Minutes = 0x02; RTC_TimeStruct.RTC_Seconds = 0x00; ErrorStatus=RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct);}THE RESULT IS THE SAMERTC does not go to INIT state and the return status is ERROR2015-09-25 06:42 AM
Can you try without the reset commands?
What debugger are you using?2015-09-25 07:39 AM
Check in debugger, that PWR_CR.DBP is set indeed.
JW2015-09-25 08:11 AM
I have made a try without the reset command
/* Reset RTC Domain */ //RCC_BackupResetCmd(ENABLE); //RCC_BackupResetCmd(DISABLE);but no result
The debugger is ST-LINK with SWD2015-09-25 08:26 AM
hello JW
PWR_BackupAccessCmd(ENABLE) set it and I verified that it is set#define PWR_OFFSET (PWR_BASE - PERIPH_BASE)#define CR_OFFSET (PWR_OFFSET + 0x00)#define DBP_BitNumber 0x08#define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4))void RTC_Config(void){ unsigned char ErrorStatus; unsigned long app; /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); app=*(__IO uint32_t *) CR_DBP_BB;app=12015-09-25 08:38 AM
By itself, or running something like CooCox or GDB?
Anyway, all very odd, identical code functions on a STM32F429I-DISCO with LSE circuitry added. STM32F429ZIT6 I see hours of fun ahead..2015-09-25 11:29 AM
Let's try another tack.
Does you board have a USART hooked up? Which USART, which pins? Is SWO (PB3) connected on your debug interface? What is the external HSE frequency? What speed is the board running at?2015-09-28 01:09 AM
I used
PB10:UART3 TXPB11:UART3 RXPB3 is freeDebug Interface with only 2 pinPA13 : SWDIOPA14: SWCLKBoard running at 168 Mhz starting from an oscillator of 8 MhzI saw that in this forum at least 3 other people had the same problem and I was wondering if these people had then resolved the issueThanksCarlo De Bonis2015-09-28 01:25 AM
> I saw that in this forum at least 3 other people had the same problem and I was wondering if these people had then resolved the issue
Some posters never come back to report of their success; others are tinkerers who give up. Let's step back - tell us, what exactly is your problem and how do you diagnose it. As I said above, you should have started your own thread. JW