Help with reading serial with timers

Status
Not open for further replies.

StefanB

Member
Hey guys. Please reference https://github.com/AirmanEpic/teensy_dshot_simple which I'm using to code.

the problem is that reading from serial will stop the "Packet sending" which breaks the system I'm devising. So instead, it was decided to use timer interrupts to handle the packet sending while the serial handling was done in the main loop.

See line 49 through 52 in the code. This is where the serial commands are read.

I also added interrupt handling where the code received enters the flow, line 109 and 111.

However, when I run this, it will accept a single command before all subsequent commands are denied. I suspect this is because of the "Send single command" function on line 58. However, I've added a serial print in that code block and it will always print so it's not simply hanging there.

Anyone have any idea? Feel free to make PRs to the github too.
 
For testing at least change this line 8:: myTimer.begin(timerCommand, 20);

To something over well 20us.

There is a lot of code and delay in the timer _isr()
 
Sure, but something this speed or higher is required for the project.

ok yes I see it's responding now at 100us. Hmmm.
 
I take that back, at 50us it is working exactly ideally and sending the correct packets. This is solved. Thank you for the help!
 
Glad you have it working...

Note: With your code:
Code:
  while (Serial.available()){
    String a = [COLOR="#FF0000"]Serial.readString();[/COLOR]
    Serial.println("Received Signal: "+a);
    handleCommand(a);
  }
}
Personally I don't use this method nor most others like it...
As if you look at how it is defined:
screenshot.jpg
You will see this call will wait until it does not receive any more Serial data until a timeout happens.
And by default the timeout is 1 second. (1000ms)

Wonder how code might work if you added a call like: Serial.setTimeout(1);
for 1ms timeout?
 
I take that back, at 50us it is working exactly ideally and sending the correct packets. This is solved. Thank you for the help!

Great news!

Sure, but something this speed or higher is required for the project.

ok yes I see it's responding now at 100us. Hmmm.

As noted - that was a 'test' since in scanning the code 20us seemed low to allow completion before the next timer would want to execute!
 
Status
Not open for further replies.
Back
Top