2019-05-07 03:28 AM
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.
2019-05-07 04:38 AM
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.
2019-05-07 04:51 AM
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)
2019-05-07 05:21 AM
> 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.
2019-05-07 05:39 AM
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?)
2019-05-07 06:24 AM
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
2019-05-07 06:38 AM
Milliseconds, woow !! Too slow.
At this point I do as you suggested before, or take a number of samples from the RAM and write them later on the PC. I thank you for your help and excuse my ignorance hahah
2019-05-07 07:10 AM
> ... and excuse my ignorance hahah
Learning is a process, and embedded SW is a complex field.
You can search for example applications with similar tasks/requirements, and examine the source code, how they do it.
Could be STM32, or another Cortex M family, or even a different architecture. Learning never stops.