Here's the issue I'm having. I want to send serial message to PC. Its size is about 70 bytes.
The problem:
It doesn't work.
The fix:
I've increased size of serial buffer to 255 (way too much, I know, but it was just a test), and it started working.
So, what does really happen here? When my code starts filling outgoing serial buffer, doesn't interrupt fire immediately, which sends data to USART, and also automatically starts deleting data from buffer after transmission? How should I handle this?
I'm sending array of 70 bytes to that function. MIDI library then sends it to serial buffer:
/*! \brief Generate and send a System Exclusive frame.
\param length The size of the array to send
\param array The byte array containing the data to send
\param ArrayContainsBoundaries When set to 'true', 0xF0 & 0xF7 bytes (start & stop SysEx) will NOT be sent (and therefore must be included in the array).
default value is set to 'false' for compatibility with previous versions of the library.
*/
void MIDI_Class::sendSysEx(int length,
const byte *const array,
bool ArrayContainsBoundaries)
{
if (ArrayContainsBoundaries == false) {
USE_SERIAL_PORT.write(0xF0);
for (int i=0;i<length;++i) {
USE_SERIAL_PORT.write(array[i]);
}
USE_SERIAL_PORT.write(0xF7);
}
else {
for (int i=0;i<length;++i) {
USE_SERIAL_PORT.write(array[i]);
}
}
#if USE_RUNNING_STATUS
mRunningStatus_TX = InvalidType;
#endif
}
one byte at a time. As soon as the first one hits the outgoing buffer, interrupts are triggered to send the data in the outgoing buffer.
When the outgoing buffer is full, write() blocks until there is room.
I can't imagine why changing the outgoing buffer size made any difference.
Here's some screenshots then. So, my project is a MIDI controller capable of understanding SysEx messages. Depending on received messages, Arduino either changes some data inside EEPROM (SET command), or it reads data from 328p and sends it back to MIDI app (GET command). In this scenario, I want to find out MIDI notes for each of 64 buttons. Response is SysEx start (1 byte), 3 ID bytes, 4 other bytes used to determine message type and 1 byte for each button. So that's 73 bytes in total. First attachment shows what I get when serial buffer is set to 32 bytes. Response is 33 bytes long instead of 73. Second attachment shows exactly the same message being sent to Arduino, only with 255 bytes of serial buffer. No other code changes. Works just fine, without any warning.