|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
newbie needs help with MIDI input |
Posted: Mon Feb 27, 2006 3:04 am |
|
|
Hi,
I'm using a 18F452 clocked at 20Mhz with the CCS compiler and am trying to get MIDI input implemented. The circuit is all setup, but I can't figure out how to parse the MIDI input that's coming into the PIC. It looks like garbage when I view the info in my terminal.
What do I need to do to setup the UART to work with MIDI? How do I grab the middle 8 bits of each 10-bit MIDI word (there is a start and stop bit)? Does UART remove these?
I've searched the forum without much luck; most of the examples on the web I found were in assembler or PicBasic Pro. Any help is very much appreciated.
Thanks! - Charlie |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Mon Feb 27, 2006 5:29 am |
|
|
Firstly MIDI is just plain serial data with a bit of hardware to manage the driving between instruments (5mA opto isolated loops).
MIDI data is transmitted or received as asynchronous serial data at a rate of 31.25KBaud with a format of 1 start bit, 8 data bits, and 1 stop bit, so it can be handled directly by the builtin UART and treated as normal serial data. So each 'byte' of MIDI data you are interested in is stripped of the start and stop bits for you.
try:
#uses RS232(baud=31250, xmit=PIN_C6, rcv=PIN_C7)
your clock speed may not support the baud rate within acceptable tollerances, but you can always choose a different crystal if your design will accept it.
then you can handle incomming MIDI with the INT_RDA interrupt handler incorporating kbhit(), getc() and a recieve buffer. process the receive buffer in the main program loop (so you dont miss incomming data) and send MIDI using putc(), etc.
have a look on this forum for methods of reading and parsing serial data, you should find plenty of examples. _________________ Regards,
Simon. |
|
|
yerpa
Joined: 19 Feb 2004 Posts: 58 Location: Wisconsin
|
|
Posted: Mon Feb 27, 2006 10:41 am |
|
|
Here is a short but complete (tested) code for a MIDI drum set where the PIC reads the drumpads and sends out a MIDI string with note # and velocity data to a MIDI synthesizer. It is MIDI OUT, not MIDI IN, but you can see the individual bytes of the MIDI string if you look at the putc() commands in the code. Link:
http://www.reprolabs.com/drumsource.html
Good luck! |
|
|
bigbadotis
Joined: 27 Feb 2006 Posts: 1
|
|
Posted: Mon Feb 27, 2006 1:06 pm |
|
|
Thanks for the help! does this code look correct? I don't get the right numbers displayed in my terminal... wondering if I'm having electrical problems rather than code ones. The MIDI messages are triggering the interrupts at the correct times, but the values that are displayed in the terminal are incorrect.
Code: | #include <18F452.h>
#fuses EC
#use delay(clock=20000000)
#use rs232(stream=TERM, baud=9600, xmit=PIN_B7, rcv=PIN_B6, INVERT)
#use rs232(stream=MIDI, baud=31250, xmit=PIN_C6, rcv=PIN_C7)
BYTE msg[3];
int count=0;
void printMsg() {
fprintf(TERM, "Message is: %i %i %i \r\n", msg[0], msg[1], msg[2]);
}
#INT_RDA
void RxBytes() {
msg[count] = fgetc(MIDI);
count++;
if(count == 3) {
printMsg();
count=0;
}
}
main() {
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
while(TRUE) {}
} |
|
|
|
bigbadotis
Joined: 27 Feb 2006 Posts: 1
|
|
Posted: Mon Feb 27, 2006 3:35 pm |
|
|
Ok, got the above code to work.
Thanks for the help! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|