Terminal handshake flag

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Terminal handshake flag

Postby mishmanash » Fri May 11, 2012 1:30 am

PIC18F47J13 and MPlab C18 compiler.

I have this made up code for communicating with Terminal(teraTerminal) via TX/RX of RS-232.

I want to print an initial message as soon as there is a connection, is there any flag that gets set after a successful handshake?

if not, is there anyway to do this?

thanks
mishmanash
 
Posts: 6
Joined: Wed Feb 22, 2012 2:37 pm

Re: Terminal handshake flag

Postby adafruit_support_rick » Fri May 11, 2012 8:55 am

If I understand you correctly, you want your code to somehow know when a terminal has been plugged in?
There is an RS232 signal called Data Terminal Ready (DTR). Terminals are supposed to set this line high when they are ready to receive data. If you're lucky, your terminal will actually do this.
User avatar
adafruit_support_rick
 
Posts: 2917
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Terminal handshake flag

Postby mishmanash » Fri May 11, 2012 12:45 pm

Yes exactly thats what I want, so is this something I can put in a variable or do a if statement on?
can you explain more?

thanks
mishmanash
 
Posts: 6
Joined: Wed Feb 22, 2012 2:37 pm

Re: Terminal handshake flag

Postby philba » Fri May 11, 2012 12:54 pm

On an RS232 DB9 connector there is a pin that is dedicated to DTR. Look up the spec. You don't say if you are using USB or not but I would bet you are. DTR is usually defined for USB to serial adaptors. You need to make sure that it runs into an I/O pin on your micro. You can either use an interrupt pin or poll it. You might have to set DTR (or DSR) in your terminal program as well.

There are other tricks - you could fill up the transmit buffer and look to see if it empties. There are also autobaud detection techniques you could look at to get an idea. google is your friend.
philba
 
Posts: 387
Joined: Mon Dec 19, 2011 5:59 pm

Re: Terminal handshake flag

Postby adafruit_support_rick » Fri May 11, 2012 1:14 pm

How to do it really depends on how you are talking to the RS232 UART. If you are using a serial driver from a library, then that driver should have functions you can call to determine the state of DTR. If you are writing your own driver, or just working with the UART directly from your application, then you are going to have to look at the documentation for the UART to find out what hardware register you have to read in order to find out the state of DTR. The PIC data sheet will have information about the UART.

If you are just using generic C I/O functions, you may have a problem. Offhand, I don't know how to do this in C. Possibly, if you create a stream with FILE, fopen() might give you an error code if DTR is not set. I don't know. See if the compiler manual offers any help with this.

There are several signals like DTR in the RS232 standard. Sometimes, you may see them referred to collectively as 'modem signals'.
User avatar
adafruit_support_rick
 
Posts: 2917
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Terminal handshake flag

Postby philba » Sat May 12, 2012 9:12 am

I want to clarify some points about serial as it often makes it hard to understand what's going on. There is no such thing as an RS232 UART. Doesn't exist. RS232 really has nothing to with a UART. It's a common misunderstanding, though.

RS232 is a standard defining what signals and voltage levels go between communicating devices. RS232 does not define a protocol. RS232 voltage levels are not compatible with modern microcontrollers. A transceiver like a max232 simply takes TTL level signals and turns them into RS232 signals and vice-versa. RS232 also defines specific signal pins/wires beyond the receive and transmit lines (so called RX and TX). RS232 is pretty much gone, being supplanted by USB. In fact hardly any new PCs have an RS232 connector on them but they still speak "serial". http://en.wikipedia.org/wiki/RS-232

A UART (or USART) is a device that speaks a particular protocol - in this case we are talking about Asyncronous Serial. http://en.wikipedia.org/wiki/Asynchronous_serial Async is often spoken over RS232 connections but doesn't have to be. In fact people talk about TTL serial when they mean async that is not being transmitted via RS232. (TTL is a bit of a misnomer as well but enough pedantry for one day.) The UART does not know anything about RS232 signalling pins like DTR, DSR, CTS, RTS, RI or CD. It just speaks async (transmit and receive). Those signals need to be routed from the RS232 transceiver into I/O pins on the microcontroller (or perhaps other logic) completely separate from the UART. A serial driver needs to look at the I/O pins if it expects to use, say, DTR. Usually, a UART is integrated into a microcontroller and the RS232 transceiver is separate.

Often USB to serial adapters will use some of the RS232 signalling pins though you have to take a close look at each one. Ones meant for Arduino seem to use CTS and RTS though it appears you don't really need those signals on recent versions. Most USB to serial chips support the full range of RS232 signals but often breakout boards don't route them all out. The adafruit FTDI friend, for example, appears to support RTS and CTS. Some of the SFE breakouts support everything (even CD - carrier detect - talk about ancient signals).

Phil

[edit] some terminal programs will allow you to define what signalling methods to use. I use Putty which allows me to select RTS/CTS or DSR/DTR to start/stop transmission. teraterm doesn't appear to (though I haven't used it in a while).
philba
 
Posts: 387
Joined: Mon Dec 19, 2011 5:59 pm


Return to Microcontrollers

Who is online

Users browsing this forum: No registered users and 4 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [108]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[31]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[34]
LCDs & Displays[48]
Components & Parts[70]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[111]
 
Wireless[14]
Cables[62]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]