element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Sustain The World - Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Sustain The World - Design Challenge
  • More
  • Cancel
Sustain The World - Design Challenge
Blog Blog#4 - Using Real Time Clock on XMC4200 Platform2Go
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dang74
  • Date Created: 6 Sep 2020 11:06 PM Date Created
  • Views 479 views
  • Likes 3 likes
  • Comments 0 comments
Related
Recommended

Blog#4 - Using Real Time Clock on XMC4200 Platform2Go

dang74
dang74
6 Sep 2020

Including a Real Time Clock makes the XMC4200 a rare breed amongst microcontrollers.  It's also a blessing for me, as my project requires time-keeping and scheduling functions.

 

When you configure the RTC APP in DAVE you are presented with two tabs.

 

In the General Settings tab, pictured below, current time and alarm time can be set.

 

image What we learn immediately from the image below is that, as far as the RTC is concerned, the world was created on January 1, 1970. image

image

Figure 1 - RTC General Settings

 

 

The second tab  is for configuring interrupt settings.  I used this tab to set up an interrupt every second.

For the moment, I have not enabled Alarm interrupts.  However, in the future I will return to this setting because in the end, I will use the Alarm interrupt to activate the sprinkler.

image

Figure 2 - RTC Interrupt Settings

 

The interrupt handler that is executed every second is shown below.  For the moment, I use it to toggle the user LED.

 

image

image

 

The first time I read from the RTC I noticed that January is month 0.

And the 1st day of each month is day 0.

image

Figure 3- Month 0, Day 0?

 

Since I prefer 1970.01.01 over 1970.00.00, I decided to create a new data type called human_time_t and a couple of functions to convert between the native RTC format and the preferred 'human' format.

 

image

Figure 4 - Functions to convert between time formats

 

 

I was curious to see how leap years were handled. image

 

In the first test, I set the date to 2020.02.28 and the time to 23:59:45.

 

When I read back the time the following was displayed:

image

Figure 5 - February 28, 2020

 

 

A few moments later I read back the following:

image

Figure 6 - February 29, 2020

 

So, February 28 transitioned to February 29.  That is good, because 2020 is a leap year.

 

 

I did the same type of test for 2021.

 

Initially the date and time displayed was:

image

Figure 7 - February 28, 2021

 

 

A few moments later, the following was read back:

image

Figure 8 - March 1, 2021

 

This time February 28 transitioned to March 1.  This is perfectly fine since 2021 is not a leap year.

 

Up until now I had never written any microcontroller code that required a Real Time Clock function... so it was pretty cool.

 

Thank you for taking the time to read this blog,

 

Dan

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube