AK-SDFS-UART Change baudrate


#1

Hello, I’m trying to change the baudrate of the SD logger, but without success.
I’m using an Arduino Uno board for the communication with the SD logger.

I’ve tried to use the functions fprot_set_baudrate(115200); and then fprot_save_parameters(); in order to save the new baudrate to the internal memory, but when I replug the board, the baudrate seems to be still 9600.

I’ve also tried to change the baudrate and then close and reopen the serial port with the new baudrate but it didn’t work.

What would be the correct sequence of the operations?

Furthermore, according to the comments on the product page, it seems that values higher than 115200 are supported but the datasheet says the maximum value is 115200. What is the actual max value for the baudrate?

Thank you.


#2

Hi @alessandro.b,

The sequence is correct. The tests we do on a PC + AK-SDFS-UART work fine.

  • Are other commands working ok?
  • Can you check the return code for the fprot_save_parameters() function.
  • Can you uncomment the #define FPROT_BIG_ENDIAN line of the fprot.h file and see if it does any difference? (swaps words before sending them to the board).

The maximum baudrate is 460800bps. I’ll verify if the documentation is up to date.


#3

Sorry for the very late replay, but I haven’t been working on this project for a while. I still have the problem. Uncommenting FPROT_BIG_ENDIAN didn’t solve the problem.

The following code works, but the serial port is set to 9600 baud

LogSerial.begin(9600);

if (fprot_init(send_data, recv_data, delay))
{
    // AK-SDFS-UART library initialized
    DebugSerial.printf("fprot_init initialized\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("\\log4.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("Opened new file log.txt\n");
        // Indicate failure keeping the LED ON
        // LED_ON();
        my_file = 0;
    }
}

The following tries to set the baudrate to 115200 but it doesn’t work:

LogSerial.begin(9600);

DebugSerial.printf("Set baudrate to 115200\n");
fprot_set_baudrate(115200);

LogSerial.begin(115200);    

DebugSerial.printf("Calling constructor\n");

if (fprot_init(send_data, recv_data, delay))
{
    // AK-SDFS-UART library initialized
    DebugSerial.printf("fprot_init initialized\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("\\log4.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("Opened new file log.txt\n");
        // Indicate failure keeping the LED ON
        // LED_ON();
        my_file = 0;
    }
}

Thanks.


#4

The fprot_set_baudrate(115200) function has to be called after fprot_init(send_data, recv_data, delay).

That is because fprot_set_baudrate(115200) sends a command to the board indicating that the baudrate should change. This command is sent through the functions you pass to the fprot_init function.

Try with something similar to:

LogSerial.begin(9600);

if (fprot_init(send_data, recv_data, delay))
{
    fprot_set_baudrate(115200);
    // maybe a delay here
    LogSerial.begin(115200); 
    // etc.

#5

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;
    }
}

#6

Could you please post the complete code, including tx and rx functions so I can test it over here?

Thank you.


#7

Please find the below the link for downloading the code:

Notes:

  • The board is based on arduino mega

  • The code is organized as a class. I’ve create an object with the following code:

    ArtekitLogManager artekitManager;
    artekitManager.init();

  • LogSerial is the alias for Serial2

  • DebugSerial is the alias for Serial

  • Both serial port are initialized using the FastSerial library. You would need to rename #include “FastSerialDep.h” with #include “FastSerial.h” in ArtekitLogmanager.h.

Thank you for your support.


#8

I’m trying to debug the issue with the scope and I’d like to share with you what I’ve found so far. The image below shows the tx pin of the sd logger (going to the board).
The ouptut in the image is just the call of the following two functions:

  • fprot_close_all()
  • fprot_set_baudrate(115200);

The function fprot_close_all() responds correctly (0x90), while the answer of the function fprot_set_baudrate(115200); is 0xB8 0x14 and I don’t see the header (0x41 0x4B).


#9

Thank you for the capture. 0x41 and 0x4B would be the CRC16 of the response for fprot_close_all. Check if you can see if there is any data after that packet in search for the response of the baudrate command. The baudrate command will send back either an ‘invalid parameter’ response (if the baudrate value is invalid) or an ACK response before changing the baudrate. Let’s try to catch this answer before going further.

You also say:

Can you log with DebugSerial what’s being read into the data array, in the ArtekitLogManager::recv_data function? I’am afraid that may be part of the answer is being missed, and then it blocks on the reading function waiting for data.

As I prepare a rig for testing this tomorrow with an Arduino UNO and a Cortex-M3 (we don’t have a MEGA at the moment, and the production tests are done in batches with a program for Windows), I ask you also if you have tried with the standard Arduino Serial library.

Thank you.


#10

I will try to see what’s read in the data array and I will also try with the standard library.

Thank you.


#11

Good morning,
I’ve tried with the standard arduino serial library using and Arduino UNO board. Everything works fine, but on my board still doesn’t work. I’m thinking that it could be an issue with the FastSerial library.

Anyway, for the moment I’ve fixed the problem using Arduino UNO for changing the baudrate and saving the new parameter. In this way my board will start the communication directly at 115200.

I will try to dig into this more, but for the moment it’s ok.

Thank you anyway for your support.


#12

Thank you @alessandro.b for the update.


#13

Hi…i am a new user here. I am also facing the same issue. In my case 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.

smt prototype assembly


#14

Hi @NoellEagan,

Please tell us what platform are you using, libraries, etc. and please also post a little sketch that reproduces the problem for you.

Thanks.