Array shift in C

Hello.

I'm programming a microcontroler, and I've a problem with transfering Data.

I've created an array of 512 short int and in each short there is a 16bit ADC value which I want to transfer throw USB.

The problem is I'm using USB bulk transfer with 64 char array for bulk transfer.

I've my values being transfer and I want to shift my 512 short int in 32 char each shifting. I believe the correct way is to use pointers.

Here's the code to better understanding:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
unsigned short int DataToTransfer[512]; //The Data is in there (I'm sure)
//(...)
unsigned int b;
for(b=0;b<16;b++)
{
    unsigned int l;
    for(l=0;l<1;l++){
        unsigned int j,i;
        for(j=0, i=0;j<64;j++)
        {					
           INPacket[j]=DataToTransfer[i];
           j++;
           INPacket[j]=DataToTransfer[i]>>8;
           i++;
        }	
        if(!USBHandleBusy(USBGenericInHandle))		
        {
             USBGenericInHandle = USBGenWrite(USBGEN_EP_NUM,(BYTE*)&INPacket,USBGEN_EP_SIZE);
        }
    }
}


When I use this code, the first 32 values of the array are send and displayed in a chart 16 times (16*32=512). I just need to shift the array to send not the same 32 values but the other values in the array. Using pointers is the correct way but I dont know how.
I know I need to assign a pointer:
short int *ptr;
and then assign it to other part of the array I don't know how. Could anyone help me?

Thank you.
Assuming USBGEN_EP_SIZE = 64 (bytes), and assuming that USBGenWrite() takes a byte array:

1
2
3
4
5
6
7
8
9
BYTE *curChunk = reinterpret_cast<BYTE*>(DataToTransfer);
for (int i = 0; i < sizeof(DataToTransfer) / USBGEN_EP_SIZE; i++)
{
    if(!USBHandleBusy(USBGenericInHandle))		
    {
         USBGenericInHandle = USBGenWrite(USBGEN_EP_NUM, curChunk, USBGEN_EP_SIZE);
    }
    curChunk += USBGEN_EP_SIZE;
}


The above would require that sizeof(DataToTransfer) % USBGEN_EP_SIZE == 0.
Topic archived. No new replies allowed.