Welcome

This blog has permanently moved to
https://boseji.com

Contact Form | Email Address

© 2018 All rights reserved by Boseji

Thank you for all your support.

Sunday, February 10, 2013

Using Alternative Pins for AVR V-USB Implementation

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:
VUSB=>--|>]--|>]--VCC-------+
                            [] 1.5k
D- => ----/\/\/\------------+- => PB1 pin 15
           220E

D+ => ----/\/\/\-------------- => PB0 pin 14 (ICP1)
           220E
USBGND => GND

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:
#define USB_CFG_IOPORTNAME      B
/* 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_ENABLE_BIT    TICIE1
#define USB_INTR_PENDING    TIFR
#define USB_INTR_PENDING_BIT    ICF1
#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.

No comments:

Post a Comment