Sunday, February 10, 2013

We were trying to have a complete 8-bit port on ATmega8 and at the same time implement Objective Development's V-USB stack to communicate with the chip.

To develop a proper example case we decided to use the BootloadHID example from Objective Development. The reason was that we needed a boot loader as easy as BootloadHID which does not need drivers on any platform. The command line program provided with this serves as an example to go ahead with the implementation.
ATmega8 PDIP28 Pinout

On the 8-bit port side we had ATmega8 in PDIP28 pin package. In this package "Port D" is the only port that has complete 8-bits. However for V-USB implementation we generally need to use PD4(D-) and PD2(D+) pins. This means that the D port cant be used for other things. If we want to use the "Port B" for 8-bit output then we can't have Crystal oscillator needed for the V-USB. Thus to solve this problem we tried another hack by modifying the interrupt configuration of V-USB. This hack was inspired by the USB2LPT implementation of Henrik Haftmann.
We use Ubuntu development environment and AVR Dragon as ISP for programming.

In PortB we have PB0 pin 14 which has ICP1 feature. This can act as Interrupt. Exactly what we need for the D+ line in the V-USB Stack. This also implies that we would not be able to use TIMER1 input compare or output compare functions. In our usage scenario we needed neither so we when ahead with the implementation.

Here is our Hardware connections:
                            [] 1.5k
D- => ----/\/\/\------------+- => PB1 pin 15

D+ => ----/\/\/\-------------- => PB0 pin 14 (ICP1)

We used 2 Diodes (1N4007) to reduce the USB bus voltage to 3.3V. Rest of the connections are similar to any other V-USB implementations. We use the 12MHz crystal.

Next you need to download the BootloadHID and apply the fix as shown.

In the firmware directory open the file 'bootloaderconfig.h' -
Change the following from line 42 to line 50:
/* This is the port where the USB bus is connected. When you configure it to
 * "B", the registers PORTB, PINB and DDRB will be used.
#define USB_CFG_DMINUS_BIT      1
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
 * This may be any bit in the port.
#define USB_CFG_DPLUS_BIT       0

And save the file. This would configure the pins for D+ and D-. We have kept the boot loading jumper at PD3 pin 4 of the ATmega8.

In the firmware directory open the file 'usbconfig.h' -
Add the following after line 273 just before '#endif /* __usbconfig_h_included__ */':
#define USB_INTR_CFG        TCCR1B
#define USB_INTR_CFG_SET    0    // no configuration necessary
#define USB_INTR_CFG_CLR    0
#define USB_INTR_ENABLE        TIMSK
#define USB_INTR_VECTOR        TIMER1_CAPT_vect

This would enable the use of ICP interrupt in the V-USB stack to communicate on USB. Save these files and build the code.
Thus now we have successfully moved the D+ and D- pins to Port B which gives us a complete 8-bit Port D.

Hope that you would find this hack useful. Let us know your thoughts, suggestions and feedbacks.

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to Boseji's Blog

Popular Post

Blogger templates


Creation by Electronics Hobbyists from Bharat(India) to encourage & help people. This blog hosts the numerous innovations, discoveries and projects we provide.
Our Research Wing Adhar Labs
Contact Form | Email Address
We Support Open Source Hardware Definition v1.0
Creative Commons License
All works on this blog are licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at and

Permissions beyond the scope of this license may be available at
Thank you for all your support.

© A.D.H.A.R Labs Research 2008-2013 . Powered by Blogger.

Follow by Email


PCB Unit Converter


- Copyright © Electronics for Bharat -Robotic Notes- Powered by Blogger - Designed by Johanes Djogan -