cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-L476RG: Write ADC values into SD_CARD using SPI

GChir.2
Associate II

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

16 REPLIES 16

Hi @XZhen.2 (Community Member)​ .

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

@Community member​ 

Hi�?I tried another sd card module with the same code, still failed to work.

0693W000008GPibQAG.jpg

@GChir.2​ 

I am looking forward to that because I tried another module, still failed.

GChir.2
Associate II

@XZhen.2​ Try this simple code (PB6 as cs pin and SP1 enabled).

Make a backup of your sd because, in the code, I inserted the command for formatting the sd card. On my board, with an sd module similar to your, the code works without problems (connect the vcc pin of the sd module to 5V on the board).

Let me know if this solves your problems 😉

@GChir.2​ 

Hi. thanks for the code.

still failed.

this is the info I got from serial comm.

ERROR in mounting SD CARD...

Total Drive Space: 2147481600 KiB (2047.997 GiB)

Space Available:      0 KiB (0.000 GiB)

ERROR!!! No. 1 in creating file *Test.txt*

ERROR!!! Test.txt does not exists

there might be something wrong with my Nucleo-L476RG board

Could you share a photo with module's connection to the board?

Have you used my code?

There's perhaps something more fundamentally wrong with your implementation or wiring.

The level translators on the prior board will likely become an issue as the bandwidth increases.

With the SDIO/SDMMC implementation I was using uniform wires of around 3"(8 cm), and those were capable of getting me to 25 MHz.

I wouldn't recommend DuPont wires which people seem to use prolifically, but rather something that really bites into the corners of the headers, like Schmartboard jumper wires, or wire-wrap.

https://schmartboard.com/jumper-wires/

Watch the CS to CLK edges, and perhaps back-off on the slew-rates.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..