Skip to main content
MCrew.1
Associate III
November 16, 2020
Solved

Using memcpy to get data from ADC buffer to use elsewhere

  • November 16, 2020
  • 2 replies
  • 2063 views

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

This topic has been closed for replies.
Best answer by TDK

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.

2 replies

TDK
TDKBest answer
November 16, 2020

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
MCrew.1Author
Associate III
November 16, 2020

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