Go Down

Topic: NewSoftWareSerial causes restart (Read 830 times) previous topic - next topic

sy kristina

Hi all,

I have been programming and soldering for a while on a digital compass for my boat. When I added a serial chip and an instance called NMEA to the program, it crashes every time I write a sentence to the NMEA port. I have been using hardware serial upto now, and it writes my nmea sentences beautifully, but the same sentence causes a crash in NMEA. Any idea what might cause this?

Code: [Select]

#include <Wire.h>            //For the compass
#include <NewSoftSerial.h>
#include <SparkFun_SerLCD.h> //for the display
#include <EEPROM.h>          //for writing brightness value to EEPROM
#include <string.h>          //These two are for Checksum calculatino for the NMEA output
#include <ctype.h>


sf_LCD lcd = sf_LCD(7);       // desired LCD pin
NewSoftSerial NMEA(0,9);     //rx,tx

void setup()
{
value = EEPROM.read(addr);
bright = value;  

NMEA.begin(4800); //Opens NewSoftSerial port to send NMEA data through pin 9
}

void loop()
{
Serial.print('$');
Serial.print(CSSentence);
Serial.print('*');
Serial.println(CS, HEX);

NMEA.print('$');
NMEA.print(CSSentence);
NMEA.print('*');
NMEA.println(CS, HEX);
}


Now the Serial.print works well, but once I expose NMEA.print, it crashes and restarts void setup().
The rest of the code is not really that important. It's a 2009 with 168 chip, and the code is abt 13K. I don't think RAM is the issue. Any suggestions?

Joachim

sy kristina

..of course it is called NewSoftSerial.

I have discovered that when I try to print a string to NMEA, the 2009 restarts. As print is inherited and not an integral part of NewSoftSerial, I'm puzzled. And on top of all that, I can write the string to lcd, which is also a NewSoftSerial object...

Joachim

mikalhart

Joachim,

It is slightly unusual for a NewSoftSerial object to use pin 0 -- the HW Serial RX pin -- for its RX.  It would appear that you are not using the NewSoftSerial RX at all, right?  If so, try something like

NewSoftSerial NMEA(255, 9); // no RX pin

Does that help your situation?

Mikal

sy kristina

Mikal,

I know. However I have tried (9,9) and other combinations before, but not 255... Anyhow, that did not solve the problem. It doesn't seem logical to me. the string is printed well to the LCD, which is called as such:
Code: [Select]

sf_LCD::sf_LCD ( int pin )

     : NewSoftSerial(pin,pin) {                                
     _w=2; _p=pin;                                              
}


I assume that is the same as writing (9,9) in my case.

the nmea object can write a bracketed text string, but fails to write a predefined string. This string can however be printed to serial and lcd...

I'm lost!

sy kristina

Here is the relevant code. If you try it, you will (probably) see that once nmea is called to print the string, the board resets.

I've said it before, but I'm a big fan of your work, Mikal!

Code: [Select]

#include <NewSoftSerial.h>

NewSoftSerial NMEA(255,9);     //rx,tx

void setup()
{

NMEA.begin(4800); //Opens NewSoftSerial port to send NMEA data through pin 9
Serial.begin(4800);

Serial.println("setup");
}

void loop()
{
 char CSSentence[] = "123";
 int CS = 79;
Serial.print('$');
NMEA.print('$');
Serial.print(CSSentence);
NMEA.print(CSSentence);
Serial.print('*');
NMEA.print('*');
Serial.println(CS, HEX);
NMEA.println(CS, HEX);


}

mikalhart

Joachim,

Thanks for your kind words.

I'm quite sure that you should not use the same pin for both TX and RX in the NewSoftSerial constructor, because code in NewSoftSerial sets the pinMode for the TX pin to "OUTPUT and for RX to "INPUT".  If these are the same pin then, well, you are asking for trouble.

That said, I can't understand why

NewSoftSerial nss(255, 9);

would cause any trouble.

Does it work if you only comment out the line "NMEA.print(CSSentence);"?  Can you try deleting the NewSoftSerial.o to force it to recompile?

Mikal

sy kristina

Thanks again Mikal,

Deleting the o file did the trick. Why didn't I think of that?

Anyway, enjoy the summer!

Joachim

Go Up