The best way to detect that a full message has been received is to have an end of message character either one that you have explicitly appended to the message or a Carriage Return character added by the transmitting system
thanks UKHeliBob
but i need to understand end of transmit no receive
of course DI and RE pin in driver ic connected to one pin of esp8266
therefor i don't receive in transmit time
Sorry but I find it difficult to understand what you want to do in either your original post or the latest one.
If the problem is that Serial.write() with a length parameter moves quickly to the next program statement then you could iterate through the my_data_buffer array and send one byte at a time. That way you will know exactly what has been sent and that you have completed the transmission.
If the problem is that data is being added to the output buffer whilst data is being sent from it then consider using a second buffer to hold incoming data during serial transmission
If neither of these is the problem, then please give more details and maybe an example of the problem.
Alternative to Serial.flush() is to check with Serial.availableForWrite(); this can allow (maybe within limits) for non-blocking code. When transmission is done, it should return 64.
GolamMostafa:
Can the 'end-of-transmission' be known by polling the TXC0-bit (USART Transmit Complete) of UCSR0A Register?
while(bitRead(UCSR0A, 6) != HIGH)
{
;
}
I think that that only works per byte, not per sequence of bytes.
check with Serial.availableForWrite() ... When transmission is done, it should return 64.
At which point, there will still be a byte in the TX Shift register, and another one in the buffer register.
And it assumes that the buffer was 64 to start with... On an AVR.
On AVR, I believe that Serial.flush() has gone to some trouble to ensure that those last bytes are sent before it returns. But the OP is using an ESP8266, which has a signficantly different UART (128byte hardware FIFOs, according to the TRM!), so who knows? Actually looking at the code, I see:
void HardwareSerial::flush(){
:
uart_wait_tx_empty(_uart);
//Workaround for a bug in serial not actually being finished yet
//Wait for 8 data bits, 1 parity and 2 stop bits, just in case
delayMicroseconds(11000000 / uart_get_baudrate(_uart) + 1);
So it does seem to be "trying."
this can allow (maybe within limits) for non-blocking code.