cancel
Showing results for 
Search instead for 
Did you mean: 

USB transfer code in DMA Service Routine

durgesh777
Associate II
Posted on December 12, 2011 at 13:59

I have an application where analog voltage is coverted by ADC and is saved in an array of size 128 byte. So the information to this array comes every few milliseconds (less than 1). Now i need to transfer the data to pc via usb.

So at the end of 'DMA complete ISR', how should i write the code or what are the lines to write?

I only know,

if (bDeviceState == (CONFIGURED))

            {

            

            while ((_GetEPTxStatus(ENDP1))==EP_TX_VALID);

            USB_SIL_Write(EP1_IN, data1, count);

 

            SetEPTxValid(ENDP1);

            

            while ((_GetEPTxStatus(ENDP1))==EP_TX_VALID);

            USB_SIL_Write(EP1_IN, data2, count);

     

            SetEPTxValid(ENDP1);

            }

where data1 is the first 64 byte and data2 is the second 64 byte so that the total data to be transmitted at once is 128 byte.

After each availability of the data through ADC and also after they are saved in variables (data1 and data2) i need them immediately to be transferred to PC before processing for other information.

The code that i implement is taking too longer time. So, it would be so nice if someone could suggest me to solve my problem.

Thanks in advance.

#usb-via-dma
1 REPLY 1
raptorhal2
Lead
Posted on December 12, 2011 at 17:25

My suggestion - double buffer the data. After one array buffer is full, start filling a second array buffer while the first is being sent to the PC. When the second array buffer is full, go back to the first buffer and repeat the process.

This assumes one buffer can be emptied before it is required to be filled. If not, you may need triple, quadruple, etc. buffers, assuming the total ADC data capture data size won't ultimately overrun the buffer space available.

Cheers, Hal