Teensy 4 & rtc_second interrupt

Status
Not open for further replies.

quadrupel

Well-known member
I've ordered a couple of Teensy 4's, but until I receive them I've been playing around with possible problems I might encounter on current 3.6 programs migrating to 4.0. I use the rtc_second interrupt to trigger a call to rtc_get(), but it looks like the rtc_second interrupt is not currently supported in Teensyduino 147 with the Teensy 4.0.

Am I missing something? Will it be available for the Teensy 4 in the near future?
 
Quick look at the sources and it seems that was a Kinetis (T_3.x) supported interrupt?

Even less knowing look didn't find the same interrupt pre-Defined on T_4. RM suggests one could be created using one of its features?
 
Thanks Paul. Is the vector number 63, the same as for Teensy 3.6? I've looked thru the Teensy4 core code, and I can't find a list of interrupt vectors like the Teensy3 in mk20dx128.c?
 
Paul, I located attachInterruptVector(), and it answered my question. Actually, in reality, it's made me do a lot more investigation, but what the heck, I don't have the Teensy 4's yet, so I've got time :)
 
Thanks manitou, all I need now are my T4s. There's only so much I can do without actually testing. Fingers crossed they'll arrive next week some time :)
 
Quadrapel- I ordered my T4s when Paul announced them last week and they showed up in Eastern Canada today (using the cheap mail shipping option. Regards
 
Hi bmiller,
I ordered mine last Thursday, and I just got an email from Robin saying they were shipped today. I live in Edmonton, and typically stuff from PJRC takes 7+ days to get here. Still have lots of prep work to sort out.
 

Hi manitou, I've taken a break from PIT to resolve the Teensy3 to Teensy4 rtc_seconds_isr problem. I took your rtchp.ino test code and reduced it to generate an interrupt once per second. I wrote a P-O-C to prove it performs as expected. The output is triggered by the rtc_seconds_isr that prints a comparison of the Teensy4's rtc unix time and the rtc_second_isr's unix time. I didn't bother converting the unix time to a more usable date time format as I was interested in verifying the once per second interrupt trigger and the two unix time counts. Here is the P-O-C:
Code:
// rtc_seconds_isr.ino
// The code in this proof-of-concept is derived from
// https://github.com/manitou48/teensy4/blob/master/rtchp.ino

volatile uint32_t rtc_seconds_count;
volatile bool rtc_trigger = false;
void rtc_seconds_isr(void)
{
  SNVS_HPSR |= 3;
  rtc_seconds_count++;
  rtc_trigger = true;
  asm("dsb");
}


void rtc_seconds_begin()
{
  constexpr uint8_t SNVS_HPCR_PI_FREQ_MASK = 0x0F;
  constexpr uint8_t SNVS_HPCR_PI_EN_MASK   = 0x08;

  attachInterruptVector(IRQ_SNVS_IRQ,rtc_seconds_isr);
  NVIC_DISABLE_IRQ(IRQ_SNVS_IRQ);

  SNVS_HPSR |= 2;
  SNVS_HPCR &= SNVS_HPCR_PI_FREQ_MASK;
  SNVS_HPCR |=  SNVS_HPCR_PI_FREQ(15); // 2^15 = 32768
  SNVS_HPCR |=  SNVS_HPCR_PI_EN_MASK;

  NVIC_ENABLE_IRQ(IRQ_SNVS_IRQ);
  asm("dsb");
}


void setup()
{
  while (!Serial);
  pinMode(LED_BUILTIN, OUTPUT );

  rtc_seconds_begin();
  rtc_seconds_count = rtc_get();
}

void loop()
{
  if( rtc_trigger == true )
  {
    rtc_trigger = false;
    Serial.print("\r\nrtc_get() unix time is "); Serial.println( rtc_get() );
    Serial.print("rtc_seconds count is   "); Serial.println( rtc_seconds_count );
    digitalWrite( LED_BUILTIN, !digitalRead(LED_BUILTIN) );
  }
}
 
Status
Not open for further replies.
Back
Top