NUCLEO-L476RG: Write ADC values into SD_CARD using SPI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-07-16 5:25 AM
Good Morning.
For my thesis work, I have to develop a sensor for seismocardiography based on sensortile.
Being unfamiliar with microcontrollers, I'm running some tests using an L476RG nucleo board.
I created a project that foresees continuous analog-digital conversion; I can save the data thus obtained in a circular buffer using dma but I cannot save the data obtained on sd.
When the HAL_ADC_ConvHalfCpltCallback interrupt occurs, I send the data contained in the first half of the buffer containing the readings of the adc to an auxiliary buffer using dma. At this point, when the memory to memory transfer is complete, I need a for loop to convert the data contained in the "TxBuffer" buffer into a string and concatenate these strings to create a single string to be saved on the SD (to reduce the time of writing).
The same should happen when the HAL_ADC_ConvCpltCallback interrupt occurs so that no reading of the ADC is lost.
However, a hard fault occurs when the first for loop is executed.
Where am I wrong?
Sorry for the banality of the question but, as mentioned, it is the first time that I work on microcontrollers
- Labels:
-
ADC
-
STM32L4 series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-07-16 6:52 AM
> uint16_t TxBuffer[ADC_buffer_Size/2];
>
> ...
>
> for(int indx=0; indx<sizeof(TxBuffer); indx++)
> {
> sprintf(adc_value, "%hu\r\n", TxBuffer[indx]);
sizeof(TxBuffer) = ADC_buffer_Size, not ADC_buffer_Size/2.
Consider adding another variable which gives the length of the array so you don't confuse yourself.
const uint32_t TxBuffer_length = ADC_buffer_Size/2;
uint16_t TxBuffer[TxBuffer_length];
...
for(int indx=0; indx<TxBuffer_length; indx++)
There may be other errors.
You should be able to launch a debug session and figure out exactly where the code crashes.
> strcat(data_SD+strlen(data_SD),adc_value);
If you're going to use strlen to figure out how much data is stored already, you need to initialize the array with zero: data_SD[0] = 0. You should also be checking to make sure you're not writing past the end of the array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-07-16 7:56 AM
@TDK Thank you for your quick answer.
I tried to apply your suggestion using these lines of code
- const uint32_t TxBuffer_length = ADC_buffer_Size/2;
- uint16_t TxBuffer[TxBuffer_length];
but i had this error: variably modified 'TxBuffer' at file scope
I solved it like this:
- #define TxBuffer_length ADC_buffer_Size/2
- ...
- uint16_t TxBuffer[TxBuffer_length];
Is it correct?
Now the for loop inside the "DMATransferComplete" interrupt is completed correctly (data_sd buffer is filled for just over half) and the code hangs in corrispondence of instruction "Mount_SD (" / ");" inside the interrupt.
I don't understand why.
Thanks again for the help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-02-15 6:28 PM
@GChir.2 Hi!
I am trying to access SD card using SPI and i think i am using the same FATFS&SPI code that you are using.
but i cant manage to get it work.
have you get your project work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-02-16 2:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-02-16 4:25 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-02-16 4:39 PM
@GChir.2
and this is the module that i am using
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-02-16 5:22 PM
That's a 5V adapter with a level shifter. At the 3.3V of the STM32 you should perhaps consider a more direct connection.
https://www.waveshare.com/micro-sd-storage-board.htm
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-02-16 5:30 PM
ok, ordered one just now. I will try again.
thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-02-16 6:27 PM
Hi @XZhen.2 .
Tomorrow night I'll try to send you a working example with your settings so that you can test if your module works.
I have a module identical to yours and in my case it works without problems
