Loading...
Pages: [1]   Go Down
Author Topic: SoftwareSerial - Bug  (Read 1672 times)
0 Members and 1 Guest are viewing this topic.
NSW, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

We are having problems with the SoftwareSerial library found in the Arduino 1.02 Release.

When the SoftwareSerial is initialised, it sets the tx port to output and then sets it to HIGH. This causes a momentary low spike that is being interpreted as a start bit on some controllers.

The code currently is:-
Code:
void SoftwareSerial::setTX(uint8_t tx)
{
  pinMode(tx, OUTPUT);
  digitalWrite(tx, HIGH);
  _transmitBitMask = digitalPinToBitMask(tx);
  uint8_t port = digitalPinToPort(tx);
  _transmitPortRegister = portOutputRegister(port);
}

The 'fixed' code is:-
Code:
void SoftwareSerial::setTX(uint8_t tx)
{
  digitalWrite(tx, HIGH);
  pinMode(tx, OUTPUT);
  _transmitBitMask = digitalPinToBitMask(tx);
  uint8_t port = digitalPinToPort(tx);
  _transmitPortRegister = portOutputRegister(port);
}

This solves the issue.

Please advise

Regards
4D Systems
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 279
Posts: 15314
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Interesting. What the fix is doing is enabling the internal pull-up resistor on the pin number in question while it's still an input pin so that when the pin mode is changed to output mode it's already at a high state, otherwise without out that, when the pin mode is first changed to output mode it's default state is low until the very next digitalWrite (tx,HIGH) is executed, causing the downstream circuit to see a very brief low 'spike' before the high takes place.

Lefty

Another maybe ( or maybe not) clearer 'fix' that does the same thing might be to use:

Code:
void SoftwareSerial::setTX(uint8_t tx)
{
  pinMode(tx, INPUT_PULLUP);
  pinMode(tx, OUTPUT);
  _transmitBitMask = digitalPinToBitMask(tx);
  uint8_t port = digitalPinToPort(tx);
  _transmitPortRegister = portOutputRegister(port);
}
« Last Edit: January 01, 2013, 11:51:46 pm by retrolefty » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 119
Posts: 10172
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


@4D_Systems, please create an issue here...
https://github.com/arduino/Arduino/issues
https://github.com/arduino/Arduino/issues/new
Logged

NSW, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Done

https://github.com/arduino/Arduino/issues/1195

Thank you
Logged

NSW, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello again

After posting the bug report 8 days ago, still no one seems to be assigned to the bug...

Is there anything further we can do to get this seen to?

Looking at other bug reports, there seem to be numerous without someone being assigned to them either...

Can probably put a lot of it down to the holiday season.

Please advise

Regards
4D Systems
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 316
Posts: 35532
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can probably put a lot of it down to the holiday season.
And other priorities, and a small staff. Patience, grasshopper.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 119
Posts: 10172
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

After posting the bug report 8 days ago, still no one seems to be assigned to the bug...

Is there anything further we can do to get this seen to?

Absolutely!  Fork.  Fix.  Submit a pull request.

This dramatically increases the chances of the change being included much sooner than if you rely on someone else.

As an added bonus, until the fix has been applied, you can maintain your own up-to-date version by re-merging and using your fork.
Logged

Pages: [1]   Go Up
Print
 
Jump to: