Adding a RTC - nealcrook/multicomp6809 GitHub Wiki

The easiest way to add a real-time clock (RTC) is to get a pre-built DS1302 module from EBAY. If you use the hook-up described below, the clock code in my NitrOS9 port will work without modification.

       -- 3 GPIO mapped to "group A" connector. Pin 1..3 of that connector
        -- assigned to bit 0..2 of gpio0.
        -- Intended for connection to DS1302 RTC as follows:
        -- bit 2: CE          (FPGA PIN 42)
        -- bit 1: SCLK        (FPGA PIN 41)
        -- bit 0: I/O (Data)  (FPGA PIN 40)

There is a utility in the NitrOS9 code that allows you to set the time at boot using the RTC. Test it like this:

  1. Boot NitrOS9, enter the date manually
  2. At the command prompt type mc09rtc -w (should set the RTC from the system time)
  3. At the command prompt type mc09rtc -d (dumps the contents of the RTC memory). If you look at the DS1302 data sheet you can see what each of the values mean, but if you repeat this step multiple times you should see the seconds count advance, and (eventually) the minute count advance
  4. Power down the board, leave it off for a minute then power up and boot to NitrOS9 again
  5. At the command prompt type mc09rtc -d again. You should see that the time is still correct (ie that it continued to advance while the power was off)
  6. At the command prompt type mc09rtc -r (should set the system time from the RTC)

If all of that works correctly, change the NitrOS9 startup script replacing the date -t command with the command mc09rtc -r.

If step 3 fails, the RTC is not connected correctly or the RTC is faulty or the RTC crystal is not oscillating. Try putting your finger on the bottom of the RTC pcb and power-cycling the whole board then repeating steps 1-3. If that makes a difference, you might need a tiny (5pF?) cap from one leg of the crystal to gnd.

If step 5 fails, its a problem with the battery or the RTC did not get the correct bits set to turn on the clock (the register dump will tell you) which would imply unreliable comms or a bug in the mc09rtc code.

Otherwise, it could be bad connection from the FPGA through the main board to the RTC board; you may need a simple scope or logic analyser to check the signals.

The mc09rtc code is here:

https://sourceforge.net/p/nitros9/code/ci/default/tree/level1/cmds/mc09rtc.asm