Hello,
I modified a "memory" example for AT91SAM7X-EK board and I am trying to read data from Endpoint 2 (OUT). The function USB_ReadEP returns a byte count of data received. But When I try to read the data buffer that is suppose to hold this data it doesn't match what the Host sent.
Here is the code I used:
BYTE * EP_Data; DWORD cnt; // Read EP2 data cnt = USB_ReadEP (0x02, (BYTE*)EP_Data); // Write data back to host USB_WriteEP(0x83, (BYTE *)EP_Data, cnt);
So I get the correct count of bytes received but the data in the EP_Data buffer doesn't match what I sent from the Host. Does anyone know if this is the correct way to read data from Endpoints?
Thanks Mario
BYTE * EP_Data;
Did you assign a valid buffer to the EP_Data? It's just a pointer.
Tsuneo
I just noticed this morning that I need to have an declared array and not just a pointer. I thought it would work either way since I wanted to do some data comparison using strncmp() function. Since I now know I have to declare it as BYTE EP_Data[] now I can't use that function anymore. So you are right, I didn't have it declared properly.
Thanks
comparison using strncmp() function. Since I now know I have to declare it as BYTE EP_Data[] now I can't use that function anymore.
What makes you think that? I suggest you go back to you C textbook and re-read the chapter on "pointers and arrays" (there's bound to be one).
Since I now know I have to declare it as BYTE EP_Data[] now I can't use that function anymore.
Don't you mean: BYTE EP_Data{ENOUGH_ROOM_TO_FIT_THE_ANSWER];
The maximum packet size is defined in the wMaxPacketSize field of the endpoint descriptor.
ENOUGH_ROOM_TO_FIT_THE_ANSWER = wMaxPacketSize
The transfer of greater size is split into the packets of this size. The last packet of the transfer may be "short packet", less than wMaxPacketSize.
Yes that's what I mean, I was just trying to say that I need an array :)