Hi I’m using an AVR4809 to run a stepper motor using the accelstepper library. The AVR receives instructions from a C# driver I’ve written, which sits between client software and the 4809. The comms protocol between the driver and the 4809 is well established and all works fine. Serial and Serial2 Comms are via USB through 2 x FTDI devices.
So my problem is that whilst Serial comms work fine with no delay (i.e. non blocking), Serial2 seems to block, and that causes my stepper motor to pause. I’ve stripped the code down and experimented to try to isolate the problem. Here’s the (pretty simple) code that causes the problem:
if (Monitor.available() > 0)
{
String monitorReceipt = Monitor.readStringUntil('#');
if (monitorReceipt.indexOf("dataRequest", 0) > -1) // request for data packet from the C# driver
{
dataPacket= String(syncCount) + '#';
Monitor.print(dataPacket); // this seems to take about 2 seconds to execute
ledToggle();
}
Note that there’s a compiler directive which assigns Monitor as Serial2.
syncCount is defined as int and is incremented elsewhere in the code.
dataPacket is defined as String and is normally assigned elsewhere in the code, I put it where it is currently shown just to make a simple example of the problem.
I introduced the ledToggle so I could get a visual on the delay and it’s about 2 seconds.
Normally in the C# code a 3 second timer event transmits the text ‘dataRequest’ and the AVR4809 responds with the data packet (this normally consists of six data items concatenated with ‘#’ delimiters). The code works as expected, apart from the delay which causes the stepper motor to pause.
Any suggestions as to the cause, or anything to look for would be greatly appreciated.