cancel
Showing results for 
Search instead for 
Did you mean: 

Using memcpy to get data from ADC buffer to use elsewhere

MCrew.1
Associate III

Hello,

I am trying to use the memcpy function to transfer data from the ADC data buffer to a separate data buffer, but when I call memcpy, only the first 1400 of 6000 samples gets copied, while the remainder of the buffer does not get updated. I noticed this when I added a breakpoint after the memcpy function and when I output the new data on a DAC and saw the following on an oscilloscope, where the green toggle indicates when the HAL_ADC_ConvCpltCallback function is called, and the blue is the data being output by the DAC after being copied from the ADC buffer. The function being read at the ADC is a simple ramp function:

0693W000005BZdyQAG.bmp 

I am wondering if there is any specific reason this may be occurring. I am using DMA for the ADC (Continuous DMA requests enabled) and a DAC on the STM32F413 MCU. The only thing being done in the callback is a flag being set.

Thanks,

MC

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Sure sounds like you're only copying 1/4 of the buffer, or only 1/4 of the buffer is populated. Perhaps there is an error due to interpreting X uint32_t values as X bytes instead of 4X bytes, or similar. It should not be hard to debug by setting a breakpoint at memcpy and comparing the source and destination buffers before and after.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

Sure sounds like you're only copying 1/4 of the buffer, or only 1/4 of the buffer is populated. Perhaps there is an error due to interpreting X uint32_t values as X bytes instead of 4X bytes, or similar. It should not be hard to debug by setting a breakpoint at memcpy and comparing the source and destination buffers before and after.

If you feel a post has answered your question, please click "Accept as Solution".
MCrew.1
Associate III

I had not realized that I had the incorrect size in the memcpy function. I changed that and got the expected output, Thank you!