I am currently attempting to get the micro-controller to write and read from a text file, so that I can ensure that the board will be capable of what I need it to do. Unfortunately, I'm having strange run-time hang-ups with this, and I don't know if this is something that that I'm doing wrong, or if the board simply isn't designed to do so.
I'm attempting to use fprintf and fscanf. Sample below (I don't see a code block in the forum settings.)
#include <stdio.h>
//Global Variables for Easy Debug Access
float out[10];
float input[10]={1,2,3,4,5,6,7,8,9,10};
int test;
int test2;
int i;
void WritetoFile(void)
{
FILE *fp;
fp = fopen("C:\\Users\\DaJJBomb\\workspace_v5_3\\senior_design_project_code\\hello.txt", "w");
//test=fwrite(input,sizeof(float),sizeof(input)/sizeof(float),fp);
for(i=0;i<10;i++)
{test=fprintf(fp,"%f\n",input);}
fclose(fp);
}
void ReadfromFile(void)
{
FILE *fp;
fp = fopen("C:\\Users\\DaJJBomb\\workspace_v5_3\\senior_design_project_code\\hello.txt", "r");
for(i=0;i<10;i++)
{ test2=fscanf(fp,"%f\n",out[i]);}
//test2=fread(out,sizeof(float),sizeof(input)/sizeof(float),fp);
fclose(fp);
}
void main()
{
WritetoFile();
ReadfromFile();
}
When I attempted to build this for the first time, I get a compiler error stating that there's not enough memory in .text to fit the library, so I expanded that section in the linker file:
.text : >> RAML0|RAML1|RAML2, PAGE = 0
Everything else is default. With this line, the code compiles, but when it gets to the first fprintf, it hangs forever.
In order to test it, I used fwrite and fread. It worked for reading and writing strings and integers perfectly, but when I tried to use floats it gave me erroneous results.
I haven't dug deep enough to see whether or not using RAML1 and RAML2 is the reason why this is acting so strangely. I couldn't see them being referenced in the linker file, so they shouldn't be causing any issues, but I'm not 100% sure.
Is there some important element I'm missing, or is this more of a matter of "this board isn't supposed to be performing file I/O operations?" Any help would be greatly appreciated
Thanks for your time,
JJ