How to store values in memory card from array
I am using an ADC input pin and trying to store values in memory card. Before storing in memory card i have stored in an array thinking that after some 2000 values i can store in memory card. Before storing 2000 values i tried to store 5 values but i couldnt able to store in memory for some reason.
I have configured adc with timer for a flexible sampling rate. I tried multiple ways to store the values from array to sdcard but to no avail. Below is the code.
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hadc);
adc_val= HAL_ADC_GetValue(&hadc1);
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(htim);
temp_value[i] =adc_val;
i++;
}
In the main, code is as follows:
HAL_ADC_Start_IT(&hadc1);
HAL_TIM_Base_Start(&htim2);
char myPath [] = "WRITE1.TXT\0";
char myData [] = " hello ashok\0";
f_mount(&myFATFS,SDPath,1);
f_open(&myFILE, myPath, FA_WRITE | FA_CREATE_ALWAYS);
f_write(&myFILE, myData, sizeof(myData), &testByte);
f_printf(&myFILE, "Hello world \0");
/* USER CODE END 2 */
//// the above said i.e., hello ashok gets written to sd card
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
if(i==5)
{
sd_card();
}
}
}
void sd_card(void)
{
for(j=5; j<=0; j--)
{
temp = temp_value[j];
f_printf(&myFILE, "\r\n %d", temp);
f_printf(&myFILE, "\r\n %d Hello\0", j);
}
f_close(&myFILE);
}
i can able to write values to sd card if i am not using the variable i,( the global values which is in timer function). when ever i am keeping the condition that if i == some value and trying to write values to sd card it is not happening. any inputs please ? Here I is in short seconds. as i have kept the timer to trigger every 1 second.
