RTC Learning Based on stm32f103zet6

Source: Internet
Author: User

RTC Configuration
1. For the second interrupt configuration, RTC is just a timer. It's no big deal!
1. nvic_prioritygroupconfig (nvic_prioritygroup_1 );
Nvic_prioritygroup,: Specifies the priority grouping bits length.
This parameter can be one of the following values:
Nvic_prioritygroup_0: 0 bits for pre-emption Priority 4 bits for subpriority
Nvic_prioritygroup_1: 1 bits for pre-emption Priority 3 bits for subpriority
Nvic_prioritygroup_2: 2 bits for pre-emption Priority 2 bits for subpriority
Nvic_prioritygroup_3: 3 bits for pre-emption Priority 1 bits for subpriority
Nvic_prioritygroup_4: 4 bits for pre-emption priority 0 bits for subpriority
// The meaning is clear. The only thing that needs to be understood is pre-emption (primary priority) subpriority (secondary priority );
2. nvic_inittypedef nvic_initstructure;
Find the manual for such a struct
Data Member
Uint8_t nvic_irqchannel
Functionalstate nvic_irqchannelcmd
Uint8_t nvic_irqchannelpreemptionpriority
Uint8_t nvic_irqchannelsubpriority
3. Description of nvic_irqchannel:
Specifies the IRQ channel to be enabled or disabled.
Value
Nonmaskableint_irqn 2 Non Maskable Interrupt
 
Memorymanagement_irqn 4 Cortex-M3 Memory Management Interrupt
 
Busfault_irqn 5 Cortex-M3 Bus Fault interrupt
 
Usagefault_irqn 6 Cortex-M3 usage fault interrupt
 
Svcall_irqn 11 Cortex-M3 SV call interrupt
 
Debugmonitor_irqn 12 Cortex-M3 debug monitor interrupt
 
PendSV_IRQn 14 Cortex-M3 Pend SV Interrupt
 
SysTick_IRQn 15 Cortex-M3 System Tick Interrupt
 
WWDG_IRQn Window WatchDog Interrupt
 
PVD_IRQn PCIe through EXTI Line detection Interrupt
 
TAMPER_IRQn Tamper Interrupt
 
RTC_IRQn RTC global Interrupt
 
FLASH_IRQn FLASH global Interrupt
 
RCC_IRQn RCC global Interrupt
 
EXTI0_IRQn EXTI Line0 Interrupt
 
Extistmirqn EXTI Line1 Interrupt
 
EXTI2_IRQn EXTI Line2 Interrupt
 
EXTI3_IRQn EXTI Line3 Interrupt
 
EXTI4_IRQn EXTI Line4 Interrupt
 
Dma?channel=irqn DMA1 Channel 1 global Interrupt
 
DMA1_Channel2_IRQn DMA1 Channel 2 global Interrupt
 
DMA1_Channel3_IRQn DMA1 Channel 3 global Interrupt
 
DMA1_Channel4_IRQn DMA1 Channel 4 global Interrupt
 
DMA1_Channel5_IRQn DMA1 Channel 5 global Interrupt
 
DMA1_Channel6_IRQn DMA1 Channel 6 global Interrupt
 
DMA1_Channel7_IRQn DMA1 Channel 7 global Interrupt
4. NVIC_IRQChannelCmd
Specifies whether the IRQ channel defined in NVIC_IRQChannel will be enabled or disabled.
This parameter can be set either to ENABLE or DISABLE
5. NVIC_IRQChannelPreemptionPriority
Preemption priority
6. NVIC_IRQChannelSubPriority
Subpriority
The configuration should be
NVIC_IRQChannel = RCC_IRQn
NVIC_IRQChannelCmd = ENABLE
NVIC_IRQChannelPreemptionPriority = 1
NVIC_IRQChannelSubPriority = 0
Looking at the source code, there is no such problem
Ii. Next, let's look at the RTC configuration function.
RTC_Configuration ();
1. Enable the peripheral clock, including the clock in the preparation area and the power consumption control clock
RCC_APB1PeriphClockCmd (RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE );
2. Enable BKP register
PWR_BackupAccessCmd (ENABLE );
3. initialize the BKP register and set it to the default value.
BKP_DeInit ();
4. RTC uses a low-speed external clock.
RCC_LSEConfig (RCC_LSE_ON );
5. Wait for the external clock to vibrate, are you ready?
While (RCC_GetFlagStatus (RCC_FLAG_LSERDY) = RESET ){}
6. If the external clock is enabled, you must set the RTC clock to an external low-speed clock.
RCC_RTCCLKConfig (RCC_RTCCLKSource_LSE );
7. After setting, you need to enable the external clock
RCC_RTCCLKCmd (ENABLE );
8. Wait for the RTC register Clock Synchronization
RTC_WaitForLastTask ();
9. Wait until the last instruction written to the RTC register is completed.
RTC_WaitForLastTask ();
10. Enables or disables the specified RTC interrupts is configured for RTC interruptions.
RTC_ITConfig (RTC_IT_SEC, ENABLE); Second interrupt, enabling second interrupt
11. RTC_WaitForLastTask ();
12. Set the RTC and frequency division Coefficient
RTC_SetPrescaler (32767);/* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767 + 1 )*/
13. RTC_WaitForLastTask ();
One thing to note is that after we initialize the RTC, We will write the RTC register.
An error occurs. You need to wait for the command to be completed by me, that is, RTC_WaitForLastTask ();
Now the basic configuration of RTC is complete.
3. When we need to input the clock time from the serial port, let's look at the Time_Adjust function.
1. RTC_WaitForLastTask () as soon as it comes up ();
There is no harm in waiting for the Operation to complete;
2. Change the current time value
RTC_SetCounter (Time_Regulate ());
3. The same RTC_WaitForLastTask ();
Let's take a closer look at how Time_Regulate is implemented.
Void Time_Adjust (void)
{
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask ();
/* Change the current time */
RTC_SetCounter (Time_Regulate ());
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask ();
}
There is only one function.
RTC_SetCounter (Time_Regulate (); Sets the RTC counter value.
It seems to be a second-setting function.
IV,
1. RCC_ClearFlag (); this is the function to clear the reset identifier.
2. Time_Show ();
5. The point is...
Based on the sample program provided by the wild fire, I think using the wild fire board test is certainly no problem, and now the key is that I am the most self-developed
Small system, so there are a lot of places that do not pay attention to, for example, in this low-speed external crystal oscillator, I found that it has not been vibrating, check on the Internet
According to the information, it is because the requirements for this load capacitor are relatively high, because the laboratory does not have this capacitor, so there is no way, you can only modify the use
Here, I use an internal low-speed crystal oscillator to provide a clock for RTC, so the following code needs to be modified:
It is to change the three lines of code
RCC_LSICmd (ENABLE );
//!!! Use internal low-speed Crystal Oscillator
While (RCC_GetFlagStatus (RCC_FLAG_LSIRDY) = RESET );
RCC_RTCCLKConfig (RCC_RTCCLKSource_LSI );
The corresponding frequency division coefficient also needs to be modified !!!
There is no problem in doing this test!
The specific reason is in the reposted blog post ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.