I've just got lost in the manuals for the MKL26Z64VFT4 and wondered if anyone her could help?
The code here is for the Arduino nano. It needs to work in a microsecond or so and so I've bypassed the normal Digitalread and digital write commands and addressed the digitalread port DDRD and then written to Port D with a binary command.
The teensy is much faster but doesn't like DDRD, etc, because it's specific to the arduino's chip.
So I need to do a similar thing on the teensy, but how do I set up an interrupt and find the commands for addressing the ports without reading the 600 page manual?
Ed
/*
*/
// This code is to take an input from pin D2 and output Rx blank on D3 which has a 2us delay on the falling edge and output Tx blank on D4 which has a 2us delay on the rising edge.
const byte interruptPin = 2;
volatile byte state = 0b00000000;
const byte rise_delay =6;
const byte fall_delay = 5;
void setup() {
//setup port D pins 3 and 4 as outputs. Pin 3 = RX_blank; Pin 4 = TX_blank//
DDRD = DDRD|B00011000;
//start with interrupt on rising edge//
attachInterrupt(digitalPinToInterrupt(interruptPin), rise, RISING);
}
void loop() {
// loop goes on forever with no actions so interrupts are serviced on rising and falling edges//
}
void rise() {
//Delay TX blank after rising edge//
//turn on Rx_blank//
PORTD=0b00001000;
//turn on Tx_blank as well//
delayMicroseconds(rise_delay);
PORTD=0b00011000;
detachInterrupt(digitalPinToInterrupt(interruptPin));
attachInterrupt(digitalPinToInterrupt(interruptPin), fall, FALLING);
}
void fall() {
//delay Rx_blank after falling edge//
PORTD=0b00001000;
delayMicroseconds(fall_delay);
PORTD=0b00000000;
detachInterrupt(digitalPinToInterrupt(interruptPin));
attachInterrupt(digitalPinToInterrupt(interruptPin), rise, RISING);
}
The code here is for the Arduino nano. It needs to work in a microsecond or so and so I've bypassed the normal Digitalread and digital write commands and addressed the digitalread port DDRD and then written to Port D with a binary command.
The teensy is much faster but doesn't like DDRD, etc, because it's specific to the arduino's chip.
So I need to do a similar thing on the teensy, but how do I set up an interrupt and find the commands for addressing the ports without reading the 600 page manual?
Ed
/*
*/
// This code is to take an input from pin D2 and output Rx blank on D3 which has a 2us delay on the falling edge and output Tx blank on D4 which has a 2us delay on the rising edge.
const byte interruptPin = 2;
volatile byte state = 0b00000000;
const byte rise_delay =6;
const byte fall_delay = 5;
void setup() {
//setup port D pins 3 and 4 as outputs. Pin 3 = RX_blank; Pin 4 = TX_blank//
DDRD = DDRD|B00011000;
//start with interrupt on rising edge//
attachInterrupt(digitalPinToInterrupt(interruptPin), rise, RISING);
}
void loop() {
// loop goes on forever with no actions so interrupts are serviced on rising and falling edges//
}
void rise() {
//Delay TX blank after rising edge//
//turn on Rx_blank//
PORTD=0b00001000;
//turn on Tx_blank as well//
delayMicroseconds(rise_delay);
PORTD=0b00011000;
detachInterrupt(digitalPinToInterrupt(interruptPin));
attachInterrupt(digitalPinToInterrupt(interruptPin), fall, FALLING);
}
void fall() {
//delay Rx_blank after falling edge//
PORTD=0b00001000;
delayMicroseconds(fall_delay);
PORTD=0b00000000;
detachInterrupt(digitalPinToInterrupt(interruptPin));
attachInterrupt(digitalPinToInterrupt(interruptPin), rise, RISING);
}