UART/USI -> HID device?

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
Posts: 4
Joined: Thu Nov 15, 2007 11:18 am

UART/USI -> HID device?

Post by andrewbenson » Fri Oct 31, 2008 9:50 pm

I have built several sensor-interface devices using that are built around serial output (MIDI) using the hardware USI of an ATTiny26. Since I'd like to get away from the sort of limited and slow MIDI spec, I am wondering if it is possible to build an HID device using AVR-USB that reads USI/UART serial data and packs it up into an HID report as if it were e.g. a joystick. The idea is to build a modular system where I can plug different controller modules into the base UART->HID board to connect to the computer. All of the controller devices would use the same spec for sending controls (controller numbers, range, etc.). Will the UART interrupts interfere with the USB communication? How would you recommend that I get started? I have a lot of experience working with AVR's but haven't delved very deep into AVR-USB. Would the ATTiny2313 work as the USB chip?

Any advice is greatly appreciated.


Rank 1
Rank 1
Posts: 27
Joined: Sat Oct 20, 2007 5:58 pm

Post by gert » Mon Nov 03, 2008 9:30 pm

Hello Andrew

You asked a number of questions...

Will the UART interrupts interfere with the USB communication?
- Yes, it will. The USB code must not be interrupted.

How would you recommend that I get started?
- If synchronizing your devices with the USB 1msec "heartbeat" is an option, you can access your external devices while the USB host "isn't looking".
Depending on how much data you want to transfer through the USI it may get necessary to synchronize the transfer with the USB activity using a timer ("PLL style").

To get an idea of the CPU activity set a port pin in the USB interrupt code and clear it before entering the idle loop (don't forget to remove this extra line in the USB interrupt routine before doing anything serious with your new device! ).

Would the ATTiny2313 work as the USB chip?
- that depends on how big your USI transfer code is. HID requires more ROM space than low level USB transfer. Maybe a tiny45 or one of the small mega devices would be a better choice.


Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Tue Nov 04, 2008 1:00 pm

You CAN use a UART interrupt together with USB. But you must make sure that the first thing your interrupt routine does is to set the global Interrupt Enable flag. In GCC you do this by declaring the interrupt with "__attribute__ ((interrupt))".

Post Reply