set currentAddress to send data to memori

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
ardiansyah_mrit
Posts: 10
Joined: Sun Oct 09, 2011 6:14 am
Contact:

set currentAddress to send data to memori

Post by ardiansyah_mrit » Mon Nov 07, 2011 12:45 pm

i need help, i has can to read data from eeprom in my pc...
but i can't to write data to eeprom from my pc, i think the currentAddress variable in usbFunctionSetup() doesn't get data buffer from my pc,
it just get data from it initial in usbFuctionSetup().

how to set currentAddress in usbFunctionSetup to get data from PC ??

i'm using at93c46 IC for my eeprom.

this is my code on micro (usbFunctionSetup):

Code: Select all

if(rq->bRequest == USBRQ_HID_SET_REPORT){
      int i;
            /* since we have only one report type, we can ignore the report-ID */
            at93c46_ewen();
         
         bytesRemaining = 128; //128 bit
           
         for(i=0; i<bytesRemaining;i++){
            if(i == datanya[currentAddress])
               currentAddress=datanya[i];
         }
            return USB_NO_MSG;  /* use usbFunctionWrite() to receive data from host */
        }


this is my code on micro (usbFuctionWrite) :

Code: Select all

uchar usbFunctionWrite(uchar *data, uchar len){

   if(bytesRemaining == 0)
      return 1; /* end of transfer */

   if(len > bytesRemaining)
      len = bytesRemaining;
   
   if(test){
      
      int i;
      for(i = 0; i < len; i++){      
            if(currentAddress == i)
               at93c46_write(i, data[0]);                  
      }
   }

   currentAddress += len;
   bytesRemaining -= len; // bytes = 0
   return bytesRemaining == 0;
}


and this is my code on PC/Host with .C :

Code: Select all

int pos,i;
        int buflen = sizeof(buffer);
        memset(buffer, 0, sizeof(buffer));
         
        printf("Masukkan alamatnya : ");
        scanf("%d", &addr);
       
        printf("Masukkan Nilai : ");
        scanf("%d", &pos);
       
        buflen = addr;
       
        for(i=0; i< 129 ;i++){
         if(i == addr)
            buffer[addr] = pos;
      }
        hexWrite(buffer,  buflen);//writing to memori method


best reagard
thanks be for.

Post Reply