fbpx
Skip to main content

MIDI Forum

Sending MIDI data s...
 
Notifications
Clear all

Sending MIDI data serially with MIDI Controller

4 Posts
3 Users
0 Reactions
5,810 Views
Alison
Posts: 2
New Member
Topic starter
 

Hi! I'm an undergraduate Computer Engineering student at Penn State, and I'm working on designing a MIDI Out controller for a final project. I am doing low-level programming in C using a PIC 18F2520 microcontroller and a simple MIDI Out circuit to send MIDI data to my laptop via a MIDI to USB cable. I would like the to send a MIDI message from the PIC to Max MSP and display the message with their "notein" block (this part is already set up and working- I've tested it with my MIDI keyboard). My issue is that I'm having a hard time getting the correct values to show up in Max MSP. I know I'm getting signal because there is an LED indicator light on my MIDI to USB cable, and it lights up when I run my code. I also get values of 255, 128, and 0 to print in Max MSP, though I'm not trying to send those values. I think my problem is that I'm not sending the data correctly. If, say, I want to send a note on message such as 9A, 45, 45, do I send 9A to the send register (TXREG in my case), poll the TXREG until empty (indicated by TXIF flag bit, see attached code), send 45, poll the TXREG until empty, and send 45, poll the TXREG register until empty? Or do I need to send a start and stop bit as well?

I've attached a picture of my circuit and code for your reference. The circuit is fine, and I've set up the registers/baud rate/clock to send MIDI data serially based on the PIC data sheet and MIDI specs (20MHz clock with a baud rate of 31250bps). I'm not worried about syntax or anything related to the specs of the microcontroller, I'm just inquiring about how to appropriately send MIDI data with serial communication. The IDE I'm using is MPLAB. Any and all help is appreciated, I'm trying to learn as much as I can about serial communication and MIDI! Thanks in advance!

 
Posted : 19/04/2021 9:31 pm
Geoff
Posts: 1039
Noble Member
 

First things first.

Which MIDI to USB cable are you using? As has been mentioned on this forum, and elsewhere, on a number of occasions, there are some suspect ones about, quite cheap, Chinese made. These can garble the data being sent through. Some data gets through OK, other things suffer lost bits (so a value comes through, but not the value that was sent) and other bytes can be lost totally. If you do a search re 'Problems MIDI USB cables' you'll find info, and pictures of the offending items.

Geoff

 
Posted : 20/04/2021 7:13 am
Jürg
Posts: 18
Eminent Member
 

After the 3rd transmission you probable should wait for some ms. I suggest the following

while (1)
{
while..
TREG =

while..
TREG =

while..
TREG =

sleep(100); // 100 ms
}

 
Posted : 20/04/2021 7:37 am
Alison
Posts: 2
New Member
Topic starter
 

Geoff, I tried my cable with my MIDI Keyboard, and it is sending the correct values. Thank you for the suggestion though!

Jurg, I will be trying this an experimenting with the delays. Other than that, does it look like I have the right idea?

 
Posted : 21/04/2021 2:26 pm
Share: