NET+OS 5.1 serial RS485 problem

In NET+OS 5.1 it is possible to have automatic software control of Driver Enable for serial RS485 communication (this feature is undocumented though). I cannot get this to work as expected. I am using the SIO_RTS_XMIT_ENCAPSULATION ioctl flag to make NET+OS 5.1 use the RTS pin as Driver Enable (DE). The code to activate this could look like this: //Enable RS485 DE support via the RTS signal portSettings=0x01; ioctlRes=ioctl(com, SIO_RTS_XMIT_ENCAPSULATION, &portSettings); if (ioctlRes<0) { //Error! return ioctlRes; } As long as nothing is connected to the RX pin of the serial port it works just fine (DE is high only when something is output on TX, otherwise it is low), but it appears as soon there is input on the RX pin during DE high, DE remains high infinitely even if there is no output on TX. The implementation of the NET+OS RS485 DE functionality uses TX->RX loopback and a counter to determine when to set DE to low. DE is set to low when the same number of chars that was output on TX is received on RX (the counter is used for this). Is it so that the counter somehow gets “confused” when there is input on RX so that DE is never set to low or what is causing this problem? Could it be glitches on RX? The above text assumes the typical connection for RS485 (see case 3 below) Equipment: *UNC20 rev. 0 based on the NS7520 (See *Maxim MAX3483 RS485 interface chip with 120 ohm termination resistor between A and B Tested with/without 10k resistor to ground in series with MAX3483 receiver enable (to have TX echo) Tested with DE connected to MAX3483 receiver enable (to not have TX echo) Tested with extra pull-up resistors on receiver enable and driver enable Tested with a 10k resistor in series with driver enable (from UNC20) I’ll give some cases to clarify (all connections are the same unless otherwise mentioned): Case 1: Nothing connected to the UNC20 Result: everything works Case 2: MAX3483 connected to UNC20 and all signals connected but no termination resistor Result: everything works Case 3: MAX3483 connected to UNC20 and all signals connected with termination resistor Result: DE is always high (regardless of transmitting or not) Best regards, Fredric

I have been looking into the NET+OS 5.1 implementation of serial TX and RX. The procedures I have looked at are onccIntWr() and onccIntRd() in file netos_serl.c. The counter that is used to keep track of when to set DE to low is called chars2Encapsuate. chars2Encapsuate is incremented by 1 in onccIntWr() for every char that is sent and decremented by 1 in onccIntRd() for every char that is received. When chars2Encapsuate reaches 0 in onccIntRd() all chars have been sent and it is OK to set DE to low. The problem is that chars2Encapsuate never reaches 0 in onccIntRd() and hence the code to set DE to low is never executed. Somehow chars2Encapsuate is incremented more times in onccIntWr() than it is decremented in onccIntRd(). I have not been able to figure out why this happens, but this is apparently the reason for DE not going low when it is supposed to. Best Regards, Fredric