Teensy 3.2 @3.3V (ext regulator): integrated RTC freezes everything

Status
Not open for further replies.

XFer

Well-known member
Hi,

I'm working with a Teensy 3.2, powered by an external 3.3V regulator.
I've followed the instructions to separate Vin/Vusb, etc.; the Teensy runs fine and everything.

Since I need an RTC, I figured I could plug a 32768 Hz quartz and take advantage of the Teensy integrated RTC.

I use Teensyduino-supplied DS1307RTC library.

Problem: when I try to access RTC object methods, Teensy just freezes! :-(
I swapped 3 different crystals, which by the way work fine on other DS1307 modules I have, and I always have Teensy freezing.

I wonder if the problem occurs because Teensy is powered by the external 3.3V source (so no 5V from USB)?
Maybe for the integrated RTC to work, it needs 5V somewhere, so I cannot use it with external 3.3V only? :-(

Thanks for any help!
 
It likely has nothing to do with the external power supply. I typically run my Teensies 3.x this way. It definitely does not need an external 5V power supply to run the RTC. Consider that the Teensy 3.2 is also configured with a 'external' power supply (i.e. the regulator inside the MK20 chip is not used).

I'm thinking the issue may rather lie with the crystal or the code. Is this a CFS206 crystal or something different? If different, consider using a CFS206 or something equivalent. Pay particular attention to the expected load capacitance.
 
Since I need an RTC, I figured I could plug a 32768 Hz quartz and take advantage of the Teensy integrated RTC.

I use Teensyduino-supplied DS1307RTC library

It's Impossible to use DS1307RTC library with Teensy3.x integrated RTC
 
all you need is this: #include <Time.h> //include Arduino Time library

example code
Code:
/*
 * TimeRTC.pde
 * example code illustrating Time library with Real Time Clock.
 *
 */

#include <Time.h> //include Arduino Time library

//   my variabls for time
int myHr, myMin, mySec, myDay, myMonth, myYr;
boolean oneTime = true; //

// ***********************************************************************************************************
// *
// *                            Power Up Init.
// *                            put your setup code here, to run once:
// *
// ***********************************************************************************************************
void setup()  {
  // Set the Arduino Time library to Sync from Teensy 3.x's RTC
  setSyncProvider(getTeensy3Time);
  setSyncInterval(60); // 1 minute / Configure how often the getTimeFunction is called in seconds.
  setTime(getTeensy3Time()); // Set Arduino Time library with Teensy 3.x RTC time.

  Serial.begin(115200);
  // while (!Serial);  // Wait for Arduino Serial Monitor to open
  delay(2000); // Wait 2 sec
  
  if (timeStatus() != timeSet) {
    Serial.println("Unable to sync with the RTC");
  } else {
    Serial.println("RTC has set the system time");
  }
}

// ***********************************************************************************************************
// *
// *                            Main Loop
// *                            put your main code here, to run repeatedly:
// *
// ***********************************************************************************************************
void loop() {
  //oneTime_set_option(); //One Time Set Option
    
  // Check for a time message from your computer, This message is sent by a Processing-based program,
  // found in Time's examples/Processing folder. https://processing.org/
  USBtime_set_option(); //Check for a time message.
  
  digitalClockDisplay(); //Display Clock

  // put your main code here, to run repeatedly:
  delay(1000); //<----- Remove delay l8r.

}

// ***********************************************************************************************************
// *
// *                            One Time Set Option
// *
// *
// ***********************************************************************************************************
void oneTime_set_option() {

  if (oneTime == true) {
    oneTime = false;
    Serial.println("Setting new time");
    myHr = 10;
    myMin = 15;
    mySec = 15;
    myDay = 20;
    myMonth = 5;
    myYr = 2020; // year 2020

    // This sets the system time (NOT the Teensy RTC Clock)
    // set your seperated date/time variables out as normal and update system time FIRST
    //setTime(hour(), minute(), second(), day(), month(), year())
    setTime(myHr, myMin, mySec, myDay, myMonth, myYr);

    // now lets set the RTC in teensy before exiting.
    // now we can use the system time to update the Teensy's RTC bits
    // This sets the Teensy RTC Clock from Arduino Time library(system time) - epoch stylee, just like it wants :)
    Teensy3Clock.set(now());
  }
}

// ***********************************************************************************************************
// *
// *                   Display Digital Clock
// *
// *
// ***********************************************************************************************************
void digitalClockDisplay() {
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());

  //isAM();            // Returns true if time now is AM
  //isPM();            // Returns true if time now is PM
  if (isAM() == true) {
    Serial.print(".AM");
  }
  else {
    Serial.print(".PM");
  }

  Serial.print(" "); // space
  switch (weekday()) // Day of the week, Sunday is day 1
  {
    case 1:
      Serial.print("Sunday");
      break;
    case 2:
      Serial.print("Monday");
      break;
    case 3:
      Serial.print("Tuesday");
      break;
    case 4:
      Serial.print("Wednesday");
      break;
    case 5:
      Serial.print("Thursday");
      break;
    case 6:
      Serial.print("Friday");
      break;
    case 7:
      Serial.print("Saturday");
      break;
  } //end of switch case
  Serial.print(" "); // space
  Serial.print(day());
  Serial.print(" "); // space
  Serial.print(month());
  Serial.print(" "); // space
  Serial.print(year());
  Serial.println();
}

// ***********************************************************************************************************
// *
// *                 utility function for digital clock display: prints preceding colon and leading 0
// *
// *
// ***********************************************************************************************************
void printDigits(int digits) {
  Serial.print(":");
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

// ***********************************************************************************************************
// *
// *                 Read Teensy 3.x time from Teensy 3.x internal RTC
// *
// *
// ***********************************************************************************************************
time_t getTeensy3Time()
{
  return Teensy3Clock.get();
}

// ***********************************************************************************************************
// * USB time set option using your computer's time.
// * TimeSerial listens for a message from your computer. This message is sent by a Processing-based program,
// * found in Time's examples/Processing folder.
// ***********************************************************************************************************
void USBtime_set_option() {
  if (Serial.available()) {
    time_t t = processSyncMessage();
    if (t != 0) {
      Teensy3Clock.set(t); // set the internal RTC in teensy
      setTime(t); // set the Arduino Time library
    }
  }
}

// ***********************************************************************************************************
// *
// *                 code to process time sync messages from the serial port
// *
// *
// ***********************************************************************************************************
//#define TIME_HEADER  "T"   // Header tag for serial time sync message
char TIME_HEADER[] = "T"; // fix / warning: deprecated conversion from string constant to 'char*'

unsigned long processSyncMessage() {
  unsigned long pctime = 0L;
  const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013

  if (Serial.find(TIME_HEADER)) {
    pctime = Serial.parseInt();
    return pctime;
    if ( pctime < DEFAULT_TIME) { // check the value is a valid time (greater than Jan 1 2013)
      pctime = 0L; // return 0 to indicate that the time is not valid
    }
  }
  return pctime;
}
 
I can't see a slightly different 32768 crystal freezing hard the Teensy (it stops doing anything).
It could be the code: I'm using the "regular" RTC methods to access the clock, like:

Code:
tmElements_t	tTime;

if (RTC.read(tTime))
{
...
}

As soon as an RTC.* method is called, the Teensy freezes.

From Defragster's code, it looks like I can't call RTC.* methods to access the onboard RTC clock; instead, it seems I should call something like "Teensy3Clock.get()".

It would mean a lot of editing of my existing code. :(

Maybe I should just wire an external RTC module (like a DS1307) and be done with it.

Thanks everyone!

Fernando
 
Status
Not open for further replies.
Back
Top