SerialCommands issue : not receiving the whole packet over UART

Hi,

I'm trying to develop a simple ASCII API over UART using the nanoatmega328. So far, i'm able to send ascii commands from a terminal and receive it on arduino. I'm using serialCommands like this :

    
#define HOST_PROTOCOL_BUFFER_SIZE               100
#define HOST_PROTOCOL_TRAILER                   "\r"
#define HOST_PROTOCOL_DELIMITER                 " "

    cmdParser = new SerialCommands(stream, cmdBuffer, HOST_PROTOCOL_BUFFER_SIZE, (char *) HOST_PROTOCOL_TRAILER, (char *) HOST_PROTOCOL_DELIMITER);
    cmdParser->SetDefaultHandler(cmd_unknown);
    cmdParser->AddCommand(&cmd_menuconfig);
    cmdParser->AddCommand(&cmd_menucalibration);
	cmdParser->AddCommand(&cmd_hib_1);
    cmdParser->AddCommand(&cmd_hib_2);
    cmdParser->AddCommand(&cmd_prf);

Then when I send a command matching cmd_prf the right function is called. I can access params through

void cmd_profile_handler(SerialCommands* sender)
{
    Stream *stream = sender->GetSerial();
    char *param;
    char *valueStr;

    param = sender->Next();

}

But when i'm sending a command with around 80 characters only the 66 first are received. When i'm typing it by hand there is no problem. I've set the SERIAL_COMMANDS_DEBUG in order to see char by char and the ouput is this :

//What i am sending :
//P W N DE Azerty (fast) AD 0 TR 180000 PO 30 AN 15 PS -130 PT 130 PE -10 SC 10000

//Output :
Read: bufLen=99 bufPos=0 termPos=0 ch=[P]
Read: bufLen=99 bufPos=1 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=2 termPos=0 ch=[W]
Read: bufLen=99 bufPos=3 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=4 termPos=0 ch=[N]
Read: bufLen=99 bufPos=5 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=6 termPos=0 ch=[D]
Read: bufLen=99 bufPos=7 termPos=0 ch=[E]
Read: bufLen=99 bufPos=8 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=9 termPos=0 ch=[A]
Read: bufLen=99 bufPos=10 termPos=0 ch=[z]
Read: bufLen=99 bufPos=11 termPos=0 ch=[e]
Read: bufLen=99 bufPos=12 termPos=0 ch=[r]
Read: bufLen=99 bufPos=13 termPos=0 ch=[t]
Read: bufLen=99 bufPos=14 termPos=0 ch=[y]
Read: bufLen=99 bufPos=15 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=16 termPos=0 ch=[(]
Read: bufLen=99 bufPos=17 termPos=0 ch=[f]
Read: bufLen=99 bufPos=18 termPos=0 ch=[a]
Read: bufLen=99 bufPos=19 termPos=0 ch=[s]
Read: bufLen=99 bufPos=20 termPos=0 ch=[t]
Read: bufLen=99 bufPos=21 termPos=0 ch=[)]
Read: bufLen=99 bufPos=22 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=23 termPos=0 ch=[A]
Read: bufLen=99 bufPos=24 termPos=0 ch=[D]
Read: bufLen=99 bufPos=25 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=26 termPos=0 ch=[0]
Read: bufLen=99 bufPos=27 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=28 termPos=0 ch=[T]
Read: bufLen=99 bufPos=29 termPos=0 ch=[R]
Read: bufLen=99 bufPos=30 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=31 termPos=0 ch=[1]
Read: bufLen=99 bufPos=32 termPos=0 ch=[8]
Read: bufLen=99 bufPos=33 termPos=0 ch=[0]
Read: bufLen=99 bufPos=34 termPos=0 ch=[0]
Read: bufLen=99 bufPos=35 termPos=0 ch=[0]
Read: bufLen=99 bufPos=36 termPos=0 ch=[0]
Read: bufLen=99 bufPos=37 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=38 termPos=0 ch=[P]
Read: bufLen=99 bufPos=39 termPos=0 ch=[O]
Read: bufLen=99 bufPos=40 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=41 termPos=0 ch=[3]
Read: bufLen=99 bufPos=42 termPos=0 ch=[0]
Read: bufLen=99 bufPos=43 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=44 termPos=0 ch=[A]
Read: bufLen=99 bufPos=45 termPos=0 ch=[N]
Read: bufLen=99 bufPos=46 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=47 termPos=0 ch=[1]
Read: bufLen=99 bufPos=48 termPos=0 ch=[5]
Read: bufLen=99 bufPos=49 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=50 termPos=0 ch=[P]
Read: bufLen=99 bufPos=51 termPos=0 ch=[S]
Read: bufLen=99 bufPos=52 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=53 termPos=0 ch=[-]
Read: bufLen=99 bufPos=54 termPos=0 ch=[1]
Read: bufLen=99 bufPos=55 termPos=0 ch=[3]
Read: bufLen=99 bufPos=56 termPos=0 ch=[0]
Read: bufLen=99 bufPos=57 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=58 termPos=0 ch=[P]
Read: bufLen=99 bufPos=59 termPos=0 ch=[T]
Read: bufLen=99 bufPos=60 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=61 termPos=0 ch=[1]
Read: bufLen=99 bufPos=62 termPos=0 ch=[3]
Read: bufLen=99 bufPos=63 termPos=0 ch=[0]
Read: bufLen=99 bufPos=64 termPos=0 ch=[ ]
Read: bufLen=99 bufPos=65 termPos=0 ch=[P]
Read: bufLen=99 bufPos=66 termPos=0 ch=[S]

If anyone has any clue where the problem is ?
Thanks !

I've moved your post to a better location (it's not a library)
In the future please pay attention to the category in which you are posting (and you'll be more likely to get an answer)


we need more info like the full code (or a minimal example demonstrating the issue) and also information about your arduino's type and connections

1 Like

Sounds like your code is too slow, and can't keep up with the speed the terminal sends at.

Many (most?) terminals can be configured to put a delay between each character - have you tried that?

You can increase the serial RX-buffersize
open the file HardwareSerial.h

and change the value
#define SERIAL_RX_BUFFER_SIZE 64
to a bigger value like
#define SERIAL_RX_BUFFER_SIZE 256

best regards Stefan

3 Likes

It's hardly ever needed to extend that buffer. It's only needed if the other code is blocking.

Be aware that with the usual IDE installation the change will affect every sketch. So you run the risk that old perfectly working code now results in either low "memory warnings" when compiling or no longer works (e.g. when using AdaFruit's NeoPixel library where memory allocated for the pixels can be counted by the IDE).

Far better to just read the data from that buffer as it arrives.

This solved my problem thanks !

In my case the serial com can't be a priority so I can't read it instantly as it arrives

I've tried slowing it down but the problem still persist, the problem came from the SERIAL_RX_BUFFER_SIZE that wasn't large enough as pointed by @StefanL38

Thanks ! Sorry for the post location, i'm new here and couldn't find the good one

My interpretation of that statement is that you have blocking code (knowingly because you use e.g. delay() or unknowingly because 'hidden' functionality blocks (e.g. analogRead()).

You have your solution so you're OK.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.