I am trying to use Serial.write() to write 1003 bytes on the serial port. It works fine but the issue is that since 1003 not a multiple of 64 bytes then serial port type the first 960 (15*64) no problems but then for the remaining 43 bytes, it waits until they complete the 64 bytes then it send it out to the serialport.
how can I make sure it doesn't wait to do that, in another words how can i enable partial write
Calling Serial.flush() will force it to wait for all characters to be sent, so don't call that if you don't want to wait.
You can check [url=https://www.arduino.cc/en/Serial/AvailableForWrite]Serial.availableForWrite()[/url] to see how much room is left in the transmit buffer. Only write that many characters, and do other things until there is room for the rest of your message. At 9600, it will take about 1000ms to send 1003 characters, so there will lots of time to do other things.
BTW, your Arduino "blocks" after the first 66 characters of the 1003 characters (64 in TX buffer, plus 2 in the UART hardware). It has nothing to do with "multiples" of 64.
Calling Serial.flush() will force it to wait for all characters to be sent, so don't call that if you don't want to wait.
BTW, your Arduino "blocks" after the first 66 characters of the 1003 characters (64 in TX buffer, plus 2 in the UART hardware). It has nothing to do with "multiples" of 64.
I agree, I removed Serial.Flush. That is exactly what I am doing
sterretje:
Is this on your 32U4 based board with modified usb code?
If so, are you using the usb port or the serial port with ftdi cable?
Yes it is
and not it isn't
I have a solution but I'm not sure if it ideal
I can just easy send 1024 and in my receiver application just read 1003
or i can increase the buffer size to 1003 , now that will still give me problem since I need that length to be variable not a constant
availableForWrite returns a number, not a true or false; under normal circumstances 0..64 (for the 32U4, the USB_EP_SIZE - FifoByteCount()).
Not sure if it will help though. I'm running a test on a Leonardo (as you might remember, I do not have a Micro) with serial monitor; measuring the time that it takes to send 1003 bytes. the results are (till now) consistent; between 7 and 10 milliseconds per write.