Skip to main content
MSimo
Associate II
May 7, 2019
Question

HOW TO SAVE ADC RESULTS?

  • May 7, 2019
  • 7 replies
  • 2694 views

Hi everyone, I am new to the community and I am also not very expert on microcontrollers. I own a STM32F407G-DISC1. I was able to write the code for ADC (at least I think), but I don't know how to save the data on the memory. Can anyone tell me how to do it.

attached you can find the code I'm using

Thanks a lot.

This topic has been closed for replies.

7 replies

Ozone
Principal
May 7, 2019

Depends on what you mean with "saving to memory".

The ADC data already end up in the RAM of the MCU.

If you need them only for debugging, try semi-hosting to get them to your PC via debugger.

Or push them out via UART (RS232) or USB.

For permanent storage, you can add a SD card/interface to your discovery board, and use FatFS to store the values there.

MSimo
MSimoAuthor
Associate II
May 7, 2019

And is there a method to copy the results from RAM to a text file for example?

The input signal is a sinusoid and in the debug mode I use the "function editor", so that I can see the results on the "command window" as the sine wave advances. But with this method the ADC seems quite slow. (100Hz signal)

Ozone
Principal
May 7, 2019

> And is there a method to copy the results from RAM to a text file for example?

Sure you could do.

You can collect a number of samples in RAM, and write them to a PC via semihosting. This assumes you need those values only in the debug phase.

Actual implementation/code depends on your requirements, and your toolchain.

I don't use / work with Cube code, though.

> ... in the debug mode I use the "function editor", so that I can see the results on the "command window" as the sine wave advances. But with this method the ADC seems quite slow. (100Hz signal)

Not sure what you describing here, and what your environment is.

But any way of saving this ADC data will have an impact on application timing. Saving collected data concurrently in realtime makes an application more complex.

This might be a bit over the head for a beginner.

Start simple, and do small steps.

MSimo
MSimoAuthor
Associate II
May 7, 2019

But is there any way to write the result of my conversion on the flash memory?

example: my ADC has 10 channels.

         -1 conversion -> 1 memory cell

         -2 conversion -> 2 memory cell

                      .

                      .

                      .

        -1 conversion again -> 11 memory cell.

Is such a thing possible?

In RAM I understand that data is overwritten every time it is converted (or is it wrong?)

Ozone
Principal
May 7, 2019

Writing to Flash would be possible, yes.

Problems associated with Flash are:

- only page-wise erase possible (check for page sizes, usually 64 kbyte)

- writing (AFAIK) only in 32 bit words

- word write takes millisecond, during which code execution stalls

- limited durability (10k erase/program cycles guaranteed)

- values in Flash are as invisible to the outside as in RAM