Overriding Baud Rate is not the same as specified

I have been using the Arduino Uno R3 with a receiver (coordinator) XBee. The Arduino has a program (code 1) that will supposedly read out the “Hello, world!” packet message from the router XBee, which I’ll be using with XCTU’s serial console. From there, I’ll be typing the message in the XCTU and read it out at the Arduino serial monitor. Both XBees are configured to communicate at 9600 bps using the XCTU. But the Arduino’s program was required to have a baud rate of 115200 for the serial monitor.

Code 1:
// Copyright 2015, Matthijs Kooijman matthijs@stdin.nl
//
// Permission is hereby granted, free of charge, to anyone
// obtaining a copy of this document and accompanying files, to do
// whatever they want with them without any restriction, including, but
// not limited to, copying, modification and redistribution.
//
// NO WARRANTY OF ANY KIND IS PROVIDED.
//
//
// This example reads data from an AltSoftSerial port and prints this
// (in both hexadecimal and ASCII) to the main serial port (to be read
// on a computer). Any data received from the computer is forwarded to
// the AltSoftSerial port as-is. This is intended to dump all data
// received from an XBee module and allow sending data back to it, but
// can of course be used in other situations too.
//
// Typical output looks like this:
// Starting…
// 7E 00 19 90 00 13 A2 00 ~…
// 40 D8 5F 9D 00 00 02 48 @._…H
// 65 6C 6C 6F 2C 20 57 6F ello, Wo
// 72 6C 64 21 3B rld!;

#include <AltSoftSerial.h>

// Use some macros to allow changing the serial ports to use easily
AltSoftSerial SoftSerial;
#define DebugSerial Serial
#define XBeeSerial SoftSerial

void setup() {
Serial.begin(115200);
DebugSerial.begin(115200);
XBeeSerial.begin(9600);
DebugSerial.println(F(“Starting…”));
}

void loop() {
if (XBeeSerial.available()) {
char data[8];
uint8_t column;

for (column = 0; column < sizeof(data); ++column) {
// Wait up to 1 second for more data before writing out the line
uint32_t start = millis();
while (!XBeeSerial.available() && (millis() - start) < 1000) /* nothing */;
if (!XBeeSerial.available())
break;

// Start of API packet, break to a new line
// In transparent mode, this causes every ~ to start a newline,
// but that’s ok.
if (column && XBeeSerial.peek() == 0x7E)
break;

// Read one byte and print it in hexadecimal. Store its value in
// data, or store ‘.’ is the byte is not printable. data will
// be printed later as an “ASCII” version of the data.
uint8_t b = XBeeSerial.read();
data[column] = isprint(b) ? b : ‘.’;
if (b < 0x10) DebugSerial.write(‘0’);
DebugSerial.print(b, HEX);
DebugSerial.write(’ ');
}

// Fill any missing columns with spaces to align lines
for (uint8_t i = column; i < sizeof(data); ++i)
Serial.print(F(" "));

// Finalize the line by adding the raw printable data and a newline.
DebugSerial.write(’ ');
DebugSerial.write(data, column);
DebugSerial.println();
}

// Forward any data from the computer directly to the XBee module
if (DebugSerial.available())
XBeeSerial.write(DebugSerial.read());
}

By the way, I am following the example (example code is named SerialDump.ino) from Matthijs Koojiiman’s book, Building Wireless Sensor Networks using Arduino. However, I still fail in trying to receive any message. I tried some simpler examples from the internet, and that is when my concern started to appear when I tried to upload another code (code 2) to the Arduino.

The overriding baud rate is unchangeable at 115200. I tried to change the baud rate of the ports connected to the Arduino at 9600 at the Device Manager, but whenever I try to compile and upload another code results are still the same.

Code 2:

/*****************************************************************
XBee_Serial_Passthrough.ino

Set up a software serial port to pass data between an XBee Shield
and the serial monitor.

Hardware Hookup:
The XBee Shield makes all of the connections you’ll need
between Arduino and XBee. If you have the shield make
sure the SWITCH IS IN THE “DLINE” POSITION. That will connect
the XBee’s DOUT and DIN pins to Arduino pins 2 and 3.

*****************************************************************/
// We’ll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
// XBee’s DOUT (TX) is connected to pin 2 (Arduino’s Software RX)
// XBee’s DIN (RX) is connected to pin 3 (Arduino’s Software TX)
SoftwareSerial XBee(2, 3); // RX, TX

void setup()
{
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
XBee.begin(9600);
Serial.begin(9600);
}

void loop()
{
if (Serial.available())
{ // If data comes in from serial monitor, send it out to XBee
XBee.write(Serial.read());
}
if (XBee.available())
{ // If data comes in from XBee, send it out to serial monitor
Serial.write(XBee.read());
}
}

I tried to rewrite the 115200 parameter from code 1 at the Serial.begin and DebugSerial.begin and uploaded the same code. Nothing still changed at the errors and notification console. See attached image. How do I do this?

rayrayrayyourboat:
that is when my concern started to appear when I tried to upload another code (code 2) to the Arduino.

The overriding baud rate is unchangeable at 115200. I tried to change the baud rate of the ports connected to the Arduino at 9600 at the Device Manager, but whenever I try to compile and upload another code results are still the same.

You’re chasing a red herring. The baud rate number you see in the console output during upload:
2ec6160caab91d58987cb2fc8ff6784dd5683323.png
Is completely unrelated to the baud rates your sketch uses to communicate. Forget about that. It has absolutely nothing to do with whatever problem you’re having.

rayrayrayyourboat:
I tried to change the baud rate of the ports connected to the Arduino at 9600 at the Device Manager, but whenever I try to compile and upload another code results are still the same.

Don’t mess with that. It won’t do you any good.

In this case you have two different communication lines:

  • XBee-Uno
  • Uno-Computer (Serial Monitor)

You need to make sure that both ends of each communication line are set to the same baud rate.

XBee-Uno: From the comment in the code it sounds like the XBee defaults to 9600 baud so you need to set the serial port on the Uno that is connected to the XBee to 9600. That is done via this code:

XBee.begin(9600);

Uno-computer: On the Uno side the baud rate of this line is set by this code:

Serial.begin(9600);

On the computer side the baud rate is set by the baud rate menu at the lower right corner of Serial Monitor. You need to make sure that is set to the same baud rate as what you set in your sketch.

@pert

Thank you for your help. I'm just wondering why the overriding baud rate was set to 115200 even though I upload different programs to the board, or with the steps I tried doing, which I mentioned.

The bootloader uses 115200bps to upload your sketch, regardless of what speeds your sketch might use to communicate.