About MIDI bytes and their MSB

I wish I could answer this question here. I'm not sure if it would be offtopic. I'm about to work with MIDI and Arduino but I need to clearify this.

I wonder why Status byte must start with 1, and the other data bytes must start with 0. I mean, I read that this is the way the reciever recognize each byte. However, that doesn't make sense to me.

Why isn't it possible to use 256 values for each data bytes? What happens in the first 0-127 values of the Status byte?

I'm not a MIDI expert...

I wonder why Status byte must start with 1, and the other data bytes must start with 0. I mean, I read that this is the way the reciever recognize each byte. However, that doesn't make sense to me.

The receiver (or software) needs some way of knowing what a particular byte represents. For some reason, this is what the people chose when they created the MIDI protocol.

Why isn't it possible to use 256 values for each data bytes? What happens in the first 0-127 values of the Status byte?

With the MSB used to indicate a status byte, values of 0-127 are not status bytes.

So, how the reciever knows which one of the two available data bytes is reading if both starts with 0?

If a byte has the high-order bit set, then it is the status byte which can indicate that this message is a Note On, Program Change, etc.
If there is noise on the line and some of the data gets garbled, the receiver can eventually get synchronized again by ignoring everything until it sees a byte that has the high-order bit set.

Pete

So I assume the reciever can separate byte per byte, as bits flow?

Yes.

Every 8 bits are actually transmitted as 10 bits on the wire. When idle, the digital signal is 1 (logic high).

A start bit (0) is sent first. Then the 8 data bit follow. After the last data bit, a stop bit (1) is transmitted.

To the receiver, the start bit indicates when a new byte will arrive. The stop bit, from the receiver's perspective, is simply guaranteed idle time after the last data bit, so it can begin looking for the next start bit as a 1-to-0 transition.

The start+stop bit framing is automatically added by the transmitter and removed by the receiver, so you deal only with a sequence of bytes in software, without having to worry about the framing of which bits belong in which bytes.

Also, the hardware transfers each byte in LSB-first bit order. Normally, you never need to know this, since you deal only with properly-framed bytes at the software level.

But if you want to know what's really happening on the wire, that MSB which indicates the beginning of a message is actually transmitted after the 7 lower bits which represent the channel and message type, which come after the start bit. Serial framing is always start bit, then data in LSB to MSB order, optional parity check (never used on MIDI), followed by 1 or 2 stop bits.

Thanks very much for the explanation. I've almost got everything but I think I'll check it again in the future.

I suspect that you know that the first byte indicates the channel in the lower four bits, but with these bits at all zero, this indicates channel 1, because musicians can't cope with the concept of a number zero channel. So these bottom four bits PLUS one is the MIDI channel.

Yep, i knew that. but why did you say "PLUS one"? MIDI channel is represented in 4 bits as you said before

Because the MIDI channel that is used is those four bits plus one.
So if those bits are say two, that is 0010 then the MIDI channel is 3

Oh, that.
0000 would be the first channel so it's called MIDI channel 1 and so on..

Does the reciever has got a bit counter to know if, for example, the stop bit (1) is really the stop bit and not some 1 inside the Status Byte?
I mean, how can the reciever split those bytes?

I've already understood the MIDI 3-byte message and that's what I need to know, but I'm still curious about the behind the scenes.

Yes it has a state machine so it knows where it is up to. This is not only how MIDI works but the way the code gets uploaded into the Arduino. See