Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yldzmuhammed opened this issue Aug 30, 2018 · 2 comments
Labels
component: core level: easy type: enhancement waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Milestone

Comments

@yldzmuhammed
Copy link

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.

@d-a-v
Copy link
Collaborator

d-a-v commented Aug 30, 2018

Those parameters should not come to this function that way.
They are already internally stored and their values should be extracted from there.

What would be nice is to move this workaround into uart.c:uart_wait_tx_empty(), in there you can read USC0(uart->uart_nr) which is the serial mode (8N1 or whatever).
With a couple of defines, you can extract from it the width, the parity and the stop bit.

#define MODE2WIDTH(mode) (((mode) >> 2) + 5) // see UART_NB_BIT_* 

then MODE2WIDTH(USC0(uart->uart_nr)) would give you the needed data_width.

We would lovebe thrilled if you could make a pull request !
(note: this is C so you are an expert :)

@devyte devyte added type: enhancement component: core waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. level: easy labels Aug 30, 2018
@devyte devyte added this to the 2.6.0 milestone Aug 30, 2018
@devyte
Copy link
Collaborator

devyte commented Oct 29, 2019

This is already done in #5293 . Closing.

@devyte devyte closed this as completed Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: core level: easy type: enhancement waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests

3 participants