Jump to content
43oh

MSP430 Launchpad - Midi Output


Recommended Posts

Hi everyone,

 

      I'm trying to implement a midi output communication, but there seem to be a problem and I'm not sure if it's with my software or hardware.

 

So here's what I'm getting... I'm trying to do it with a Launchpad rev 1.4 with the MSP430G2231 chip. I connected my launchpad to a midi connector like they told on the Teensy Midi Library page

 

http://www.pjrc.com/teensy/td_libs_MIDI.html

 

So translated to the launchpad:

P1_1 (TX pin) to midi Pin 5    (tried with and without a 220 ohms resistor)

GND to midi Pin 2

VCC to midi Pin 4 with a 220 ohms resistor

 

For the VCC, I tried with the VCC pin for a +3.3v and with the TP1 connection (5v from the usb connector) for a +5v, but I get the same result with both. Since midi is a +5v protocol, I tried to amplify the TX signal with the circuit on this page but this didn't work. I found here and here that I could make it works with a +3.3v circuit by lowering the 220 ohms resistor to something about 50 ohms, but this give me the same results as with the 220 ohms.

 

My results:

I'm able to receive a midi value when I send it with no amplification to the TX pins (with 3.3v or 5v VCC). That's great, but I'm only getting a Midi Program change of ProgramChange 0 channel 1 when I try to send a midi note value (with note values of about half and up the midi scale).

 

Over USB, I get the serial data and with this software I see that it sends a midi message that 1 or 2 byte is missing.

With the MIDI connector, I plug it straight into my computer with a midi-to-usb cable (M-Audio Uno)

 

For the code, mainly the midi example on the Energia IDE:

/*
 MIDI note player
 
 This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
 If this circuit is connected to a MIDI synth, it will play 
 the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.

 
 The circuit:
 * digital in 1 connected to MIDI jack pin 5
 * MIDI jack pin 2 connected to ground
 * MIDI jack pin 4 connected to +5V through 220-ohm resistor
 Attach a MIDI cable to the jack, then to a MIDI synth, and play music.

 created 13 Jun 2006
 modified 30 Aug 2011
 by Tom Igoe 

 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/MIDI
 
 */

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250);
}

void loop() {
  // play notes from F#-0 (0x1E) to F#-5 (0x5A):
  for (int note = 0x1E; note < 0x5A; note ++) {
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note, 0x45);
    delay(100);
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note, 0x00);   
    delay(100);
  }
}

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(byte cmd, byte pitch, byte velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}

 

 

Thanks a lot for any help !

 

   G

Link to post
Share on other sites

Most likely timing issue. My Booster Pack works perfectly with 3.6V, so voltage cannot be the issue here. BTW, use two 68 ohm resistors in your TX circuit.

 

I am not that familiar with Energia, but I have two suggestions.

First, make sure you use DCO calibration data.

Second, instead of using software UART, why not use hardware SPI. 2231's USI module can do 10 bit SPI, so you could emulate hardware UART.

Link to post
Share on other sites

Thanks guys for you respond !! Sorry for the little delay, was busy yesterday.

 

But yes, you're right, this should be a timing issue. I found out that with Energia it put the clock to 1mhz, so I "unlocked" the 16mhz settings. RobG, I'm not sure about what you're saying when you say to make sure to use DCO calibration data. I didn't use a lot the launchpad, I more used the STM32F4DISCOVERY, but is it just to put the DCO clock to 16mhz ? I found on the Energia library the part where it initialize the clock. Should it be fine with those settings:

 

void initClocks(void)
{
#ifdef __MSP430_HAS_BC2__
#if defined(CALBC1_16MHZ_) && F_CPU >= 16000000L
	BCSCTL1 = CALBC1_16MHZ;
	DCOCTL = CALDCO_16MHZ;
#elif defined(CALBC1_12MHZ_) && (F_CPU >= 12000000L)
	BCSCTL1 = CALBC1_12MHZ;
	DCOCTL = CALDCO_12MHZ;
#elif defined(CALBC1_8MHZ_) && (F_CPU >= 8000000L)
	BCSCTL1 = CALBC1_8MHZ;
	DCOCTL = CALDCO_8MHZ;
#elif defined(CALBC1_1MHZ_) && (F_CPU >= 1000000L)
	BCSCTL1 = CALBC1_1MHZ;
	DCOCTL = CALDCO_1MHZ;
#else
        #warning No Suitable Frequency found!
#endif
	/* SMCLK = DCO / DIVS = nMHz */
	BCSCTL2 &= ~(DIVS_0);
	/* ACLK = VLO = ~ 12 KHz */
        BCSCTL3 |= LFXT1S_2; 
#endif

#ifdef __MSP430_HAS_CS__
    CSCTL0 = CSKEY;                // Enable Access to CS Registers
  
    CSCTL2 &= ~SELM_7;             // Clear selected Main CLK Source
    CSCTL2 |= SELM__DCOCLK;        // Use DCO as Main Clock Source
    CSCTL3 &= ~(DIVM_3 | DIVS_3);  // clear DIVM Bits
#if F_CPU >= 24000000L
    CSCTL1 = DCOFSEL0 | DCOFSEL1 | DCORSEL;    //Level 2 / Range 1 : 24.0MHz
#elif F_CPU >= 16000000L
    CSCTL1 = DCORSEL;              //Level 0 / Range 1 : 16.0MHz
#elif F_CPU >= 12000000L
    CSCTL1 = DCOFSEL0 | DCOFSEL1 | DCORSEL;    //Level 2 / Range 1 : 24.0MHz
    CSCTL3 |= DIVM_1;              // Div = 2
#elif F_CPU >= 8000000L
    CSCTL1 = DCOFSEL0 | DCOFSEL1;  //Level 2 / Range 0 : 8.0MHz
#elif F_CPU >= 1000000L
    CSCTL1 = DCOFSEL0 | DCOFSEL1;  //Level 2 / Range 0 : 8.0MHz
    CSCTL3 |= DIVM_3;              // Div = 8
#else
        #warning No Suitable Frequency found!
#endif
//    CSCTL0 = 0;                    // Disable Access to CS Registers
#endif // __MSP430_HAS_CS__

}

 

Thanks also to mention the USI module, I found the part of the Energia that they implement a USI for Spi mode. I'll have a look into it !

 

Right now, I've got the 16mhz clock and it changes the kind of midi data that I'm receiving, but not to something accurate.

 

Thanks again for any tips ! I'll let you know my progress !

 

    G

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...