2020-07-16 05: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
2020-07-16 06: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.
2020-07-16 07:56 AM
@TDK Thank you for your quick answer.
I tried to apply your suggestion using these lines of code
but i had this error: variably modified 'TxBuffer' at file scope
I solved it like this:
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
2021-02-15 06: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?
2021-02-16 02:43 AM
2021-02-16 04:25 PM
2021-02-16 04:39 PM
@GChir.2
and this is the module that i am using
2021-02-16 05: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
2021-02-16 05:30 PM
ok, ordered one just now. I will try again.
thanks!
2021-02-16 06: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