Here's the modified code (Filter.txt) for my project (with home-brewed UART handler - if you can call it that; there's only three lines of code that do the actual transmitting and receiving!!

) that I mentioned a couple of posts back. Just change the extension from .txt to .ino to be able to use it with the Arduino IDE.
As I hinted at in the previous post, there are several ways to do this sort of MIDI programming using an Arduino...
1. Use an Arduino MIDI library - simple and effective, no chip datasheets needed (see below)! But you end up with quite a bit of code (source & compiled) and a relatively slow(ish) program.
2. Use the Serial class - my original code (see previous post). Produces fairly lean code and is still pretty easy to understand.
3. Get 'close to the metal' - which is what this version does. Trickier to grok, but produces very tight compiled code and runs like a rat up a drainpipe which is why I ended up using this method
To understand (the different bits from before of) my code (all the lines with CAPITAL letter variables), you'll need to pore over an 'ATmega328 Complete Datasheet'; there are several variants out there (just google it) and any of them will do the job.
I used the Atmel original (
https://atmega32-avr.com/atmega328-datasheet/); page 176 onwards contains all the necessary info.
I'm afraid this is all about bit manipulating - bit-shifting (using << and >>) and bit-masking (using ~, & and |) - microprocessor registers and hardware control so be prepared for a bit (haha) of a headache if you've not done any low-level programming using chip datasheets before...!
It's worth it in the end though if you intend to get into this sort of microcontroller-based port-manipulating MIDI/comms programming and it has one other advantage that I REALLY like...
Unlike if you use 1 or 2 above, using 3 means that you don't have to rely on anyone else's code!
Aside from understanding (and using the register & bit names from) the datasheet, It's totally self-contained

OK, all those capital variable names (UCSR0A etc.) have been defined (by someone else) in a .h header file somewhere, but that's all they are; definitions. They're not someone else's code!
And if there's one thing I've learnt, thru bitter experience over the years, it's NOT to rely on anyone else's code no matter who they are (yeah, Microsoft, especially you!)
I've not included a circuit design as there are plenty about on the web that show the absolute minimum you need to use to get the 328P working (see previous post for component list).
But if you understand 'Assembly language' intermediate files, I've also included (FilterAsm.txt) the one for this C program which shows just how 'lean & mean' the C code gets compiled to!
Just ignore all the 'timer' stuff - this is automatically added by the Arduino compile process (to make it easier for novice Arduino programmers who just want to dip their toes in the water

) and isn't part of my program. As it only runs once at the very start, it doesn't actually affect the main code at all which is why I haven't bothered modifying the Arduino 'makefile' stuff to remove it - that would just be TOO nerdy!!

Health Warning: Assembler is not for the faint-hearted
