Probleme ISR() with Teensy 3.2

Status
Not open for further replies.

Eyolon

Member
Hi everyone

I try to build a drone and i've decided to use a 3.2 teensy for this.

i need to create a true interrupt system for the command transmission (between pilot and drone)

i use 2 way for this : Wifi (for short- medium range transmission) and radio (for medium - long transmission)

i've try to use the ISR() macro but it doesn't works.

Code:
ISR(USART2_RX_vect) {
  Serial.println("RX2 RECEIVE");//Debug over Serial (USB)
  Esc.writeESC(vavg, vavd, varg, vard, setup1); //Write to ESC
}

i've try to insert cli() and sei() in this order in the setup method and no change

i've check this page but... no help : https://www.pjrc.com/teensy/interrupts.html

and i think i've find a bug, i've re install a couple of time teensyduino and dowload it twice and when i try to use avr/interrupt.h, i've an error who say "ISR() need constructor..." and when i check the fie in the progam file/arduino repertory
(of the teensy hardware folder obviously) the file is blank !

after copy and move original file from arduino it compile but all doesn't work as expected.

thank's for your help !
 
First, I'd highly recommend you use the normal Serial2 functions. Teensy has Serial2.availableForWrite() which can tell you how many byte you may write without blocking. If your main goal is to transmit data on Serial2 without stalling the rest of your program, that is the best way.

You might also try using serialEvent2(). It's not called from interrupt context, but Teensyduino has pervasive support for yield() in all blocking functions, so you'll find the serialEvent stuff is far more responsive than regular Arduino. Perhaps that will be good enough, without the complexity of executing in interrupt context?

If you *really* must program your own interrupt handler, you're going to have to start with the code in serial2.c.

https://github.com/PaulStoffregen/cores/blob/master/teensy3/serial2.c

As you can see in that file, on Teensy 3.2 the interrupt is named uart1_status_isr(void). It's *not" ISR(USART2_RX_vect), which is an AVR only name.

Teensy 3.2 is a 32 bit ARM processor from Freescale, so the UART hardware is completely different. The hardware is also much more advanced than on AVR, featuring a FIFO. The ARM processor also has nested priority interrupts. You can probably see the code is much more complex than Arduino's UART code for AVR chips, due to leveraging these advanced hardware features. If you're going to dig into the actual interrupt code, you'll need to deal with the details of Freescale FIFO-based UARTs. Complete documentation is available in the reference manual, but be warned... these UARTs are loaded with tons of advanced features, which means there's a *lot* of documentation!
 
Thank's for all answers

My goal is simple i need to stop the code and execute a routine. after some optimization, using serialEvent2() can be a solution but i'm feared by the potential latency. I think if i optimize my loop routine, i can reduce it to 10 or 20 ms and if i work on baudrate, i can reduce it again.

Thank's for your help. if i fail in my optimization, i try with uart1_status_isr(void).

PS : i'm french and i'm sorry if my english hurts your eyes.
 
I did a quick serialEvent1() and serialEvent2() sample tying two each of the serial ports between two Teensy 3.1 or 3.2's and set baud rate at 6,000,000 and transmitted short strings (strings up to and over the default buffer size) between the those four ports for days with no problem. That code works pretty well with the FIFO hardware. Earlier tests with LC and no FIFO peaked just over 220,000 baud as far as I tested.

As long as your loop cycles fast enough or you add yield() as Paul notes all should be well to keep you ahead of the math. Worst case if you have larger messages you can't get to soon enough - make the default buffers large enough or drop the baud rate instead - or you'd need flow control or some other means to make sure messages don't come in while you are blocked elsewhere.
 
Status
Not open for further replies.
Back
Top