SOLVED - Disabling NSS Reset

Hi All!

Hope you can help with this one!

I’ve read up on how to disable the serial Auto-reset using a resistor between 5v and GND,

I am attempting to use an XBEE on pins 11 and 12 using NewSoftSerial I can’t use 0 & 1 as these are used by my GSM Shield,

The issue I am having is that when I send a message from the XBee it resets the Arduino code - so all I ever get is “Setup Done”

Here is my code:

// Main Code for BaseStation Node
// And component Libraries
// Include required libraries for power saving
#include <avr/power.h>
#include <avr/sleep.h>
// New Soft Serial for XBee
#include <NewSoftSerial.h>
// Define the pins
const int RX = 11;
const int TX = 12;
// Instantiate the serial port
NewSoftSerial xbee = NewSoftSerial(RX, TX);

// Constants
const int wakeUpPin = 2;
// 30 Sec Delay time
const int SLEEP_TIMEOUT = 30;

// Counter
int count = 0;
// 0 - Off / 1 - ON
int externalClock = 0;

// This method is the first thing that is called when the node is woken up via the switch interrupt
// Note: Serial outputs do not work at this stage, nor does ADC conversions

void wakeUp()
{
  externalClock = 1;
}
  
void setup()
{
   // XBee Serial
  xbee.begin(9600);
  Serial.begin(9600);
  // Set-up interrupt pin
  //pinMode(wakeUpPin, INPUT);
  //digitalWrite(wakeUpPin, HIGH);
  Serial.println("Setup Done");
  // Attach the interrupt
  //attachInterrupt(0, wakeUp, LOW);
  delay(100);
}

void loop()
{
  // Increment counter
  count++;
  // Check if it was a serial interrupt i.e. a network broadcast
  // First wait for 1 second to allow serial to initialise after sleep
  // An error will occur if this delay is not implemented
  delay(100);
  
  // Check Serial Lines
  if (xbee.available() >= 0)
  {
    // Read the serial port value (byte)
    int val = xbee.read();
    Serial.println(val);
    
    if (val == 'A')
    {
      Serial.println("true");
      const int LENGTH = 30;
      const char TERMINATOR = 'Z';
      char inString[LENGTH + 1] = "";
      int inCount = 0;
      // Send Response to call
      xbee.print(TERMINATOR);
      // Recieve Message
      do
      {
        while (!xbee.available()); // Wait here 
        inString[inCount] = xbee.read();
        // Check if a terminating character has been recieved
        if (inString[inCount] == TERMINATOR)
        {
          Serial.print("Terminator");
          xbee.print(TERMINATOR);
          xbee.flush();
          Serial.println("Starting GSM");
          gsmStart();
          while(!isConnected()); // Wait here
          sendAlert(inString);
          break;
        }
      } while (++inCount < LENGTH);
      
      Serial.println("Outside Do");
      xbee.print(TERMINATOR);
      xbee.flush();
      gsmStart();
      while(!isConnected()); // Wait here
      sendAlert(inString);
    }
    Serial.println("Outside IF A"); 
  }
}

Is there a way to stop this from happening?

Thanks,

Dave.

The XBee can not reset the Arduino, so there is no need to stop it from happening.

        while (!xbee.available()); // Wait here

You really should look at the documentation for the available() method. It does not return a boolean (yes, there is data; no, there is not). It returns the number of bytes available.

        while (xbee.available() == 0); // Wait here

Which XBees do you have? How have you configured them? Do you KNOW that they communicate with each other? Why do you think that sending data via the XBee is causing a reset?

PaulS: The XBee can not reset the Arduino, so there is no need to stop it from happening.

        while (!xbee.available()); // Wait here

You really should look at the documentation for the available() method. It does not return a boolean (yes, there is data; no, there is not). It returns the number of bytes available.

        while (xbee.available() == 0); // Wait here

Which XBees do you have? How have you configured them? Do you KNOW that they communicate with each other? Why do you think that sending data via the XBee is causing a reset?

If a ! function returns 0 then it is false else it is true - this would work even if I was returning an integer value it doesn't have to return a boolean.

I have the Series 2 XBee - And they are configured in Transparent (AT) mode,

I am trying to use a Call and response method i.e. I send out a burst of data say 'A' and then my Base station sends back a terminating character in this case 'Z' once that is received the Node sends the complete message and the BS again responds with the terminator.

I know that a reset is happening because when I connect the serial monitor to the base station and then send out the broadcast from the node the string "Setup Done" is written to the console - The only place this line of code exists is in the setup() method.

I know that a reset is happening because when I connect the serial monitor to the base station and then send out the broadcast from the node the string "Setup Done" is written to the console - The only place this line of code exists is in the setup() method.

If you send two broadcasts, do you see two "Setup Done" messages? If you send 3 broadcasts, do you see 3 "Setup Done" messages?

PaulS:

I know that a reset is happening because when I connect the serial monitor to the base station and then send out the broadcast from the node the string "Setup Done" is written to the console - The only place this line of code exists is in the setup() method.

If you send two broadcasts, do you see two "Setup Done" messages? If you send 3 broadcasts, do you see 3 "Setup Done" messages?

Yes - I see 10 in total as this is the amount of retries I perform before putting the sending node to sleep

Anyone have any ideas? bump

The issue I was having was caused by an SD card library I was using that was in another code file

All sorted now :smiley: