Hi.
I'm trying to send MIDI signal from a PIC microcontroller to plug any equipment to a DIN socket.
If anybody have ever done this, i'd like some informations about the way to do this.
I have a 3 pin connector to link to my external DIN socket, connected as on this shematic :
https://www.sonelec-musique.com/images3/electronique_interfaces_midi_out_001a.gif
I use a PIC18F26K22 and for transmission I use the USART module.
Recept doesn't interest me, I'm just trying to send this signal but I don't know what will be the equipment which will be downstream (otherwise it'd understand MIDI signals).
The original signal is read from a SD card by SPI connection. I have ever controlled that this reading is OK.
When I have to begin or stop a note, Midi standard works at 31250kHz and imposes this sequence (3 bytes) :
In the MIDI files, each message is separated by some bytes to indicate a delay to wait between the two messages.
My µC operates delays read in the Midi file and send "in time" the activations or deactivations of notes.
Here is my code :
When I send a signal, I can control with digital oscilloscope that this signal exists. Unfortunately, I tried to connect my MIDI cable to various equipments and it seems they never receive anything (or they don't understand the messages).
Could you help me to understand what happen, what isn't correctly configured or what is the error when sending my MIDI message ?
Should I send a "0 delay message" before each message to prevent the external equipment to understand my message as a delay ?
Thanks so much for your help.
I'm trying to send MIDI signal from a PIC microcontroller to plug any equipment to a DIN socket.
If anybody have ever done this, i'd like some informations about the way to do this.
I have a 3 pin connector to link to my external DIN socket, connected as on this shematic :
https://www.sonelec-musique.com/images3/electronique_interfaces_midi_out_001a.gif
I use a PIC18F26K22 and for transmission I use the USART module.
Recept doesn't interest me, I'm just trying to send this signal but I don't know what will be the equipment which will be downstream (otherwise it'd understand MIDI signals).
The original signal is read from a SD card by SPI connection. I have ever controlled that this reading is OK.
When I have to begin or stop a note, Midi standard works at 31250kHz and imposes this sequence (3 bytes) :
- 0x8C to open a note, C being the channel (0-15) when we communicate with multiple instruments, or 0x9C to close a note.
- 0xNN, to send what note to open (0-128)
- 0xVV, the "velocity", corresponding to level at which note should be played for instrument which support it.
In the MIDI files, each message is separated by some bytes to indicate a delay to wait between the two messages.
My µC operates delays read in the Midi file and send "in time" the activations or deactivations of notes.
Here is my code :
Code:
// Ports config
// As datasheet says : "For all modes of EUSART operation, the TRIS control bits corresponding to the RXx/DTx and TXx/CKx pins should be set to ‘1’. The EUSART control will automatically reconfigure the pin from input to output, as needed."
TRICbits.TRISC6 = 1;
// I don't use receiver, it's pin (RC7) is used for another function and is set as an output.
// Usart config
TXSTA1 = 0x00; // 8bit transmission, asyncronous, low speed baud rate.
RCSTA1 = 0x80; // Enable serial port
BAUDCON1 = 0x00; // Idle state is high
SPBRG1 = 7; // working at 16MHz SPBRG = (Fosc/31250/64)-1
// Next I enable transmitter
TXSTA1birts.TXEN = 1;
// For sending a byte, I use this function, it's called 3 times in a row, to send the 3 bytes of a MIDI message :
void UART_Write(unsigned char Data) {
// Wait for the end of an eventual current transmission
while (!TXSTA1bits.TRMT);
TXREG1 = Data;
}
When I send a signal, I can control with digital oscilloscope that this signal exists. Unfortunately, I tried to connect my MIDI cable to various equipments and it seems they never receive anything (or they don't understand the messages).
Could you help me to understand what happen, what isn't correctly configured or what is the error when sending my MIDI message ?
Should I send a "0 delay message" before each message to prevent the external equipment to understand my message as a delay ?
Thanks so much for your help.