Good morning,
thank you for your answer.
Unfortunately the solution above is not working.
The problem is that the program stops on the fprot_set_baudrate(115200); function without retuning any value. So I’m not able to see what’s going on.
If I don’t change the baudrate, everything works fine: I’m able to open a file and write on it, without any problem.
I’ve also tried to put a delay of 2 seconds after calling the fprot_set_baudrate function but nothing.
The board I’m currently using is based on arduino mega and therefore I’ve downloaded and used the library for arduino. I’ve noticed that the arduino library doesn’t contain the FPROT_BIG_ENDIAN define. Furthermore, I’ve also tried to use the other version of the library on the product page (just renaming the lib file from fprot.c to fprot.cpp) but I get the same behaviour.
Any other suggestion?
Thank you so much.
Here is the code:
LogSerial.begin(9600);
if (fprot_init(send_data, recv_data, delay))
{
// AK-SDFS-UART library initialized
DebugSerial.printf("fprot_init initialized\n");
// ---------------------------------------------
// removing the following line, everything works
DebugSerial.printf("Set baudrate to 115200...");
unsigned char d = fprot_set_baudrate(115200);
printf("Return value: %c\n",d);
delay(2000);
LogSerial.end();
LogSerial.begin(115200);
//DebugSerial.printf("OK\n");
// ---------------------------------------------
// Close all files that may be opened before reset
fprot_close_all();
DebugSerial.printf("Closed all previous_files\n");
//DebugSerial.printf("cpu load: %2.3f free_mem (bytes): %d\n", cpu_load, freeMemory());
unsigned char c = fprot_open("\\log5.txt", FPROT_MODE_RW | FPROT_MODE_CREATE_ALWAYS, &my_file);
DebugSerial.printf("fprot_open result: %u\n",(unsigned int)c);
// The name of the file will depend on the name of the last file created, to avoid overwriting
if (c != FPROT_NO_ERROR || my_file == FPROT_INVALID_FILE)
{
DebugSerial.printf("Error opening new file log.txt\n");
// Indicate failure keeping the LED ON
// LED_ON();
my_file = 0;
}
else
{
// write some data
char str[32];
unsigned long written;
sprintf(str,"Hello world! - %d",2);
if(fprot_write(my_file, str, strlen(str), &written) == FPROT_NO_ERROR)
{
fprot_flush(my_file);
}
else
my_file = 0;
}
}