I'm currently writing a MicroPython library to support the SC16IS740 over SPI.
I'm using a breakout for testing the SC16IS740 coupled to a MAX3237.
Every basic features works (including RX & TX FiFo) and tested with physical TX->RX Loopback (and my scope).
Now, I want to test/implement the Auto-RTS feature.
To check it: I placed a scope with ch1 on RX and ch2 on RTS.
I flood the RX buffer and expect the RTS signal to switch High on the scope.... but it doesn't happens.
Here follows the MicroPython code with value of halt_trigger & resume_trigger (in chars). Code mainly read & write register for a given channel (the 'ch' parameter).
I'm missing something with the datasheet but I'm not able to identify it.
Remark: the last instructions force the RTS high for checking manual activation at the scope. It then goes low and never gets activated by auto-RTS.... for sure, the RX FIFO get full.
def enable_rts( self, halt_trigger, resume_trigger ):
assert 4<=halt_trigger<=60, "RTS trigger must be within 4-60 range"
assert 4<=resume_trigger<=60, "RTS trigger must be within 4-60 range"
assert (halt_trigger%4) + (resume_trigger%4) == 0, "Trigger level are step by 4!"
assert halt_trigger > resume_trigger, "halt_trigger must be greater than resume_trigger!"
_halt = halt_trigger//4
_resume = resume_trigger//4
# Set LCR=0xBF to access EFR register
_old_lcr = self.owner.bus_wrapper.read_reg( REG_LCR, ch=self.ch ) # store transmission config (eg: 8n1)
self.owner.bus_wrapper.write_reg( REG_LCR, 0xBF, ch=self.ch )
# activate enhanced feature
_efr = self.owner.bus_wrapper.read_reg(REG_EFR, ch=self.ch)
_efr = _efr | 0b00010000
self.owner.bus_wrapper.write_reg(REG_EFR, _efr, ch=self.ch)
print( "EFR:" , bin(self.owner.bus_wrapper.read_reg(REG_EFR, ch=self.ch)) , 'Enhanced function activation')
# Close access to EFR & restore transmission config (eg:8n1)
self.owner.bus_wrapper.write_reg( REG_LCR, _old_lcr, ch=self.ch )
# Enable TCR & TLR register access
_mcr = self.owner.bus_wrapper.read_reg(REG_MCR, ch=self.ch)
_mcr = _mcr | 0b00000100
self.owner.bus_wrapper.write_reg(REG_MCR, _mcr, ch=self.ch)
print( "MCR:" , bin(self.owner.bus_wrapper.read_reg(REG_MCR, ch=self.ch)), 'Enable TCR & TLR register')
# Set TCR trigger values
_tcr = self.owner.bus_wrapper.read_reg(REG_TCR, ch=self.ch)
_tcr = _tcr | (_resume<<4)
_tcr = _tcr | _halt
self.owner.bus_wrapper.write_reg(REG_TCR, _tcr, ch=self.ch)
print( "TCR:", bin(self.owner.bus_wrapper.read_reg(REG_TCR, ch=self.ch)), "Transmission Control register (resume & halt levels)")
# TLR must be cleared (to use TCR)
self.owner.bus_wrapper.write_reg(REG_TLR, 0x00, ch=self.ch)
print( "TLR:", bin(self.owner.bus_wrapper.read_reg(REG_TLR, ch=self.ch)), "Disable TLR values (so use TCR)")
# Disable TCR & TLR register access
_mcr = self.owner.bus_wrapper.read_reg(REG_MCR, ch=self.ch)
_mcr = _mcr & 0b11111011
self.owner.bus_wrapper.write_reg(REG_MCR, _mcr, ch=self.ch)
print( "MCR:" , bin(self.owner.bus_wrapper.read_reg(REG_MCR, ch=self.ch)), 'Disable TCR & TLR register')
self.owner.bus_wrapper.write_reg( REG_LCR, 0xBF, ch=self.ch )
# Enable auto RTS flow control
_efr = _efr | 0b01000000
self.owner.bus_wrapper.write_reg(REG_EFR, _efr, ch=self.ch)
print( "EFR:" , bin(self.owner.bus_wrapper.read_reg(REG_EFR, ch=self.ch)) , 'Enable auto RTS')
# Close access to EFR & restore transmission config (eg:8n1)
self.owner.bus_wrapper.write_reg( REG_LCR, _old_lcr, ch=self.ch )
# Initial State of RTS bit in Modem (MCR)
_mcr = self.owner.bus_wrapper.read_reg( REG_MCR, ch=self.ch )
_mcr = _mcr | 0x02
self.owner.bus_wrapper.write_reg( REG_MCR, _mcr, ch=self.ch )
Hint and suggestions would be warmly welcome.
Cheers,
Dominique
Hello,
Based on the data sheet, I would suggest checking the following points:
Please verify that EFCR[4] = 0. EFCR[4] enables the Auto RS-485 RTS control. When this bit is set, the transmitter takes control of the RTS pin, and this function has precedence over both manual RTS control and the hardware flow-control circuitry. Therefore, EFCR[4] should be cleared when using Auto-RTS hardware flow control.
TLR does not define the Auto-RTS halt/resume thresholds. For Auto-RTS, the receiver FIFO trigger levels are taken from TCR, or from FCR if the TCR bits are cleared. TLR is used for the programmable transmit and receive FIFO trigger levels associated with interrupt generation. Therefore, clearing TLR should not be required for Auto-RTS operation.