-
Notifications
You must be signed in to change notification settings - Fork 520
Description
Hello!
Using ArduinoIDE for RP2040 programming. Use serial transmission (PIOSerial, 115k) for sending data, with code:
(...)
int SerialBufferSize=512;
SerialPIO PIOSerial3 (10, 11, SerialBufferSize);
(...)
HardwareSerial* port=nullptr;
port = &PIOSerial3;
(...)
gpio_put(DIR_PIN, true); //start sending
port->write(txFrameBuffer, totalLen); //sending
gpio_put(DIR_PIN, false); //sending end
Of course it fails, because “sending end” information raise to early - DIR_PIN going low during transmission (upper: data frame, lower DIR_PIN state):
So, lets use Serial.flush() which check when output buffer will be empty (all data sent):
gpio_put(DIR_PIN, true);
port->write(txFrameBuffer, totalLen);
port->flush();
gpio_put(DIR_PIN, false);
Much better, but.. why Serial.flush() tooks so much time longer? All Serial goes out, but DIR_PIN is HIGH for over 170us after real transmission ends?
Lets do other test - change serial speed to 9600:
The same situation, too long “tail” but seems almost fine
So, speed up to 961k:
Seems Serial.flush() takes about 10x more time than real transmission time! As I see, Serial.flush() executes not less than ~1ms (?)
My questions are:
- Does Serial.flush() should works like that?
- How proper check when serial transmission ends?
Best regards!