Skip to content

Add RS485 transmit pin functionality #4

@vk2tds

Description

@vk2tds

Firstly, thanks for your work. It has saved me from writing my own code. Great work.

I am wanting to use this for RS485, where we need to swap between transmit and receive modes on the converter, by changing the state of a pin. This would normally raise an output some time before sending the first character, and then lowering the output sometime after the last character has been sent and the send buffer is empty.

I am thinking about how this should be implemented. I am guessing that the signal should go high when MB_PRE_DELAY is set. And then unset when MB_POST_DELAY goes to MB_RECEIVE.

A callback would probably work well here The only complication here is that there are (generally) 63 bytes in the outgoing buffer. The Serial.write will not block until the outgoing buffer is full. With Modbus being a master/slave protocol, this shouldn't be too much of an issue with bytes from previous packets still waiting to appear on air. There are functions that can report if the outgoing buffer is empty or how many characters are free in the buffer, but they vary between Arduino implementation and processor.

Therefore I think the best way to deal with that would either be a delay based on bitrate and number of transmitted characters, or a callback that can return true when the outgoing buffer is actually empty.

Once again, thanks for the great work

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions