SoftwareSerial changing speed unexpectedly

Hello,

My environment is the following:

  • Working on an Arduino Leonardo
  • Compiling/Loading with Atmel Studio and an Atmel ICE JTag

I’m using the SoftwareSerial to add an UART to the board. I need it, hardware serial already used.

The communication using the Soft Serial is ok, until it unexpectedly change speed, I do not know why…

The communication is supposed to be at 38400, about 26µs for a bit. I check it by changing a GPIO when the driver is sampling data. The GPIO change state every 26µs.

But suddenly, the sampling change to a new fixed value of 4.3ms!

First I thought it was because of overload of the µC. But I made a check:

  • SoftwareSerial defined a timing inter bit _rx_delay_intrabit that is set to 99 when working at 38400Bds
  • When the Serial change it own speed, this value change (I made a GPIO changing its state if value is different from 99)

So it is like there was a new call to Serial.begin (only methode to change _rx_delay_intrabit value). But there is no call of this methode (add a break point in it)

Any ideas what could cause this problem? Or anything other to check?
Thank you

Or anything other to check?

Seeing your code might help ...

By using SoftwareSerial on a Leonardo you are creating a third serial interface. What are the other two being used for ?

hardware serial already used.

Both of them?

Any ideas what could cause this problem?

You've probably stomped on memory you don't own, writing past the end of an array or writing to an uninitialized pointer.

But, of course, that's just a guess because, despite posting code being a requirement for posting in the Programming section, you failed to post any code.

Hello,

One interface connected to the USB is used to display some trace on my terminal.
The other Hardware Uart is used to communicate with another device.

And sorry for not showing my code, but unfortunately I am not allowed to show it... but anyway it is quiet large so I do not think it could help... Maybe I post to the wrong section of the forum! :wink:

I will have a look to check all the array writing to avoid memory corruption!
Thank you

You can write a simple sketch that exhibits the behaviour.

Further the sentiment is that if your business makes money from the product, you will not get free help if you do not share your code.

Are you setting up or using any interrupts in your (invisible) sketch?

Since we can't read your program, it will be up to you to read the SoftwareSerial Code and see how it works and interacts with your program.

AntoineCa:
And sorry for not showing my code, but unfortunately I am not allowed to show it...

If that means it is a commercial project it is not fair to be expecting free advice from people here. Pay a professional for advice.

...R

No it is not a commercial project. Theres is two network here, one for work, one for internet. And I am not allowed to transfert anything from one to the other...

I have a function call that will send a command to an Arduino GSM shield via the SoftwareSerial.

gsm_send( bufferCommand, answer, index)

The call of the function is made like that (index is a param, value is 1, answer is a tab defined and initialized):

#define READ_SMS "AT+CMGR="

char buffer[32];
sprintf(buffer, "%s%d", READ_SMS, index);

gsm_send( buffer, answer, index);

In this configuration, it is not working (timing are too long!)

But if I do:

#define READ_SMS "AT+CMGR=1"

//char buffer[32];
//sprintf(buffer, "%s%d", READ_SMS, index);
gsm_send( READ_SMS , answer, index);

it is working!

When working with the sprintf, the command in "buffer" is correct. buffer is large enough to perform the sprintf(buffer, "%s%d", READ_SMS, index) without overflow. So I do not understand what could be wrong...

I even do the following test:

This is working:

#define READ_SMS "AT+CMGR=1"

//char buffer[32];
//sprintf(buffer, "%s%d", READ_SMS, index);
gsm_send( READ_SMS , answer, index);

This is not working

#define READ_SMS "AT+CMGR=1"

char buffer[32];
sprintf(buffer, "%s%d", READ_SMS, index);
gsm_send( READ_SMS , answer, index);

While:

  • buffer is not used in the function call
  • buffer is large enough to perform the sprintf with no buffer overflow

AntoineCa:
No it is not a commercial project. Theres is two network here, one for work, one for internet. And I am not allowed to transfert anything from one to the other...

How about taking the code home and doing it on your own personal PC where there are no restrictions.

Expecting people to help with code we cannot see is ridiculous.

...R