Embedded Computing
  • About
  • Blog
  • Hardware
    • Which Platform?
    • Controller Platforms >
      • Adafruit Platform
      • Arduino Plaform
      • BBC micro:bit
      • Espressif Platform
      • iLabs Platform
      • Raspberry Pi Platform (MCU)
      • Seeed Platform
      • Silicon Labs Platform
      • Teensy Plaform
    • Computer Platforms >
      • BeagleBone Platform
      • Raspberry Pi Platform (SBC)
      • UDOO Platform
    • Peripherals >
      • Shields
      • Grove System
      • Sensors
      • Actuators
    • Displays >
      • E-Paper Displays
      • Reflective Displays
      • TFT Displays
      • LCD Displays
    • Legacy Platforms >
      • chipKIT Plaform
      • 4D Systems Platform
      • Intel Platform
      • LaunchPad Plaform
      • BoosterPacks for LaunchPads
      • LightBlue Bean
      • Maple Plaform
      • Mediatek Platform
      • Microsoft Azure IoT DevKit
      • Particle Platform
  • Software
    • Exploring RTOS with Galaxia >
      • Event Library
      • Semaphore Library
      • Mailbox Library
      • Timer Library
      • Clock Library
      • SWI Library
      • Task Library
    • Ultra-Low Power with EnergyTrace >
      • Ultra-Low Power with MSP430
      • Ultra-Low Power with Energia MT and Galaxia
    • Using Integers Instead of Reals
    • Going Python?
  • IoT
    • IoT Platforms: Which Hardware? >
      • Matter with Silicon Labs MG24
    • IoT Services: Which Solution? >
      • Recommended IoT Solutions
      • Platform-Specific IoT Solutions
      • Other IoT Solutions
      • Not tested IoT Solutions
      • Notification Solutions
    • Get Date and Time from Internet with NTP
    • Fast and Easy WiFi Connection with QR-Code
  • Tools
    • How to Start?
    • Reference >
      • Asking for Help
      • Boards Pins Maps
      • Ruler
      • Boards and Plugs
      • I²C Logic Level Converter
      • Standards for Connectors
    • Training >
      • Texas Instruments Workshops
      • Embedded Systems: Shape The World — MOOC edX UTAustinX UT.6.02x
      • Embedded Systems - Shape The World: Microcontroller Input/Output — MOOC edX UTAustinX UT.6.10x
      • Embedded Systems - Shape The World: Multi-Threaded Interfacing — MOOC edX UTAustinX UT.6.20x
      • Real-Time Bluetooth Networks: Shape the World — MOOC edX UTAustinX UT.RTBN.12.01x
      • Systems Thinking with Texas Instruments Robotics System Learning Kit
    • Books >
      • Getting Started with the MSP430 LaunchPad
      • Getting Started with Arduino
      • Arduino Cookbook
    • IDE >
      • The Battle of IDEs
      • More Options
      • Assessing the Next Generation of IDEs
      • Tools for Documentation
    • Equipment >
      • Saleae Logic Analyser
      • Rigol DS1102E Oscilloscope
      • XDS110 Debug Probe with EnergyTrace​
      • Segger J-Link Programmer-Debugger
      • Nordic Power Profiler Kit II
  • Projects
    • Libraries >
      • Master I²C Software Library
      • Date and Time Library
      • highView Library Suite
      • Others Libraries
    • smartDevices >
      • I²C smartColours Smart Sensor
      • I²C smartRFID Smart Sensor
      • I²C smartLED Display
      • I²C smartControls Smart Device
      • I²C smartWiFi Smart Device
      • I²C smartBLE Smart Device
      • I²C smartNode Smart Device
    • IoT Projects >
      • Remote E-Paper Weather and Message Board
      • Typie-Walkie with LoRa and E-Paper Screen
      • Typie-Walkie with E-Paper Screen
      • Remote e-Paper Pictures Panel
      • Remote e-Paper Messages Panel
      • Industrial IoT Project
      • Remote Contactless Temperature Monitor
      • Using Node-RED for IIoT
      • Low Power Home Network Weather Monitoring
      • Updated Low Power Home Network Weather Monitoring
      • Weather and Security Station with Blynk
      • SensorTag to Blynk Using Node-RED
      • Pervasive Reporting
    • AI Projects >
      • Colour Recognition with Neural Network
    • Other Projects >
      • Air Quality Monitoring
      • Driving a Large E-Paper Display with a Compact Xiao RP2040
      • Low-Power E-Paper Weather Station
      • Portable Particulate​ Matter Monitor
      • FRAM-based E-Paper Screen Controller
      • General Purpose 3.5" Screen
      • Colour Recognition with Neural Network
      • A Low Power Weather Station
      • Digital Volt-Amp-Watt Meter
      • Mobile Measurement with LCD Display
      • Screen with SRAM for GUI
      • Volt-Amp-Watt-Meter for Grove
      • Multi-Touch Project with CapTIvate

Date and Time Library

Modern MCUs include a RTC, or Real Time Clock, that keeps date and time. The MSP432, CC3200, TM4C123 and TM4C129 include high-level commands to manage the RTC. 

RTC can be powered by a battery but unfortunately, battery line is hard-linked to main supply on the LaunchPads.

With a board with WiFi capabilities like the CC3200, the library gets the exact time from Internet using NTP or Network Time Protocol.

The Date and Time Library provides an object that encapsulates the most commonly used functions.

Time Formats: Epoch and Structure

There are two commonly used formats to represent the time: epoch and structure.
  • The epoch is the number of seconds since 00:00 Jan 1st, 1970. It is often called Unix time. It is an unsigned 32-bit integer.
Picture
  • The structure tm is defined in the <time.h> library and includes one element for each component of the date and time. 

Please note daylight savings time, offset from GMT and time zone are not managed by the MCU. The MSP432 has its own specific structure, without those three elements.
Picture
The Date and Time Library provides two utilities to convert from one format to another: convertEpoch2Structure() and convertStructure2Epoch(), with self explanatory names. Both functions are based on the <time.h> library and take both formats, epoch and structure.

Similarly, the Date and Time Library includes functions to display the date as a string: stringDateTime() and formatStringDateTime(). 

The latter uses format codes which are detailed here. Both functions are based on the <time.h> library and take both formats, epoch and structure.
Picture

Using the RTC

The clock myRTC is declared as a DateTime variable, and then initialised with begin().

Optionally, the time-zone is set with setTimeZone(), here with tz_CEST for Central Europe Savings Time.

The setTime() function sets the date and time to the clock based on an epoch time. By convention, the reference time kept in the MCU's RTC is always GMT.

The getTime() function gets the date and time from the clock as an epoch time, which is converted into as string with stringDateTime().

To get the local time, i.e. CEST, use getLocalTime().

Picture

Getting Date and Time from Internet with NTP

Additionally, the CC3200 LaunchPad and the CC3100 BoosterPack can read the official time from a time server using NTP or Network Time Protocol, thanks to a WiFi connection. One example of time sever is the National Institute of Standards and Technology, or NIST.

Picture
The getTimeNTP() function reads date and time from the specified NTP server. If no NTP server is specified, the function uses wwv.nist.gov  mentioned earlier.

if getTimeNTP() is successful, the function updates the myEpochNTP variable and returns true. 

Each 10 seconds, NTP time is checked again and compared to RTC. RTC may drift up to 4 seconds a day.

The library is based on the example provided with Energia 16. 
Picture

Download

The library was developed with embedXcode and has been tested on Energia 16 against MSP432 EMT, CC3200 non-EMT, TM4C123 and TM4C129. 

NTP compilation was successful against CC3200 non-EMT but, for an unknown reason, failed against CC3200 EMT.

Download 

​Posted: Jul 31, 2015 — Edited: Apr 02, 2016
Powered by Create your own unique website with customizable templates.