esp8266 软串口 例程:

参考网址:
https://arduino-esp8266.readthedocs.io/en/2.4.1/reference.html#serial

https://github.com/plerup/espsoftwareserial 源码

esp8266 软串口 例程:_第1张图片

esp8266 软串口 例程:_第2张图片

代码:


#include 

SoftwareSerial swSer(14, 12, false, 256);

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




    Serial.println("\nSoftware serial test started 2222");

    delay(5000);

    for (char ch = ' '; ch <= 'z'; ch++) {
        swSer.write(ch);
    }
    swSer.println("");

}

void loop() {
    while (swSer.available() > 0) {
        Serial.write(swSer.read());
    }
    while (Serial.available() > 0) {
        swSer.write(Serial.read());
    }

}

函数 定义:

class SoftwareSerial : public Stream
{
public:
   SoftwareSerial(int receivePin, int transmitPin, bool inverse_logic = false, unsigned int buffSize = 64);
   ~SoftwareSerial();

   void begin(long speed);
   long baudRate();
   void setTransmitEnablePin(int transmitEnablePin);

   bool overflow();
   int peek();

   virtual size_t write(uint8_t byte);
   virtual int read();
   virtual int available();
   virtual void flush();
   operator bool() {return m_rxValid || m_txValid;}

   // Disable or enable interrupts on the rx pin
   void enableRx(bool on);

   void rxRead();

   // AVR compatibility methods
   bool listen() { enableRx(true); return true; }
   void end() { stopListening(); }
   bool isListening() { return m_rxEnabled; }
   bool stopListening() { enableRx(false); return true; }

   using Print::write;

private:
   bool isValidGPIOpin(int pin);

   // Member variables
   int m_rxPin, m_txPin, m_txEnablePin;
   bool m_rxValid, m_rxEnabled;
   bool m_txValid, m_txEnableValid;
   bool m_invert;
   bool m_overflow;
   unsigned long m_bitTime;
   bool m_highSpeed;
   unsigned int m_inPos, m_outPos;
   int m_buffSize;
   uint8_t *m_buffer;

};

你可能感兴趣的:(arduino)