Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: Teensy 4 & rtc_second interrupt

  1. #1
    Member
    Join Date
    Nov 2018
    Location
    Canada
    Posts
    38

    Teensy 4 & rtc_second interrupt

    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?

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,289
    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?

  3. #3
    Member
    Join Date
    Nov 2018
    Location
    Canada
    Posts
    38
    Thanks defragster, you've confirmed my suspicions.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,439
    Quote Originally Posted by quadrupel View Post
    Am I missing something? Will it be available for the Teensy 4 in the near future?
    On Teensy 4.0, use attachInterruptVector().

  5. #5
    Member
    Join Date
    Nov 2018
    Location
    Canada
    Posts
    38
    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?

  6. #6
    Member
    Join Date
    Nov 2018
    Location
    Canada
    Posts
    38
    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 :-)

  7. #7
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,129
    may not be relevant, but here is a sketch that does T4 RTC interrupts ...
    https://github.com/manitou48/teensy4...ster/rtchp.ino

    also see https://forum.pjrc.com/threads/54711...l=1#post195387

  8. #8
    Member
    Join Date
    Nov 2018
    Location
    Canada
    Posts
    38
    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 :-)

  9. #9
    Senior Member bmillier's Avatar
    Join Date
    Apr 2016
    Location
    Halifax, N.S. Canada
    Posts
    149
    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

  10. #10
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,289
    Quote Originally Posted by manitou View Post
    may not be relevant, but here is a sketch that does T4 RTC interrupts ...
    https://github.com/manitou48/teensy4...ster/rtchp.ino

    also see https://forum.pjrc.com/threads/54711...l=1#post195387
    Doh - ran that sketch in beta - more than once … of course I see 142 sketches in the T4 folder … I was going to mention @manitou … should have searched the sketches ...

  11. #11
    Member
    Join Date
    Nov 2018
    Location
    Canada
    Posts
    38
    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.

  12. #12
    Member
    Join Date
    Nov 2018
    Location
    Canada
    Posts
    38
    Quote Originally Posted by manitou View Post
    may not be relevant, but here is a sketch that does T4 RTC interrupts ...
    https://github.com/manitou48/teensy4...ster/rtchp.ino

    also see https://forum.pjrc.com/threads/54711...l=1#post195387
    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) );
      }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •