ericscottf
Member
Hello all,
I am working on a project where I am doing a lot of computation in recursive functions, but need to be able to react immediately to small amounts of incoming serial data, which will happen frequently but not on an exact schedule. Somewhere on the order of 5 bytes every 1.2 milliseconds... half the time the system is running, and the other half the time, every 30 or so ms.
Ideally, I need to have incoming serial data trigger an interrupt.
The serial connection I'm using is the USB port on the teensy 4.0.
I'd like to keep the existing hardwareserial libraries, not redo things!
I can't constantly poll Serial.available() - that's really not practical. I can't pepper my functions with that call, it would be inelegant and probably not fast enough anyway.
I suppose I could make an interrupt timer that would hammer Serial.available() on a very very frequent schedule, but that seems incredibly wasteful - 99% of the time, the buffer will be empty and that entire interrupt service will hamper operations.
My service routine won't be complicated - just needs to see if the incoming byte is the end of the message, and if it is, operate on the message. It'll get out way before the next byte is available.
Is there a reasonable way to make the hardware serial trigger an interrupt (or just call a function, I guess) after retrieving the byte from the serial port?
Do I need to edit the hardwareserial code, or is there a more straightforward reasonable way to do this that doesn't require editing existing libraries?
Thank you
Eric
I am working on a project where I am doing a lot of computation in recursive functions, but need to be able to react immediately to small amounts of incoming serial data, which will happen frequently but not on an exact schedule. Somewhere on the order of 5 bytes every 1.2 milliseconds... half the time the system is running, and the other half the time, every 30 or so ms.
Ideally, I need to have incoming serial data trigger an interrupt.
The serial connection I'm using is the USB port on the teensy 4.0.
I'd like to keep the existing hardwareserial libraries, not redo things!
I can't constantly poll Serial.available() - that's really not practical. I can't pepper my functions with that call, it would be inelegant and probably not fast enough anyway.
I suppose I could make an interrupt timer that would hammer Serial.available() on a very very frequent schedule, but that seems incredibly wasteful - 99% of the time, the buffer will be empty and that entire interrupt service will hamper operations.
My service routine won't be complicated - just needs to see if the incoming byte is the end of the message, and if it is, operate on the message. It'll get out way before the next byte is available.
Is there a reasonable way to make the hardware serial trigger an interrupt (or just call a function, I guess) after retrieving the byte from the serial port?
Do I need to edit the hardwareserial code, or is there a more straightforward reasonable way to do this that doesn't require editing existing libraries?
Thank you
Eric