{"id":162,"date":"2004-05-24T15:55:50","date_gmt":"2004-05-24T20:55:50","guid":{"rendered":"http:\/\/www.tigoe.net\/pcomp\/code\/category\/basicx\/162"},"modified":"2008-03-01T16:00:18","modified_gmt":"2008-03-01T21:00:18","slug":"midi-for-the-bx-24","status":"publish","type":"post","link":"https:\/\/www.tigoe.com\/pcomp\/code\/BX-24\/162\/","title":{"rendered":"MIDI for the BX-24"},"content":{"rendered":"<p>\nThis page covers the details of MIDI communication on the BX-24.\n<\/p>\n<p>To send MIDI out from the BX-24, you use the serial commands. You need to set the baudmode to match MIDI settings. You can&#8217;t use COM3 for MIDI, because it can&#8217;t reach the required baud rate, so you have to use COM1.  Wiring is as follows:<\/p>\n<p><!--more--><\/p>\n<table width=\"20%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"\/pcomp\/img\/bx-midiout.jpg\" alt=\"\" height=\"172\" width=\"350\" border=\"0\"><\/td>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"\/pcomp\/img\/midi-photo1.jpg\" alt=\"\" height=\"320\" width=\"240\" border=\"0\"><\/td>\n<\/tr>\n<\/table>\n<p>You can only set the COM1 serial port to a rate close enough to the baudrate necessary for MIDI. This means you won&#8217;t be able to use debug.print statements in your program, as the baud rate will be wrong for the BX-24 development environment. It also means that you can&#8217;t use just any I\/O pins. You have to use the TX and RX pins of the BX-24 for your output and input, respectively (pins 1 and 2).<\/p>\n<p>I find it&#8217;s best to disconnect the MIDI output from the TX pin while programming, to minimize the ubiquitous &quot;Error Halting BX-24&quot; message, then reattach it once the program&#8217;s downloaded.<\/p>\n<pre>    call openCom(1, 9600, inputBuffer, outputBuffer)\n register.ubrr = 14<\/pre>\n<p>This opens the COM1 serial port, then resets the baud rate to 30,720 baud, the closest it can get to MIDI&#8217;s 31,250 baud.<\/p>\n<p>Then, you send messages according to the MIDI spec. For example, a noteon channel 1, middle C (note 69), medium velocity (velocity 64) would be:<\/p>\n<pre>dim midiCmd as byte\ndim note as byte\ndim velocity as byte\n...\nmidiCmd = 144\nnote = 69\nvelocity = 64\ncall putQueue(OutputBuffer, midiCmd, 1)\ncall putQueue(OutputBuffer, note, 1)\ncall putQueue(OutputBuffer, velocity, 1)<\/pre>\n<p>and a noteoff for the same would be:<\/p>\n<pre>midiCmd = 128\nnote = 69\nvelocity = 0\ncall putQueue(OutputBuffer, midiCmd, 1)\ncall putQueue(OutputBuffer, note, 1)\ncall putQueue(OutputBuffer, velocity, 1)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This page covers the details of MIDI communication on the BX-24. To send MIDI out from the BX-24, you use the serial commands. You need to set the baudmode to match MIDI settings. You can&#8217;t use COM3 for MIDI, because it can&#8217;t reach the required baud rate, so you have to use COM1. Wiring is &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.tigoe.com\/pcomp\/code\/BX-24\/162\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;MIDI for the BX-24&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,24],"tags":[],"class_list":["post-162","post","type-post","status-publish","format-standard","hentry","category-BX-24","category-circuits"],"_links":{"self":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/comments?post=162"}],"version-history":[{"count":0,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/162\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/media?parent=162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/categories?post=162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/tags?post=162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}