LoopBack fails for the second time

Hi, I am new to this group. I am using cypress fx2lp usb controller.

I have written a loopback firmware for it and successfully downloaded o its ram.

On the host side I have written an application which opens the usb device send some data, read it back, verify and close the device.

When I send 512B for the first time loopback works but when I sen anything after that loopback fails. Following is code for TD_Init() an TD_Poll().

void TD_Init() { CPUCS = 0x12; // 48 mhz and CLKOUT enabled SYNCDELAY; IFCONFIG = 0xE3;

// EP 2 4 6 8 Configuration SYNCDELAY; EP2CFG = 0xE2; // IN BULK 512 Double-Buffered SYNCDELAY; EP4CFG = 0xA0; // OUT BULK 512 Double-Buffered SYNCDELAY; EP6CFG = 0xE2; // IN BULK 512 Double-Buffered SYNCDELAY; EP8CFG = 0xA0; // OUT BULK 512 Double-Buffered

// FIFO Reset SYNCDELAY; FIFORESET = 0x80; SYNCDELAY; FIFORESET = 0x02; SYNCDELAY; FIFORESET = 0x04; SYNCDELAY; FIFORESET = 0x06; SYNCDELAY; FIFORESET = 0x08; SYNCDELAY; FIFORESET = 0x00; // Out EP 4 8 Byte Count // Out EP's do not come up armed SYNCDELAY; EP4BCH = 0x00; // Arm EP4OUT by writing to low byt count twice (double buffered) SYNCDELAY; EP4BCL = 0x80; // Arm EP4OUT by writing to low byt count twice (double buffered) SYNCDELAY; EP4BCH = 0x00; // Arm EP4OUT by writing to low byt count twice (double buffered) SYNCDELAY; EP4BCL = 0x80; SYNCDELAY; EP4BCH = 0x00; // Arm EP4OUT by writing to low byt count twice (double buffered) SYNCDELAY; EP8BCL = 0x80; // Arm EP8OUT by writing to low byt count twice (double buffered) SYNCDELAY; EP4BCH = 0x00; // Arm EP4OUT by writing to low byt count twice (double buffered) SYNCDELAY; EP8BCL = 0x80; AUTOPTRSETUP |= 0x01; }

void TD_Poll(void) { WORD i; WORD count;

if( !(EP2468STAT & bmEP4EMPTY) ) { // check EP4 EMPTY(busy) bit in EP2468STAT (SFR), core set's this bi when FIFO is empty

if( !(EP2468STAT & bmEP2FULL) ) { // check EP2 FULL(busy) bit in EP2468STAT (SFR), core set's this bi when FIFO is full

APTR1H = MSB( &EP4FIFOBUF ); APTR1L = LSB( &EP4FIFOBUF );

AUTOPTRH2 = MSB( &EP2FIFOBUF ); AUTOPTRL2 = LSB( &EP2FIFOBUF );

count = (EP4BCH

Reply to
sajjan
Loading thread data ...

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.