Hi
I just looked into this and found the following:
1) When the mode is set to
RTS_CTS the RTS and CTS lines are set to their corresponding peripheral mode when the interface is opened. This is what you have seen, but when not using
RTS_CTS mode (but using
SET_RS485_MODE) this doesn't happen.
The reason for this is because the RS485 mode (based on RTS signal controlling the RS485 direction) doesn't need the CTS line to be configured.
2)
SET_RS485_MODE is in fact not a mode configuration but instead is a configuration "command".
It is used in a similar way to enabling the receiver and/or transmitter:
fnDriver(SerialPortID, (TX_ON | RX_ON), 0); // enable rx and txwith
fnDriver(SerialPortID, (MODIFY_CONTROL | CONFIG_RTS_PIN | SET_RS485_MODE), 0);or
fnDriver(SerialPortID, (MODIFY_CONTROL | CONFIG_RTS_PIN | SET_RS485_MODE | SET_RS485_NEG), 0);That means that the command can be used after the interface has been opened to configure the RTS pin, set the RS485 mode and also set the polarity of the RTS control signal in this mode.
Your modification is essentially doing the same as the call above does, but within the open function.
See page 15 of the document:
http://www.utasker.com/docs/uTasker/uTaskerUART.PDF which also illustrates the method.
Regards
Mark
P.S. I notice that you set
ECHO_RX_CHARS but I am not sure that this is suitable for RS485 mode because the receiver will immediately send back each character when it is received (in its interrupt routine). If you receive data with no spaces between characters I could imaging that the echo will cause following characters to be lost since the RS485 direction will immediately be set to transmission for the character time.
If only 'typed' input is being received this probably wouldn't matter since the echo would be much faster than the next character reception.