Hi Friends,
I have been working on CY7C68013A EZ-FX2LP USB based micro controller, I have written code for IN/OUT operation i.e, Read and Write operation of USB.
I am initially reading data from HOST a bulk 64 Bytes of data and storing it in a location starting from 0xE000 which is the starting address of scrachpad memory of 512 Bytes, after which if i want to read data from this location I am initially getting a JUNK first time ,latter next read I get actual value, I mean to say that after write is done to this memory location in RAM, every first time i read I get previous value and the actual value is only reflected in the next read operation,
I tried a lot , but i am not able to find out what is the exact problem, I have pasted code below.
// INITIALIZATION CODE void TD_Init(void) // Called once at startup { BYTE i=0; // we are just using the default values, yes this is not necessary... EP1OUTCFG = 0xA0; SYNCDELAY; EP1INCFG = 0xA0; SYNCDELAY; // see TRM section 15.14 EP1INCS = 0x00; SYNCDELAY; EP2CFG = 0x82; SYNCDELAY; EP2BCL = 0xC0; // arm EP2OUT by writing byte count w/skip. SYNCDELAY; EP2BCL = 0xC0; // arm EP2OUT by writing byte count w/skip. SYNCDELAY; EP1INBC = 0x40; // EP2BCH = 0x02; // arm EP2OUT by writing byte count w/skip. // SYNCDELAY; // EP2BCH = 0x02; // arm EP2OUT by writing byte count w/skip. // SYNCDELAY; // enable dual autopointer feature SYNCDELAY; AUTOPTRSETUP |= 0x01; } TD_Poll() { /* -> USB OUT PACKET TRANSFER MODULE -> BULK - 64BYTES -> EP2 - ENDPOINT 2 -OUT DATA TRANSFER */ if(!(EP2468STAT & 0x01)) { ACC =XBYTE[0x8800]; Addr = 0xE000; // scrachpad area starting Addr AddrFIFO = 0xF000; //EP2FIFO starting Addr for( i = 0x0000; i < 64; i++ ) { XBYTE[Addr++]= XBYTE[AddrFIFO++]; } SYNCDELAY; EP2BCL = 0xC0; ACC=XBYTE[0x8800]; } /* -> USB IN PACKET TRANSFER MODULE -> BULK - 64BYTES -> EP1 - ENDPOINT 1 -IN DATA TRANSFER */ if(!(EP1INCS & bmEPBUSY)) //check for EP1IN bit, wait for BUSY Bit =0 { count=EP1INBC; // Load count with EP1 received buffer size /* for(Addr=0xE000;Addr<0xE040;Addr++) // load data to scrachpad RAM ,starting from 0xE000 to 0xE040 (64Bytes) { XBYTE[Addr]=in; // Incremental data for every read operation from HOST } in++; */ // Increment value for one Read operation Addr=0xE000 ; // Intial ScrachPad Address for(i=0;i<count;i++) // 64 Bytes Loop Count { // EP1INBUF[j]=BufferOUT[i]; // Transfer Data from scrachpad RAM Area to EP1 EP1INBUF[j]=XBYTE[Addr++]; j++; } SYNCDELAY; // Sychronization Delay j=0; EP1INBC = 0x40; // Re-Arm EP1 Byte Count SYNCDELAY; // Sychronization Delay ACC=XBYTE[0x9800]; // LED 3 ON SYNCDELAY; ACC=XBYTE[0xA800]; // LED 4 ON SYNCDELAY; } ACC=XBYTE[0x8000]; SYNCDELAY; ACC=XBYTE[0x9000]; // LED 3 ON SYNCDELAY; ACC=XBYTE[0xA000]; // LED 4 ON SYNCDELAY; } }
Please reply me if there is any mistake, waiting for a positive reply,
Abhilash