Serial.Write - accessing the ringbuffer

Hi all,

I'm currently building a MIDI controller with internal Clock to control some Synthesizers and Drummachines. For that I'm using the Serial Ports of the Arduino Mega.

I guess the Serial Output is also stored in a ringbuffer and I was wondering if there is a way to store one byte in front of the ringbuffer even if there are still some bytes which need to get send?

I want to make sure that the Clock messages always gets send directly and not get delayed by other MIDI messages which are not so timing important.

Thanks for any help,

Ramón

The internals of the HardwareSerial class are protected.

You could inherit from it, or write your own class entirely.

You'll have to decide what to do when the buffer is full. Maybe send the clock messages immediately?

Pieter

Ramon_W:
I guess the Serial Output is also stored in a ringbuffer and I was wondering if there is a way to store one byte in front of the ringbuffer even if there are still some bytes which need to get send?

Wouldn't it be simpler to organize things so the buffer is always empty or has at most 1 byte by limiting the rate at which stuff is put into it.

What baud rate are you using?

...R

Thanks for the fast reply.
I'll have a look into the HardwareSerial-Class, but not sure if my programming skills are good enough for that.
How big is the size of the HardwareSerial ringbuffer?

I'm using baud rates between 31250 and 250000 depending on the Synthesizer. The Rates are normed and I can't change them.
Some of the faders I build are controlling a lot of parameters at once. That means one fader movement sends a lot of messages, especially if the Fader is moved fast. I could probably try to limit these fast movements and skip some of the messages.
Just wanted if there might be a faster way to set the Clock-byte always at the first write position.

Ramon_W:
How big is the size of the HardwareSerial ringbuffer?

64 bytes

That means one fader movement sends a lot of messages, especially if the Fader is moved fast. I could probably try to limit these fast movements and skip some of the messages.

You could write your code so it checks availableForWrite() to make sure it is 64 before sending the next byte of every message.

If that would reduce the performance of the ordinary messages too much then it seems to me that the real problem is that you are trying to send too much data.

...R