These are chat archives for esp8266/Arduino

25th
Jan 2017
Martin Sloup
@arcao
Jan 25 2017 15:34
hi, do you know if is in SoftwareSerial any issue with reopening serial with different speed? I am tring to detect HC-12 serial speed. So I first call begin(9600), print('AT\r\n') and with find("OK\r\n") detect if it's correct speed. If not then I call end() -> flush() -> begin(2400) and try the detection with print('AT\r\n') again. Unfortunatelly SoftwareSerial can't receive anything. With Logic Analyzer I see correct speed and communication. When I try to comment particular speed detection part. It works ok. Here is my sketch:
#include <SoftwareSerial.h>

#define HC12_PIN_RXD D5
#define HC12_PIN_TXD D6
#define HC12_PIN_SET D7

SoftwareSerial hc12(HC12_PIN_RXD, HC12_PIN_TXD, false, 256); // RX, TX, inverted_mode, buffer

void setup() {
  Serial.begin(115200);

  pinMode(HC12_PIN_SET, OUTPUT);

  Serial.println(F("Setting up HC-12..."));

  // switch to config mode
  digitalWrite(HC12_PIN_SET, LOW);
  delay(80); // 40ms suggested by doc

  while(1) {
    Serial.println(F("Detecting HC12 serial speed..."));

    // try 9600bps
    hc12.begin(9600);
    hc12.print("AT\r\n");
    if (hc12.find("OK")) {
      Serial.println(F("Detected 9600bps..."));
      break;
    }

    delay(50);
    hc12.end();
    hc12.flush();

    // try 2400bps
    hc12.begin(2400);
    hc12.print("AT\r\n");
    if (hc12.find("OK")) {
      Serial.println(F("Detected 2400bps..."));
      break;
    }

    delay(50);
    hc12.end();
    hc12.flush();
  }

  Serial.println(F("Ready."));
}

void loop() {}
Martin Sloup
@arcao
Jan 25 2017 17:29
Aghhh! I figure out. It's bug in SoftwareSerialor at least inconsistency with original SoftwareSerial. Actually begin(..) doesn't call attachInterrupt, this is done in constructor only. So when I call end(), it do detachInterruptand stay detached after next begin(..) call. Can I create issue / PR in https://github.com/plerup/espsoftwareserial?