I am troubleshooting a project that was working but has stopped making the required communication to a MIDI board. I have an Arduino that was sending MIDI commands to a MIDI keyboard. The communication is serial from the Tx pin on the Arduino. MIDI protocol is an asynchronous serial interface. The baud rate is 31.25 Kbaud (+/- 1%). There is 1 start bit, 8 data bits, and 1 stop bit (ie, 10 bits total). The MIDI command code requires serial bytes to be sent.
My MIDI keyboard stopped responding to input from the Arduino setup. I have tested using 3 different Arduinos and 2 separate MIDI boards I no longer get any response from setup. It seams I have ruled out hardware issue as I have changed everything in the setup. I tried several serial monitors and get what appear to be the same results.
I set up a CP2102 module to bridge the Arduino serial output to USB. I established a communication to a windows 10 PC. I reset the baud rate and tested the connection at 9600, 14400,31250 baud and get the same results. I have used the Arduino serial monitor, putty, and CoolTerm to try and determine what the micro is sending. I have rewritten the Arduino code so that only a minimal amount of code remains for the tests. This is the entire code I am now using for the tests. I have
Using the View Hex feature available on CoolTerm I can see the hex values of the data received. I do not understand what is causing the unexpected values.
This is what I am seeing for HEX values from the serial on the Arduino.
90 3C FF 00 3C 00 90 3D FF 00 3D 00 90 3E FF 00 3E 00 ...
Most of the values are what I was expecting . However every instance of Serial.write (0x80) is showing as 00, Serialwrite(0X7F) are showing as FF. also 64 dec (hex 40) show as hex 80
I have attempted everything I can think of to remedy this issue. I don't know what else to try.
.
which Arduino ? Well! to by more accurate. I originally was using a mini pro 16- 5volt. and later switched the system over to an Atmel 328P microprocessor. supported by a voltage regulator with power supply capacitors and a 14.7456MHZ crystal.
I now see that the issue originates from using the Arduino IDE to code on a bare bones processor. A practice I have done before without any issues. I may have to change all my code to C
if you are using the standard "UNO" type target to compile and upload the code, the expected frequency is 16MHz. This is probably enough to mess up the baud rate timing and creating the issue you see.
I will switch to a 16 MhZ crystal and try it again. Thanks I had overlooked that obvious error on my part. I have to go now I will try this when I get a chance .
All I had to do is match up the crystal and the baud register bits.
I always felt that the solution was just some simple mistake that I had made but was failing to recognize. Sure enough I forgot about the USART baud register bits at UBRRnH and UBRRnL. I typically would have set that register when coding in C. I completely forgot about them for this project that I coded in Arduino IDE. I swapped out the crystal to 16MhZ on the project board and everything appears to be working again.
Actual! I am now wandering how and why the system was ever working as well as it once did with the crystal not matching up with the baud register settings.
Anyway it is working again and all is well. I greatly appreciate the help.