Forums

USBD12 Goodlink connection

Started by Vivek B November 17, 2007
I am trying to establish a connection between my Atmel Atmega 16 and
USBD12 . PORTC is connected to the USBD12's data bits and the
following pins of the PORTD is connected to RD_N, WR_N and AO.

 RD_N      PD4
 WR_N     PD5
 A0          PD7

I am not getting a goodlink connection just by initializing USBD12. I
mean the led is not getting lighted up. The hardware part is perfect
as someone else have done USB communication with assembly code
earlier. The pins of USBD12 that can be accessed by the Atmel are
RD_N, WR_N, AO and DATA pins.  Here is my C code.

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>

#include "global.h"
uint16_t ee_pwm __attribute__((section(".eeprom"))) = 42;

//----- Begin Code
------------------------------------------------------------

#define USBRD PD4
#define USBWR PD5
#define USBA0 PD7


enum {USB_DATA,USB_COMM};

void delay(void)
{
	volatile uint16_t i;
	for(i=0;i<2000;i++);
}


void usb_write(uint8_t type,uint8_t data)
{
	DDRC = 0xff;
	DDRD |= _BV(USBRD) | _BV(USBA0) | _BV(USBWR);
	PORTC = data;
	switch(data){
		PORTD |= _BV(USBRD);
		case USB_DATA:
			PORTD &= ~(_BV(USBA0));

			break;
		case USB_COMM:
			PORTD |= _BV(USBA0);

			break;
	}
	PORTD &= ~(_BV(USBWR));
	delay();
	PORTD |= _BV(USBWR);
}

void usb_read(uint8_t * buffer, uint8_t reads)
{
	int i;

	DDRC = 0x0;
	DDRD |= _BV(USBRD) | _BV(USBA0) | _BV(USBWR);
	for(i=0;i<reads;i++){
		PORTD &= ~_BV(USBRD);
		delay();
		buffer[i] = PORTC;
		PORTD |= _BV(USBRD);
		delay();
	}
}

void initialize(void)
{
	DDRC = 0xff;
	PORTC = 0xff;
	PORTD |= _BV(USBRD);
	PORTD |= _BV(USBWR);

	PORTD &= ~(_BV(USBA0));

//	printf("CMD:  Set Address/Enable\r\n");
	usb_write(USB_COMM, 0xD0);

//	printf("\tDATA: 0x80 (Enable, no address)\r\n");
	usb_write(USB_DATA, 0x80);

//	printf("CMD:  Set endpoint enable\r\n");
	usb_write(USB_COMM, 0xD8);
//	printf("\tDATA: 0x01 (Enabled)\r\n");
	usb_write(USB_DATA, 0x01);

//	printf("CMD:  Set Mode\r\n");
	usb_write(USB_COMM, 0xF3);
//	printf("\tDATA: No Lazy Clock, Clock Running, ");
//	printf("Interrupts=1, SoftConnect=1\r\n");
	usb_write(USB_DATA, 0x1E);
//	printf("\tDATA: Start of Frame interrupt disabled, ");
//	printf("Set-to-one not set, ");
//	printf("\r\n\t\tClock Division Factor = 1011b\r\n");
	usb_write(USB_DATA, 0x08);

//	printf("End of Program\r\n");
}

int main(void)
{
	initialize();
	while(1){

	}
}

Any idea, where it is going wrong???? Any help would be appreciated.

Thanking you

sincerely
"Vivek B" <vivekb1985@gmail.com> wrote in message 
news:6d547854-2ee8-4462-9d44-e1a857e943c6@d27g2000prf.googlegroups.com...
>I am trying to establish a connection between my Atmel Atmega 16 and > USBD12.
Try developers forum on http://www.usb.org/phpbb/ Leo Havm&#2013266168;ller.
On Sat, 17 Nov 2007 02:45:59 -0800 (PST), Vivek B <vivekb1985@gmail.com>
wrote:

>I am trying to establish a connection between my Atmel Atmega 16 and >USBD12 . PORTC is connected to the USBD12's data bits and the >following pins of the PORTD is connected to RD_N, WR_N and AO.
I haven't seen any obvious error yet but would like to ask why you don't use the AT90USB162, which has USB built-in with free C libraries supplied by Atmel? Mit freundlichen Gr&#2013266172;&#2013265951;en Frank-Christian Kr&#2013266172;gel
"Vivek B" <vivekb1985@gmail.com> wrote in message 
news:6d547854-2ee8-4462-9d44-e1a857e943c6@d27g2000prf.googlegroups.com...
>I am trying to establish a connection between my Atmel Atmega 16 and > USBD12 . PORTC is connected to the USBD12's data bits and the > following pins of the PORTD is connected to RD_N, WR_N and AO. > > RD_N PD4 > WR_N PD5 > A0 PD7 > > I am not getting a goodlink connection just by initializing USBD12. I > mean the led is not getting lighted up. The hardware part is perfect > as someone else have done USB communication with assembly code > earlier. The pins of USBD12 that can be accessed by the Atmel are > RD_N, WR_N, AO and DATA pins. Here is my C code. > > #include <avr/io.h> > #include <avr/interrupt.h> > #include <avr/eeprom.h> > > #include "global.h" > uint16_t ee_pwm __attribute__((section(".eeprom"))) = 42; > > //----- Begin Code > ------------------------------------------------------------ > > #define USBRD PD4 > #define USBWR PD5 > #define USBA0 PD7 > > > enum {USB_DATA,USB_COMM}; > > void delay(void) > { > volatile uint16_t i; > for(i=0;i<2000;i++); > } > > > void usb_write(uint8_t type,uint8_t data) > { > DDRC = 0xff; > DDRD |= _BV(USBRD) | _BV(USBA0) | _BV(USBWR); > PORTC = data; > switch(data){ > PORTD |= _BV(USBRD); > case USB_DATA: > PORTD &= ~(_BV(USBA0)); > > break; > case USB_COMM: > PORTD |= _BV(USBA0); > > break; > } > PORTD &= ~(_BV(USBWR)); > delay(); > PORTD |= _BV(USBWR); > } > > void usb_read(uint8_t * buffer, uint8_t reads) > { > int i; > > DDRC = 0x0; > DDRD |= _BV(USBRD) | _BV(USBA0) | _BV(USBWR); > for(i=0;i<reads;i++){ > PORTD &= ~_BV(USBRD); > delay(); > buffer[i] = PORTC; > PORTD |= _BV(USBRD); > delay(); > } > } > > void initialize(void) > { > DDRC = 0xff; > PORTC = 0xff; > PORTD |= _BV(USBRD); > PORTD |= _BV(USBWR); > > PORTD &= ~(_BV(USBA0)); > > // printf("CMD: Set Address/Enable\r\n"); > usb_write(USB_COMM, 0xD0); > > // printf("\tDATA: 0x80 (Enable, no address)\r\n"); > usb_write(USB_DATA, 0x80); > > // printf("CMD: Set endpoint enable\r\n"); > usb_write(USB_COMM, 0xD8); > // printf("\tDATA: 0x01 (Enabled)\r\n"); > usb_write(USB_DATA, 0x01); > > // printf("CMD: Set Mode\r\n"); > usb_write(USB_COMM, 0xF3); > // printf("\tDATA: No Lazy Clock, Clock Running, "); > // printf("Interrupts=1, SoftConnect=1\r\n"); > usb_write(USB_DATA, 0x1E); > // printf("\tDATA: Start of Frame interrupt disabled, "); > // printf("Set-to-one not set, "); > // printf("\r\n\t\tClock Division Factor = 1011b\r\n"); > usb_write(USB_DATA, 0x08); > > // printf("End of Program\r\n"); > } > > int main(void) > { > initialize(); > while(1){ > > } > } > > Any idea, where it is going wrong???? Any help would be appreciated. > > Thanking you > > sincerely
I did not go right through your code, but I believe the goodlink led does not activate until enumeration with a device is done. Phil W