Other Parts Discussed in Thread: LAUNCHXL-F28379D, , C2000WARE
Tool/software:
Hello,
I am currently working with the LAUNCHXL-F28379D, specifically on reading numerical data from an SD card. I am encountering an issue with the use of the strtod function.
Below, I have included the code being used and the content of the text file in the SD card.
During debugging, I have observed that the data in string form is read correctly and stored in the variable 'tok'. However, after using the strtod function, the numerical values stored in Array are always 10, regardless of the input string.
What could be the problem?
Thank you.
Code:
/*
* SD_Card.c
*/
#include "driverlib.h"
#include "device.h"
#include "board.h"
#include <string.h>
#include <stdlib.h>
#include <sdspi/sdspi.h>
#include <sdspi/SDFatFS.h>
double var1;
double var2;
double var3;
double var4;
double var5;
uint16_t SDFatFS_config_count = 1;
SDFatFS_Object sdfatfsObject;
SDSPI_Object sdspiObject = {
.spiHandle = mySDCardSPI_BASE,
.spiCsGpioIndex = mySDCardCS
};
SDFatFS_Object* SDFatFS_config [] = {&sdfatfsObject};
SDSPI_Handle sdspiHandle = &sdspiObject;
/* String conversion macro */
#define STR_(n) #n
#define STR(n) STR_(n)
/* Drive number used for FatFs */
#define DRIVE_NUM 0
FRESULT fresult;
FIL src;
#define ARRAY_SIZE 400
char lettura [ARRAY_SIZE];
double Array [20];
void Lettura_SD (void)
{
Board_init();
SDFatFS_init();
SDFatFS_Handle sdFatFs_handle = SDFatFS_open(sdspiHandle, DRIVE_NUM);
if (sdFatFs_handle == NULL)
{
while(1);
}
// Lettura file con parametri
char inputfile[] = STR(DRIVE_NUM)":input.txt";
fresult = f_open(&src, inputfile, FA_READ);
if (fresult != FR_OK) {
while(1);
}
uint16_t bw;
f_read(&src, lettura, 40, &bw);
char* tok;
char* stopstring;
tok = strtok(lettura, ":");
tok = strtok(NULL, ":");
int N_variables = atoi(tok);
int i;
for (i = 0; i<N_variables; i++)
{
tok = strtok(NULL, ":");
Array[i] = strtod(tok, &stopstring);
}
fresult = f_close(&src);
if (fresult != FR_OK)
{
while(1);
}
var1 = Array[0];
var2 = Array[1];
var3 = Array[2];
var4 = Array[3];
var5 = Array[4];
}
int32_t fatfs_getFatTime(void)
{
return 0;
}
Text file:
N.variables:5
var1:17
var2:53.4
var3:0.003
var4:101232
var5:1.30467

