Issue with truly random interrupt on Teensy3.2

Hei people I am trying to implement an interrupt function as follows:

// Random seed includes
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <util/atomic.h>
#define randomSeed(s) srandom(s)
volatile uint32_t seed;  // These two variables can be reused in your program after the
volatile int8_t nrot;    // function CreateTrulyRandomSeed()executes in the setup() function

/*
Define arduino output pins. Change these values as necessary.
The LED_BUILTIN pin is helpful as an indicator that the program is running.
*/

#define N_PINS 3
const int pins[N_PINS] = { 13, 14, LED_BUILTIN };

// define baud rate
int bd = 9600;

// define interrupt timer
IntervalTimer SerialTimer;

//define pulse parameters
#define INTERVAL_MIN 1000  //define minimum interval length [ms]
#define INTERVAL_MAX 1000  //define maximum interval length [ms]
#define PULSE_LEN 1000     //define the pulse length [ms]
bool LEDstate = 0;
int counter = 0;

void CreateTrulyRandomSeed() {
  seed = 0;
  nrot = 32;  // Must be at least 4, but more increased the uniformity of the produced
              // seeds entropy.

  // The following five lines of code turn on the watch dog timer interrupt to create
  // the seed value
  cli();
  MCUSR = 0;
  _WD_CONTROL_REG |= (1 << _WD_CHANGE_BIT) | (1 << WDE);
  _WD_CONTROL_REG = (1 << WDIE);
  sei();

  while (nrot > 0);  // wait here until seed is created

  // The following five lines turn off the watch dog timer interrupt
  cli();
  MCUSR = 0;
  _WD_CONTROL_REG |= (1 << _WD_CHANGE_BIT) | (0 << WDE);
  _WD_CONTROL_REG = (0 << WDIE);
  sei();
}

ISR(WDT_vect) {
  nrot--;
  seed = seed << 8;
  seed = seed ^ TCNT1L;
}

//function called by the interrupt sending the signal through USB port
void sendSerial60() {
  counter++;
  Serial.print(LEDstate);
  Serial.print(" - ");
  Serial.println(counter);
}

void setup() {
  //start Serial connection
  Serial.begin(bd);
  //define interrupt function and interrupt timing 60Hz -> 166666.6667us (projectors @60Hz)
  SerialTimer.begin(sendSerial60, 16666.66667);  //120: 8333.3333333, 59.81: 16719.61211

  CreateTrulyRandomSeed();
  randomSeed(seed);
  // Serial.print("Random seed = ");
  // Serial.print(seed);
  // Serial.print("\n");

  for (int i = 0; i < N_PINS; i++) {
    pinMode(pins[i], OUTPUT);
    digitalWrite(pins[i], LOW);
  }
}

void loop() {
  //switch LED to HIGH
  LEDstate = 1;
  //change the signal to on (high, 3.3V)
  for (int i = 0; i < N_PINS; i++) {
    digitalWrite(pins[i], LEDstate);  //turn the pins on (high, 3.3V)
  }

  //keep the signal on for the length of PULSE_LEN
  delay(PULSE_LEN);  //keep the current state for the length of PULSE_LEN

  //switch LED to LOW
  LEDstate = 0;
  //change the signal to off (low, 0V)
  for (int i = 0; i < N_PINS; i++) {
    digitalWrite(pins[i], LOW);  //turn the pins off (low, 0V)
  }

  // Wait for random inter-pulse interval
  int random_delay = random(INTERVAL_MIN, INTERVAL_MAX);
  Serial.println(random_delay);
  delay(random_delay);
}

I know for now it is not crazy random having 1s on and offs, in future this will change. More I get some errors I don't remember having them before as I used that code already on the mentioned Teensy 3.2.
The error list looks as follows:

C:\Users\lukashi\Arduino\randomSerialTest\randomSerialTest.ino:76:5: error: expected constructor, destructor, or type conversion before '(' token
   76 | ISR(WDT_vect) {
      |     ^
C:\Users\lukashi\Arduino\randomSerialTest\randomSerialTest.ino: In function 'void CreateTrulyRandomSeed()':
C:\Users\lukashi\Arduino\randomSerialTest\randomSerialTest.ino:61:3: error: 'MCUSR' was not declared in this scope
   61 |   MCUSR = 0;
      |   ^~~~~
C:\Users\lukashi\Arduino\randomSerialTest\randomSerialTest.ino:62:3: error: '_WD_CONTROL_REG' was not declared in this scope
   62 |   _WD_CONTROL_REG |= (1 << _WD_CHANGE_BIT) | (1 << WDE);
      |   ^~~~~~~~~~~~~~~
C:\Users\lukashi\Arduino\randomSerialTest\randomSerialTest.ino:62:28: error: '_WD_CHANGE_BIT' was not declared in this scope
   62 |   _WD_CONTROL_REG |= (1 << _WD_CHANGE_BIT) | (1 << WDE);
      |                            ^~~~~~~~~~~~~~
C:\Users\lukashi\Arduino\randomSerialTest\randomSerialTest.ino:62:52: error: 'WDE' was not declared in this scope
   62 |   _WD_CONTROL_REG |= (1 << _WD_CHANGE_BIT) | (1 << WDE);
      |                                                    ^~~
C:\Users\lukashi\Arduino\randomSerialTest\randomSerialTest.ino:63:27: error: 'WDIE' was not declared in this scope
   63 |   _WD_CONTROL_REG = (1 << WDIE);
      |                           ^~~~
C:\Users\lukashi\Arduino\randomSerialTest\randomSerialTest.ino: At global scope:
C:\Users\lukashi\Arduino\randomSerialTest\randomSerialTest.ino:76:4: error: expected constructor, destructor, or type conversion before '(' token
   76 | ISR(WDT_vect) {
      |    ^

exit status 1

Compilation error: expected constructor, destructor, or type conversion before '(' token

Any help would be clearly appreciated! Thanks and cheers.

A Teensy 3.2 uses an ARM processor; anything AVR specific will not compile.

Thanks! That is a good point actually. The code was first written for a Arduino Uno so it seems I might have missed that just switching to a Teensy.
But I think it is still worth mentioning that PJRC themselves introduce the topic of interrupts with AVR specifics (Using interrupts on Teensy, with C language).

That was likely written when the Teensy 2.0 family was their main product line. It's AVR-based. Teensy 3.x & 4.x boards are ARM-based.

Alright I see, thanks people!
Then I will ponder on a new version for ARM.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.