Page 1 of 1

USB transmitter

Posted: Tue Jun 29, 2010 2:14 pm
by gates2231
hello friends
I am trying to make an USB transmitter which transmits data from the PC via USB cable

I programmed atmega32 with hid-data and it is working fine storing data in the eeprom and reading data

but i want this data to be moved into transmit buffer and transmitted

I am not able to understand how data is being sent from PC to the uC

I read all the firmware but there is nothing in main function and the hidtool is also vague

Please enlighten me
Thanking you

Re: USB transmitter

Posted: Tue Jun 29, 2010 9:40 pm
by frank26080115
http://vusb.wikidot.com/driver-api

Code: Select all

static uchar buffer[64];
static uchar currentPosition, bytesRemaining;
 
usbMsgLen_t usbFunctionSetup(uchar setupData[8])
{
    usbRequest_t *rq = (void *)setupData;   // cast to structured data for parsing
    switch(rq->bRequest){
    case VENDOR_RQ_WRITE_BUFFER:
        currentPosition = 0;                // initialize position index
        bytesRemaining = rq->wLength.word;  // store the amount of data requested
        if(bytesRemaining > sizeof(buffer)) // limit to buffer size
            bytesRemaining = sizeof(buffer);
        return USB_NO_MSG;        // tell driver to use usbFunctionWrite()
    }
    return 0;                               // ignore all unknown requests
}
 
uchar usbFunctionWrite(uchar *data, uchar len)
{
    uchar i;
    if(len > bytesRemaining)                // if this is the last incomplete chunk
        len = bytesRemaining;               // limit to the amount we can store
    bytesRemaining -= len;
    for(i = 0; i < len; i++)
        buffer[currentPosition++] = data[i];
    return bytesRemaining == 0;             // return 1 if we have all data
}


it shows how to get the data into a buffer