RTC on G80TH doesn't appear to work after updating to firmware 4.3.8.1

I’ve tried on 3 different modules, and they all seem to fail in being able to either set or get the real time clock date/time - problem wasn’t there with previous version of firmware.

Here’s how I am testing it:
DateTime clockTime = <your date/time>;
RealTimeClock.SetDateTime(clockTime);
DateTime newDateTime = RealTimeClock.GetDateTime());

If I check the value in RealTimeClock.GetDateTime() it’s still uninitalized (1/1/1980).

I tried calling the code in a loop as was posted in the forum for a similar issue, but that doesn’t appear to work.

This could be a coincidence. Have you tried loading the old firmware back to see if the problem disappear?

@ Gus - I have confirmed that when using 4.3.7.10 the same code works!

Using:
VS2013
Installed older GHI electronics NETMF SDK 2015R1
NETMF SDK 4.3

Can you please provide a small example code so we can try?

@ Gus - Sure!

Here’s what I use:

var current = RealTimeClock.GetDateTime(); // at this point I get 6/1/2011 00:04:05
RealTimeClock.SetDateTime(new DateTime(2016,10,16,13,45,00));

current = RealTimeClock.GetDateTime(); // I still get 6/1/2011 00:04:05

Is there something wrong with how I wrote the code?
I set a breakpoint where current is declared, and step through examining the values.

Thanks!

Please, show the whole code.
Where is the excerpt you published?
In Main() or ProgramStarted() or elsewhere ?
While the program is launched, there is a behind the scene access to the clock and it may interfere.

@ SouthernStars - You’re right. Here’s the complete code:

from Program.cs



using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using GHI.Processor;
namespace GadgeteerApp1
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            var current = RealTimeClock.GetDateTime();
            RealTimeClock.SetDateTime(new DateTime(2016,10,16,13,45,00));
            var current2 = RealTimeClock.GetDateTime();
        }
    }
}

I included a snapshot as well which shows the code formatted and color-coded.
I should also mention that the way I code for the G80TH, is I start a Gadgeteer project and select the Cerbuino Bee (no Ethernet) as the board to use.
Thanks!

Stepping in ProgamStarted() is not a good idea.
Try this


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using GHI.Processor;                    // add a reference to GHI.Hardware

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace GTimer
{
    public partial class Program
    {
        public static GT.Timer timer;
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            timer = new GT.Timer(10000); // every 10 second (10000ms)
            timer.Tick += Timer_Tick;        
            timer.Start();
        }

        private void Timer_Tick(GT.Timer timer)
        {
            int nAttempt;
            DateTime tDateTime;

            timer.Stop();
            tDateTime = new DateTime(2016, 10, 18, 10, 20, 30);
            nAttempt = 0;

            do
            {
                nAttempt++;
                RealTimeClock.SetDateTime(tDateTime);
                //
                // at first iteration, the time may be set, but not the Date
                //
                Debug.Print("RTC (" + nAttempt.ToString() + ") : " +
                            RealTimeClock.GetDateTime().ToString("yyyy-MM-dd HH:mm:ss.f"));
            } while ((nAttempt < 5) && (RealTimeClock.GetDateTime().Day != 18));
        }
    }
}

Using mainboard GHI Electronics FEZ Raptor version 1.0
Program Started
RTC (1) : 2016-10-18 10:20:30.0

1 Like

@ elik - you can add code tags to show the correct formatting directly in the post.

1 Like

@ elik - I forgot to add: create a new project, name it GTimer
and select only the MainBoard, then replace program.cs with my code
and don’t forget to add a reference to GHI.Hardware.
Load the program with VS debugger and see immediate Window.
Then power off the board to be sure the RTC is in a known state
(If there is a battery, remove it for the test) and retry.

@ SouthernStars - THANK YOU!!! Your code worked perfectly!!!