We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi
I have written the following code to set and then read the time. but when I see the result in the LCD, the value of seconds is from 0 to 89 with some jumps like 10 to 16, 25 to 32, 42 to 48 and 73 to 80.
void RTC_Set(void) { RTC_DateTypeDef RTC_DateStructure; RTC_TimeTypeDef RTC_TimeStructure; RTC_InitTypeDef RTC_InitStructure; RTC_AlarmTypeDef RTC_AlarmStructure; uint8_t uwSynchPrediv = 0xFF; uint8_t uwAsynchPrediv = 0x7F; /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_RTCAccessCmd(ENABLE); RCC_LSEConfig(RCC_LSE_ON); /* Wait till LSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { } /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); /* ck_spre(1Hz) = RTCCLK(LSE) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1)*/ /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Configure the RTC data register and RTC prescaler */ RTC_InitStructure.RTC_AsynchPrediv = uwAsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = uwSynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; RTC_Init(&RTC_InitStructure); /* Set the alarm 05h:20min:30s */ RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_AM; RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = 0x05; RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 0x20; RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 0x05; RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31; RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date; RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay; /* Configure the RTC Alarm A register */ RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure); /* Enable RTC Alarm A Interrupt */ RTC_ITConfig(RTC_IT_ALRA, ENABLE); /* Enable the alarm */ RTC_AlarmCmd(RTC_Alarm_A, ENABLE); RTC_ClearFlag(RTC_FLAG_ALRAF); RTC_DateStructure.RTC_Year = 15; RTC_DateStructure.RTC_Month = RTC_Month_June; RTC_DateStructure.RTC_Date = 26; RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Friday; RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure); RTC_TimeStructure.RTC_H12 = RTC_H12_AM; RTC_TimeStructure.RTC_Hours = 5; RTC_TimeStructure.RTC_Minutes = 20; RTC_TimeStructure.RTC_Seconds = 10; RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure); } void RTC_Get(void) { RTC_TimeTypeDef RTC_Time_struct; uint8_t h,m,s; char str[500]; RTC_GetTime(RTC_Format_BCD, &RTC_Time_struct); //show in display h=RTC_Time_struct.RTC_Hours; m=RTC_Time_struct.RTC_Minutes; s=RTC_Time_struct.RTC_Seconds; sprintf(str,"H=%d,M=%d,S=%d",h,m,s); GLCD_GoTo(40,4); GLCD_WriteString("Time:"); GLCD_GoTo(40,5); GLCD_WriteString(str); }
"internal RTC works wrong"
If the internal RTC works wrong, then a number of reasonably well payed design engineers must have failed badly. And the test engineers must also have failed badly. And the people writing the documentation must have failed badly. And a significant percent of the customers would be quite upset. And extra upset if the errors aren't documented in the chip errata.
But there is always another possibility - that a single developer has failed to spend enough time reading the documentation and making sure he/she understands exactly how the RTC is expected to function.
When something doesn't work as expected, it's quite often the expectations that are wrong.
Thanks. Surely it is my fault, I should have chosen binary format!