Multiple Programs on a Single ATmega?

31 views
Skip to first unread message

Andy Leviss

unread,
Oct 25, 2011, 8:56:36 PM10/25/11
to NYCResistor Microcontrollers Group
Hey gang,
Is there a way to set multiple programs up on the same ATmega (a 32u4,
particularly), and select one via a switch during boot? I'm trying to
create a device that can be selected to show up as either a USB MIDI
or a USB Keyboard, if that's at all possible.

TIA,
Andy

Michael Jamet

unread,
Oct 25, 2011, 9:36:57 PM10/25/11
to nycresistormi...@googlegroups.com
Hi Andy,

Why not just embed both functions in one program and then, upon boot, read a switch which then has your device act as either the USB keyboard or USB MIDI?  I think this will make your life easier and, if there are common functions, you will save on code space too.

Michael


--
You received this message because you are subscribed to the Google Groups "NYCResistor:Microcontrollers" group.
To post to this group, send email to nycresistormi...@googlegroups.com.
To unsubscribe from this group, send email to nycresistormicrocon...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nycresistormicrocontrollers?hl=en.


Andy Leviss

unread,
Oct 25, 2011, 9:44:57 PM10/25/11
to nycresistormi...@googlegroups.com
On Tue, Oct 25, 2011 at 9:36 PM, Michael Jamet <brookly...@gmail.com> wrote:
> Hi Andy,
> Why not just embed both functions in one program and then, upon boot, read a
> switch which then has your device act as either the USB keyboard or USB
> MIDI?  I think this will make your life easier and, if there are common
> functions, you will save on code space too.

I suppose that could work. Can anybody point me to an idiot's guide to
merging both device types? Thus far, I've just been using the prebuilt
Teensyduino cores, and finally managed to figure out how to get it all
working with my device name (easy enough on OS X and XP, involved
finding a compatible driver and hacking through the .INF on Win 7,
since Microsoft botched the USB MIDI class driver in 7, grr).

--A

mattq...@gmail.com

unread,
Oct 25, 2011, 9:44:32 PM10/25/11
to nycresistormi...@googlegroups.com
Is there anything stopping you from creating two separate ports on 1 device?

Sent via BlackBerry by AT&T


From: Michael Jamet <brookly...@gmail.com>
Date: Tue, 25 Oct 2011 21:36:57 -0400
Subject: Re: [NYCR:Microcontrollers] Multiple Programs on a Single ATmega?

Andy Leviss

unread,
Oct 25, 2011, 9:51:22 PM10/25/11
to nycresistormi...@googlegroups.com
On Tue, Oct 25, 2011 at 9:44 PM, <mattq...@gmail.com> wrote:
> Is there anything stopping you from creating two separate ports on 1 device?

The fact that there's only one USB port on the MCU, and I'd rather not
have to put two MCUs in to only use one at a time...

--Andy

Dave Clausen

unread,
Oct 26, 2011, 1:01:12 PM10/26/11
to nycresistormi...@googlegroups.com
I've never worked with a mega32u or with a teensyduino, however I have used the at90usb series which I believe is similar to the mega32u.  It is very possible for the one microcontroller to act as both a keyboard and a MIDI device simultaneously, if that's what you want. It is also possible for you to dynamically choose one based on the position of a switch. However you may not be able to do any of this with the stock Teensyduino development tools.  You probably will have to interact directly with the microcontroller's native USB APIs, which I suspect are a lot more complicated than the teensyduino library APIs .  It's been a while since I've done this so I've forgotten all the details, but you can see some sourcecode here: http://dclausen.net/projects/tfam/ . This is an at90usb128 device that implemented both the keyboard and mouse protocols. It didn't dynamically switch between one and the other, but it will at least give you some idea of how to use the USB API directly and how to implement multiple USB device types using a single program.

David Rorex

unread,
Oct 31, 2011, 4:46:28 PM10/31/11
to nycresistormi...@googlegroups.com
The library you want to look into is called "LUFA", it makes doing USB on AVR's much easier than using the native USB API as mentioned below. I'm not sure offhand, but I believe the teensyduino libraries use LUFA internally. It can do stuff such as multiple USB devices in one, included in the many LUFA examples are things like: Mass Storage+Keyboard, Serial Port+Mouse, Keyboard+Mouse.
Reply all
Reply to author
Forward
0 new messages