Jump to content

Photo

RS232 Programming


7 replies to this topic

#1 BeeryMiller OFFLINE  

BeeryMiller

    Chopper Commander

  • 157 posts

Posted Wed Jan 10, 2018 10:57 AM

I need some insight to understand a few things.

 

I'm working with the My-Term source code.  I've never been great with the RS232 programming and have always relied on the code of others and their comments to figure out how they were sending and getting characters from the RS232 port.

 

Is there something special with any of the bits programmers are doing to establish Flow Control?  Or is it just a matter of polling the RS232 with enough frequency to capture the characters.

Specifically, I am trying to make sure I do not drop any characters from the RS232 using the Lantronix UDS-10.  I know at both 19.2K and 38.4K I can drop some characters when I am using Telnet to another telnet BBS.  Is there something I can do to prevent those loss of characters?

 

FWIW, I am using the cable specified in Tim's Port document for cable setup.

 

Thanks for any feedback.  

 

Beery

 

 

 



#2 Willsy OFFLINE  

Willsy

    River Patroller

  • 3,060 posts
  • Location:Uzbekistan (no, really!)

Posted Wed Jan 10, 2018 11:18 AM

Can you not use RTS/CTS handshaking? If you have, say a 64 byte receive buffer, you drop CTS when you have, say, 58 characters in the buffer. That way the UDS should stop sending before you overrun your buffer. Response latency of the UDS 10 (i.e. how long it takes to obey your request to stop) will probably be a function of the baud rate.

99% of folk implement RS232 as a three-wire, but it's far better to implement 5 wire (data with RTS/CTS) if you can.

#3 TheBF OFFLINE  

TheBF

    Moonsweeper

  • 458 posts
  • Location:The Great White North

Posted Wed Jan 10, 2018 11:54 AM

Can you not use RTS/CTS handshaking? If you have, say a 64 byte receive buffer, you drop CTS when you have, say, 58 characters in the buffer. That way the UDS should stop sending before you overrun your buffer. Response latency of the UDS 10 (i.e. how long it takes to obey your request to stop) will probably be a function of the baud rate.

99% of folk implement RS232 as a three-wire, but it's far better to implement 5 wire (data with RTS/CTS) if you can.

 

 

The hardware handshakes are ideal until you discover you are communicating with a system that is slow to recognize them.

 

I have had that happen in the old days.



#4 apersson850 OFFLINE  

apersson850

    Moonsweeper

  • 446 posts

Posted Wed Jan 10, 2018 11:55 AM

He would still have to transfer the data from the UART (or ACC by TI) to the buffer frequently enough to avoid data loss.



#5 mizapf OFFLINE  

mizapf

    River Patroller

  • 2,768 posts
  • Location:Germany

Posted Wed Jan 10, 2018 12:20 PM

From my page on ninerpedia:

 

Software handshaking is within the responsibility of the applications that use the serial connection; it is implemented by sending control bytes (X-ON, X-OFF) over the data line.

Hardware handshaking is possible at two levels:

  •     using RTS and CTS,
  •     using DTR and DSR.

The difference between both is that RTS/CTS handshaking has immediate effect on the transmission of the UART (a cleared CTS line turns off the transmitter of the UART) while DTR/DSR are handled by interrupts that are signaled to the application.



#6 BeeryMiller OFFLINE  

BeeryMiller

    Chopper Commander

  • Topic Starter
  • 157 posts

Posted Wed Jan 10, 2018 12:50 PM

From my page on ninerpedia:

 

Software handshaking is within the responsibility of the applications that use the serial connection; it is implemented by sending control bytes (X-ON, X-OFF) over the data line.

Hardware handshaking is possible at two levels:

  •     using RTS and CTS,
  •     using DTR and DSR.

The difference between both is that RTS/CTS handshaking has immediate effect on the transmission of the UART (a cleared CTS line turns off the transmitter of the UART) while DTR/DSR are handled by interrupts that are signaled to the application.

 

Let's explore this comment a bit further.  As my intentions are for Telnetting purposes with the potential one could either be using the Lantronix UDS-10 or the Wifi2Modem, which method (RTS/CTS or DTR/DSR) would be preferred with a reasonable expectation no characters would be lost?  I assume this is setting a bit on the RS232?

 

Listed below is the RS232 code MyTerm is using.  Can someone comment what would need to be changed?  There is an approximate 8K circular buffer as is right now and I see some places in the program I can speed up character acquisition.

 

Any thoughts appreciated.

 

 

*

* INIT     Initialize RS232
*
 
INIT0  MOV  @CRUBAS,R12  Get CRU base
       LIMI 0            No interrupts
       SBO  0            Turn on RS232 card
       MOV  R12,R9       Save CRU base
       MOV  @PORTDT,R12  Get port address
 
       SBO  31           Start initialization
       LI   R0,>20       Delay counter
INIT1  DEC  R0           Waste time
       JNE  INIT1        Keep waiting
 
       SBZ  13           Start data initialization
       MOV  @PARIDT,R1   Get parity data
       LDCR R1,8         Set parity
       MOV  @BAUDDT,R1   Get baud rate data
       LDCR R1,12        Set baud rate
 
       MOV  R9,R12       Get CRU base
       SBZ  0            Turn off RS232 card
       RTWP              Return to caller
 
 
*
* GETRS    Get a Character from the RS232 Port
*
 
GETRS0 LIMI 0            No interrupts
       BL   @GETRS1      Do routine
       RTWP              Return to caller
 
GETRS1 MOV  @CRUBAS,R12  Get CRU base
       SBO  0            Turn on RS232 card
       MOV  R12,R9       Save CRU base
       MOV  @PORTDT,R12  Get port address
 
       TB   21           Is a character waiting?
       JNE  GETRS3       No, Return to caller
 
       STCR R10,8        Yes, Get character
       SBZ  18           Tell RS232 we have it
       ANDI R10,>7F00    Strip off high bit
       MOV  @CPOINT,R8   Get buffer pointer
       MOVB R10,*R8+     Store character
       CI   R8,>6000     End of memory?
       JL   GETRS2       No, Skip this
       LI   R8,BUFF      Loop to start of buffer
 
GETRS2 MOV  R8,@CPOINT   Store buffer pointer
       SETO @CFLAG       Set buffer flag
 
GETRS3 MOV  R9,R12       Get CRU base
       SBZ  0            Turn off RS232 card
       RT                Return to caller
 
 
*
* ECHO     Echo a Character Over RS232 Port
*
 
ECHO0  MOV  @PORTDT,@RTSVPT   Save port address
 
ECHO0A MOVB *R13,R0           Get character
       MOV  @PORTDT,R12       Get port address
       ANDI R12,>FF00         Get CRU base
       LIMI 0                 No interrupts
       SBO  0                 Turn on RS232 card
       MOV  R12,R9            Save CRU base
       MOV  @PORTDT,R12       Get port address
       SBO  16                Start character send
 
ECHO1  TB   22                Is RS232 ready?
       JNE  ECHO1             No, Keep waiting
 
       LDCR R0,8              Yes, Send character
       SBZ  16                Tell RS232 we're ready
       MOV  R9,R12            Get CRU base
       SBZ  0                 Turn off RS232 card
       MOV  @RTSVPT,@PORTDT   Restore port address
       RTWP                   Return to caller
 


#7 mizapf OFFLINE  

mizapf

    River Patroller

  • 2,768 posts
  • Location:Germany

Posted Wed Jan 10, 2018 2:08 PM

I found it really enlightening to read the 9902 specification: ftp://ftp.whtech.com/datasheets%20and%20manuals/Datasheets%20-%20TI/TMS9902_dataSheet_Jan77.pdf

 

It was this manual that made me understand the RS232 chip operation for the first time.



#8 BeeryMiller OFFLINE  

BeeryMiller

    Chopper Commander

  • Topic Starter
  • 157 posts

Posted Wed Jan 10, 2018 4:12 PM

Thanks for that reference.  That is the first time I have ever seen that datasheet.

Beery






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users