Skip to content

Serial.flush should change to Serial.flush(uint32_t data_width, uint32_t parity, uint32_t stop) #5094

Closed
@yldzmuhammed

Description

@yldzmuhammed

Platform

  • Hardware: [LoLin new NodeMCU V3 board]
  • Core Version: [Updated today.So should be 2.4.2?]
  • Development Env: [Arduino IDE|Platformio|Make|other]
  • Operating System: [Windows]

Settings in IDE

  • Module: [Nodemcu 0.9]
  • Flash Size: [4MBB]
  • lwip Variant: [v2 Lower Memory|Higher Bandwidth]
  • CPU Frequency: [80Mhz]
  • Upload Using: [SERIAL]
  • Upload Speed: [921600]

Problem Description

I am building a Rs485 project. So esp has to control RE and DE pins. I have done some test and finaly find a easy way (for me at least). I added second flush function like:


void HardwareSerial::flush(uint32_t data_width, uint32_t parity, uint32_t stop)
{
    if(!_uart || !uart_tx_enabled(_uart)) {
        return;
    }

    uart_wait_tx_empty(_uart);
    //Workaround for a bug in serial not actually being finished yet
    //Wait for 8 data bits, 1 parity and 2 stop bits, just in case
    delayMicroseconds(((data_width + parity + stop) * 1000000) / uart_get_baudrate(_uart) + 1);
}

I belive in the HardwareSerial.h file the prototype should change:

void flush(uint32_t data = 8_width, uint32_t parity = 0, uint32_t stop = 1);

I user using serial port with default settings (8N1) then user dont have to anything. Otherwise, function must call with serial config parameters.

With this function, esp can handle tx enable, rx enable nicely.

What do you think? Is there any better way to handle RS485 comm direction problem?

NOTE: I am not a cpp expert.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions