MIDI interface using STM32 microcontroller

Thread Starter

zazas321

Joined Nov 29, 2015
936
Hey. I am currently trying to build some hardware for reading the midi device data. The device I am using is Akai MPK Mini Mk2 MIDI keyboard. It does not have a standard DIN connectors. Instead, it is using a single USB type A cable.

Most examples online are using MIDI to UART interface using octocoiplers:
upload_2019-7-4_11-52-12.png
First of all, I would only need MIDI IN as I would not be sending any commands out. I just need to read the data from the keyboard.

Secondly, I am not entirely sure whether this aproach is relevant for me as I have mentioned before - my device does not have standard MIDI connectors. What is the most convenient way to inferface with the device? Could I just use usb UART?
 

hexreader

Joined Apr 16, 2011
581
This device might be worth some research:

http://www.hobbytronics.co.uk/usb-host-midi

There is a compatibility list - you could see if your keyboard is listed.

Not sure if it gives the 3.3V logic levels, or 5V which is too high - you need to check.

No guarantees - it is your job to check if suitable and I will not refund you if it turns out to be no good for your application.

If my understanding is correct, then standard USB to TTL converter is of no use to you.
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
Is it possible to build a MIDI interface without additional hardware ? I was expecting that I will be able to achieve that using an STM32F469 microcontroller. The thing that confuses me the most is that the MIDI keyboard I am using uses a single USB A port for both: power and MIDI data, therefore I am not sure if I can read the MIDI from it using a usb serial?
 

MrChips

Joined Oct 2, 2009
30,706
I am going to take a stab at this though I am no expert here.

I believe the original MIDI interface was based on standard UART signalling protocol.
Hence if the MIDI instrument and your computer both supported UART communications you were good to go.

With the advent of USB interfaces, it is possible to communicate over USB cabling by using a USB-to-UART bridge such as Silicon Labs CP2102.

In your case, since the MIDI keyboard uses USB, you may as well connect to the STM32 using USB.

Are you using bare metal STM32F469 or are you using STM32F469 Discovery Kit?
You will need some kind of OS or are you going to create your own DIY OS?
You will need USB OTG libraries to connect to the USB interface.
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
Thanks for your answer MrChips.
To answer your questions:
I am using bare metal STM32F465 and will be developing software from scratch.


If using DIN cable, the MIDI data is send using a single port ( either TX or RX), I cannot get my head arround how the MIDI data would be transferred using USB, assuming that it has two outputs D+ and D-. I havent implemented the USB interface with a microcontroller myself yet, but from what I have noticed, D+ and D- are connected to USART RTS and CTS pins which i havent fully understood yet.
 

MrChips

Joined Oct 2, 2009
30,706
USB is not UART nor USART.
Basically, everything you have learned about UART goes out the window.

USB is a complementary differential signal sent on D+ and D-.
You cannot extract UART signalling from USB signals.

USB requires substantial overhead in order to enumerate the device, establish communications, and transfer command and data packets. This is not for the faint of heart.
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
Okay thanks for clarifying few things for me.

Also, maybe you would know if there is a particular reason why all MIDI interface circuits use +5V instead of 3.3V+? If you check the schematics I have posted above, you will see that both MIDI in and MIDI out use +5V. I am using stm32 microcontroller which is not 5V tolerant and I dont think I can pull the RX to +5V.

I have also found another schematics which shows that MIDI IN is +5v and MIDI OUT +3.3V:
upload_2019-7-4_16-50-37.png
 

Attachments

Thread Starter

zazas321

Joined Nov 29, 2015
936
I am considering option of using a USB to MIDI cable to connect my MIDI device to microcontroller using MIDI IN and MIDI OUT. Would that work?

My concern is how would I power the MIDI device as it does not have a dedicated connector or jack for power supply so the MIDI interface would also have to supply power.

How would I power the MIDIA device ?
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
I have just found some circuitry :


To me it seems like it would work. Powering the octocoupler using +5V and pulling RX to +3.3V logic.
Anyways, it doesnt explain how the MIDI device is powered :eek:
 

MrChips

Joined Oct 2, 2009
30,706
Personally, I don't think it will work because of what I have said. USB is not UART. They are not compatible.
But I could be wrong. What do I know.
 

Alec_t

Joined Sep 17, 2013
14,280
Your post #11 circuit is essentially an opto-isolated level-shifter. While it might play some part in your project it doesn't solve the issue of converting between the original MIDI signal protocol and the USB protocol. For that you will need driver software.
Anyways, it doesnt explain how the MIDI device is powered
A USB connector has two terminals for power (+5V and ground) plus at least two more for signals.
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
Im getting a bit confused. Are you guys suggesting me to stick with the USB? Lets say i connect my device to my microcontroller. I would be able to power the MIDI device using 5v regulator i have on my PCB. Where would I connect two signal pins and how do I extract information from it? Would i reaquire additional hardware for that or just software. Thsnk you all for help
 

MrChips

Joined Oct 2, 2009
30,706
In this scenario, you cannot convert USB to UART. They are not compatible.

An optocoupler is not fast enough to handle USB switching speeds.
 

hexreader

Joined Apr 16, 2011
581
No that will not work. ..... at least not on its own. What is pictured is a USB device, but you need a USB host.

Alec_t provided an excellent link in post #9 that explains it all really well. Play the video over-and-over until you understand fully.
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
I have seen that video. I am wondering if there is any way of building some interface myself that would allow me to read MIDI data. I have my microcontroller PCB and I could build an external device ( like MIDI host shown in the video ) which I could connect my micro and MIDI keyboard to.
Considering that the prices of those USB MIDI host devices are quite steep, I assume its quite complicated to build therefore I am not so sure if I will be able to manage that.

So in short, there is no simple way to read MIDI sent data from the USB Midi device using microcontroller?
 

hexreader

Joined Apr 16, 2011
581
You could spend years and tens of thousands of dollars designing and programming your own USB host software and hardware. ...If you can gain sufficient training and skills.

... or you could buy the devices mentioned for a few tens of dollars and have something up and running within days.

There is no simple option that I know of.

Keep dreaming.....

So in short, no.

The hobbytronics solutions ARE the cheap simple solutions. (but for some reason you see them as expensive)

Pity the hardware is mostly out of stock.

... at least... this is how I see it. I could be wrong.

EDIT: - sorry. Having read my own post it comes across as very rude. My problem not yours. Sorry
 
Last edited:

Thread Starter

zazas321

Joined Nov 29, 2015
936
No problem thank you for the information. I was just curious whether my STM32 can act as a USB host or should I refer it to 'computer'.

Anyway , i will probably look into these devices ant get one if its gonna save me time and hassle. But how would I connect my microcontroller to such device? Would it have to be UART to MIDI IN and OUT and the other side of the host is USB MIDI device
 
Top