Changing Particle Electron Hardware Baud Rate in Serial1

Particle Electrons come automatically configured to communicate through Serial1 in 9600 baud and I am attempting to write a code which will update the Serial1 baud rate to 230400 when the Electron is on. The following code, when executed on an Electron configured at 9600 baud, is not changing the baud rate to 230400 as desired. I am a novice to this sort of programming and would highly appreciate your explanations. Thank you!

#include "Particle.h"

void setup() {
  Serial1.println("ATZ"); // "wakes up" module for communication
  Serial1.println("STSBR 230400"); // sets electron baud rate to 230400
  Serial1.println("STWBR"); // saves new baud rate to electron

That would be because the Electron (also the Photon and P1) only support baud rates up to 115200.

Baud rates of 1200 up to 115200 are supported for hardware serial channels.

I’ve been sending these commands manually through CoolTerm and the Serial1 baud rate on the Electron does indeed change from 9600 to 230400. However, I do not see the same results when I run this program.

How would you set the internal baudrate from outside?
How have you connected Serial1 to your computer?
Before you can set a new baudrate you should call Serial1.end() when you called Serial1.begin() previously.

  1. I believe sending these commands via the TX/RX lines do work.
  2. I have the electron connected via a USB to TTL cable.
  3. I have incorporated that change into my code. It hasn’t resolved the issue, but hopefully its a step in the right direction.

Thank you!

I wouldn't know how that should work. AFAICT there is no logic that would support dynamic baudrate selection just via RX/TX.
The interface would need to sync to an unknown rate or scan for the desired rate but ignore the explicitly stated baudrate when calling Serial1.begin() - without that call the GPIOs are not set up as serial interface.

1 Like

Is it possible that there is some confusion between setting the baudrate via the wiring interface and setting the baudrate on the cellular modem via an AT command?

1 Like