Hi, I need to change the baud rate to receive and transmit strings, I am using this code, but when I set the Serial.begin inside the loop, my code does not work, but if I remove this if the code runs, also I have inserted a delay after the baudrate change, but despite the fact that I am not sending anything to the serial port, there are some characters that are leaking, I do not understand where they have been generated from, the characters in hexadecimal format are:
FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A FE 0D 0A . . .
Hi,
What model Arduino are you using?
If a Mega, it has more than one serial I/O.
If a UNO or Nano, have you tried Software Serial library, to make an extra serisal port from I/O pins?
Can you tell us the application, what hardware are you using and what is communicating with what?
As I said, I'm using a NANO with a multiplexer that must communicate with two peripherals that have different speeds (115200, 19200), that's why I can't define a single speed, I just published the sketch to show how I try to change the speed within the loop,
From your descriptions, it's not quite clear how you're testing. Are you using serial monitor to see the result? If so, that means that you have 2 serial devices on one UART, the PC and the multiplexer (with sources).
Also, if you change the baudrate in serial monitor, the Nano will reset; it might explain the unexpected data (leftovers from the bootloader).
I suggest that you provide a schematic (photo of handdrawn one is fine).
Why not switch to a Teensy 3.2? It has 3 Hardware UARTS that will run at whatever baud you want plus the native USB for Serial debug printing. More powerful processor and more memory too.
Would you please be kind enough to upload my code to your Arduino and enter a simple string by console, you will notice that when you enter a string, it is printed to the console but there is also a Hex 0xFF \r\n character that repeats continuously, I don't understand why?