Try to edit your code like this.
#include <Serial.h>
uint32_t tick = 0;
// Define the Timer3 Interrupt Vector
void Timer3Interrupt(void) __interrupt (INT_NO_TMR3) {
if (T3_STAT & bT3_IF_END) {
T3_STAT |= bT3_IF_END; // Clear the interrupt flag
tick++;
digitalWrite(40, tick & 1);
}
}
void setup() {
// Enable the LED
pinMode(40, OUTPUT);
digitalWrite(40, LOW);
// give the Arduino IDE some time to switch.
delay(3000);
USBSerial_println("Running " __FILE__ " " __DATE__ " " __TIME__);
#define DIV (1) // Divisor of F_CPU
#define ENDCOUNT (100) // Count
// Set divisor
T3_SETUP |= bT3_EN_CK_SE; // Enable accessing divisor setting register.
T3_CK_SE_L = DIV & 0xff;
T3_CK_SE_H = (DIV >>
![Cool 8)](https://www.eevblog.com/forum/Smileys/default/cool.gif)
& 0xff;
T3_SETUP &= ~bT3_EN_CK_SE; // Clear access again.
T3_CTRL |= bT3_CLR_ALL; // Force clear FIFO and count of timer3.
T3_CTRL &= ~bT3_CLR_ALL; // And go back to reset by software
T3_SETUP |= bT3_IE_END; // Enable interrupts
T3_CTRL &= ~bT3_MOD_CAP; // Timer or PWM mode
T3_STAT |= bT3_IF_END; // Interrupt when we pass ENDCOUNT
T3_END_L = ENDCOUNT & 0xff;
T3_END_H = (ENDCOUNT >>
![Cool 8)](https://www.eevblog.com/forum/Smileys/default/cool.gif)
& 0xff;
IE_TMR3 = 1; // Timer3 interrupt is enabled.
EA = 1; // Global interrupt enable control bit
}
void loop() {
static uint32_t last = 0;
if (last != tick) {
last = tick;
USBSerial_print("IRQ seen:");
USBSerial_println(tick);
delay(500);
}
static uint32_t lastMillis;
if (millis() - lastMillis > 2500) {
lastMillis = millis();
USBSerial_println("Still alive..");
}
}