I made some progress, and managed to have a timer isr called around 1000000 times per second but I'm facing a weird crash that I don't understand
I extracted all the meaningless parts of the code
Code:
#include <Arduino.h>
volatile uint32_t count;
uint32_t last_count;
uint32_t last_time;
const uint8_t addr_pins[16] = {32, 31, 30, 29, 1, 0, 17, 16, 5, 21, 20, 6, 8, 7, 14, 2};
FASTRUN void ftm0_isr(void) {
FTM0_SC &= ~FTM_SC_TOF;
count++;
for (unsigned int i = 0; i < 16; i++) {
//digitalReadFast(addr_pins[i]);
}
}
void setup() {
count = 0;
last_time = millis();
while (!Serial)
;
Serial.println("Entering setup");
FTM0_SC = 0;
FTM0_CNT = 0;
FTM0_MOD = 59;
for (int i = 0; i < 16; i++)
pinMode(addr_pins[i], INPUT);
NVIC_SET_PRIORITY(IRQ_FTM0, 32);
NVIC_ENABLE_IRQ(IRQ_FTM0);
FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS(0) | FTM_SC_TOIE;
Serial.println("Leaving setup");
}
void loop() {
uint32_t c;
if (millis() - last_time >= 1000) {
cli();
c = count;
sei();
Serial.println(c - last_count);
last_time = millis();
last_count = c;
}
}
The offending line of code is
Code:
digitalReadFast(addr_pins[i]);
doing 16 digitalReadFast() calls with pin constants is fine but as soon as I use addr_pins[i] the Teensy freezes.
I really don't understand what the problem is...
The fault occurs the same way with TeensyDuino 1.45 or a custom Makefile with teensy core from github master