[CODE] tags added by moderator.
Hello Team,
I am implementing data logging on an SD card using the SPI interface and FATFS libraries, with reference to the SD card libraries provided by Controllers Tech (https://controllerstech.com/sd-card-using-spi-in-s…). While I have achieved a logging speed of around 58 Hz, I am encountering data loss issues, particularly at higher logging speeds.
Function I used for SD card logging :
I would appreciate any suggestions or improvements to enhance the reliability of the implementation on the microcontroller.
Thanks in advance.
Hello Team,
I am implementing data logging on an SD card using the SPI interface and FATFS libraries, with reference to the SD card libraries provided by Controllers Tech (https://controllerstech.com/sd-card-using-spi-in-s…). While I have achieved a logging speed of around 58 Hz, I am encountering data loss issues, particularly at higher logging speeds.
Function I used for SD card logging :
Data Logger:
void HandleState(void) {
uint8_t path[20];
switch (currentState) {
case STATE_INIT:
if (f_mount(&fs, “0:/”, 1) == FR_OK) {
int fileNumber = 0;
do {
sprintf((char *)path, “log_%d.csv”, fileNumber++);
} while (f_stat((char *)path, NULL) == FR_OK);
if (f_open(&file, (char *)path, FA_CREATE_ALWAYS | FA_WRITE | FA_READ) == FR_OK) {
strcpy(buffer, “Log SD card\\\\n”);
f_write(&file, buffer, sizeof(buffer), NULL);
currentState = STATE_LOG_DATA;
} else {
Error_Handler();
}
} else {
Error_Handler();
}
break;
case STATE_LOG_DATA:
sprintf(buffer, “%lu, %.2f, %d\\\\n”, HAL_GetTick(), temperature, counter++); // current time in milliseconds since the start of the program
f_write(&file, buffer, sizeof(buffer), NULL);
f_sync(&file) ;
break;
default:
break;
}
}
Thanks in advance.
Last edited by a moderator:
