AN208

PicStic 5 & 56K90R

Interfacing the PicStic 5 to Micromint’s 56K90R Modem

January 9, 2002

 

Introduction:   This application note will demonstrate how to interface Micromint’s PicStic 5 to Micromint’s 56K90R embedded socket modem.

 

 

Background:      The PicStic 5 utilizes a pair of RS-485 drivers to allow for a variety of communication protocols, including RS-232A, RS-485 and RS-422. This enables the Picstic 5 to communicate with a wide range of devices, such as PCs and other microcontrollers. With the use of the PicBasic Pro compiler, the PicStic 5 can also use any of its GPIO as a software serial port with baud rates up to 2400bps. These software ports can be configured to send and receive inverted or non-inverted signals. In addition, these software ports can also be set with modifiers so only specific data formats are sent or received.

     With the help of the 56K90R modem, the PicStic 5 can now extend its communication capabilities to include telephone line interfaces. This application note is written under the pretense that the hardware handshaking of the 56K90R modem has already been disabled. For a detailed description on disabling the hardware handshaking of the modem, please refer to Micromint’s 56K90x/2400xEEM datasheet. For simplicity, the application does not incorporate a speaker for the modem. If a speaker is desired,  Micromint’s 56K90x/2400xEEM Users Guide can be referenced for proper connection specifications.

     This application can be performed using two PicStic 5s and two 56K90R modems or by using a PicStic 5, a 56K90R modem and a standard telephone. Regardless of the method used, either two separate phone lines or a telephone line simulator will be needed to conduct this application. The modem uses the standard AT command set.

 

 

How it works:    This application note shows how to interface a PicStic 5 to a 56K90R and to a PC. The program written for the PicStic 5 will provide step-by-step instructions for using the 56K90R modem. The program will be broken into two parts, placing a call and receiving a call. The schematic below illustrates the connections between the modem and the PicStic 5 and the connections from the PicStic 5 to the PC. Notice the series resistors between the PicStic 5 and the PC; these are for current limiting to prevent damage to the PicStic 5, as a software serial port is being used on two of the PicStic 5’s I/Os. The schematic also shows how to connect an EMI suppression network between the modem and the telephone line.       

       Upon powering the PicStic 5 a menu will appear on the PC allowing the user to place a call or wait to receive a call. As commands are issued to the modem the PicStic 5 will give a brief description of the events taking place. Once a connection has been established a third option will be available. This option will give the user the ability to terminate the connection. The PicStic 5 will again give a description of the events as they occur.

       When using the PicStic 5 and 56K90R modem to call a standard telephone there will not be a connection established. Connecting in this configuration will only allow a user to verify the call by listening to the phone ring. This is not the recommended configuration for this application, as it does not demonstrate the full capabilities of the 56K90R modem. If two PicStic 5s and two 56K90R modems are being used then two PCs or a PC with two serial ports will be needed. In this configuration one PicStic 5 will need to place a call while the other receives a call. This is the recommended configuration for this application. To simplify the communications between the PicStic 5 and the 56K90R modem, the PicStic 5 will configure the modem to respond in short form.

 

  

Program Listing:

'               '               '               '               '               '               '               '               '               '               '               '

'

'               Controlling the 56K90R modem with the PicStic 5

'               Written in PicBasic Pro Version 2.40

'               January 09, 2002

'

'               '               '               '               '               '               '               '               '               '               '               '               

 

'Definitions & Variables

DEFINE OSC 8

DEFINE HSER_RCSTA      90H         ' Receiver enable for the hardware serial port

DEFINE HSER_TXSTA      20H         ' Transmitter enable for the hardware serial port

DEFINE HSER_BAUD        2400        ' Baud rate for the hardware serial port

 

SO           VAR       PORTB.3                ' Software Transmit pin

SI            VAR       PORTB.4                ' Software Receive pin

BAUD    CON       16468                      ' Software Baud rate

ADCON1 = 7

 

STRINPUT            VAR       BYTE      ' Input variable

STRARRAY          VAR       BYTE[7] ' Input variable array

TELENUM            VAR       BYTE[11]' Telephone number to be called

NUMSIZE             VAR       BYTE      ' Number of digits in the phone number

HIGH PORTC.1

PAUSE 1

 

'

' Menu

'

 

MENU:

SEROUT2 SO,BAUD,["Please select from the options listed below",10,13,10,13]

SEROUT2 SO,BAUD,["1.       Place outgoing call",10,13]

SEROUT2 SO,BAUD,["2.       Wait for incoming call",10,13]

 

CHKVAL:

SERIN2 SI,BAUD,[ DEC1 STRINPUT ]

SELECT CASE STRINPUT

CASE 1

                GOTO MKCALL

CASE 2

                GOTO RVCALL

CASE ELSE

                SEROUT2 SO,BAUD,[ "Please select 1 or 2",10,13,10,13]

                GOTO CHKVAL

END SELECT

 

'

'MAKE A CALL

'

 

MKCALL:

GOSUB INITALZ

 

'

' Get number to dial

'

 

GTNUM:

SEROUT2 SO,BAUD,["Is the number to be dialed a long distance number (y/n)?",10,13,10,13]

SERIN2 SI,BAUD,[STRINPUT]

SELECT CASE STRINPUT

CASE 78

                GOTO TENDIGIT

CASE 89

                GOSUB AREACODE

CASE ELSE

                GOTO GTNUM

END SELECT

 

'

' Build the telephone number (11-digit)

'

 

TELENUM[0]=49

FOR STRINPUT = 0 TO 2

TELENUM[STRINPUT+1] = STRARRAY[STRINPUT]

NEXT STRINPUT

GOSUB LOCAL

FOR STRINPUT = 0 TO 6

TELENUM[STRINPUT+4] = STRARRAY[STRINPUT]

NEXT STRINPUT

NUMSIZE = 10

GOTO DIAL

 

 

TENDIGIT:

SEROUT2 SO,BAUD,["Does the number need to be in 10-digit format(y/n)?",10,13,10,13]

SERIN2 SI,BAUD,[STRINPUT]

SELECT CASE STRINPUT

CASE 78

                GOTO SVNDIGIT

CASE 89

                GOSUB AREACODE

CASE ELSE

                GOTO GTNUM

END SELECT

 

'

' Build the telephone number (10-digit)

'

 

FOR STRINPUT = 0 TO 2

TELENUM[STRINPUT] = STRARRAY[STRINPUT]

NEXT STRINPUT

GOSUB LOCAL

FOR STRINPUT = 0 TO 6

TELENUM[STRINPUT+3] = STRARRAY[STRINPUT]

NEXT STRINPUT

NUMSIZE = 9

GOTO DIAL

 

'

' Build the telephone number (7-digit)

'

 

SVNDIGIT:

GOSUB LOCAL

FOR STRINPUT = 0 TO 6

TELENUM[STRINPUT] = STRARRAY[STRINPUT]

NEXT STRINPUT

NUMSIZE = 6

GOTO DIAL

 

AREACODE:

SEROUT2 SO,BAUD,["Enter the 3-digit area code",10,13,10,13]

SERIN2 SI,BAUD,[STR STRARRAY\3]

RETURN

 

 

LOCAL:

SEROUT2 SO,BAUD,["Enter the 7-digit telephone number",10,13,10,13]

SERIN2 SI,BAUD,[STR STRARRAY\7]

RETURN

 

DIAL:

SEROUT2 SO,BAUD,["Is the number below the correct number and in the correct format to dial (y/n)?"]

SEROUT2 SO,BAUD,[10,13,10,13]

FOR STRINPUT = 0 TO NUMSIZE

SEROUT2 SO,BAUD,[ TELENUM[STRINPUT] ]

NEXT STRINPUT

SEROUT2 SO,BAUD,[" ",10,13,10,13]

SERIN2 SI,BAUD,[STRINPUT]

SELECT CASE STRINPUT

CASE 78

                GOTO GTNUM

CASE 89

                GOTO SEND

CASE ELSE

                GOTO DIAL

END SELECT

 

SEND:

SEROUT2 SO,BAUD,["The PicStic 5 will dial the number that was provided using the following AT SEROUT2 SO,BAUD,[“Command",10,13]

SEROUT2 SO,BAUD,["ATD + the number provided",10,13,10,13]

 

'

' Send the command to the modem and receive acknowledgement

'

 

HSEROUT ["ATD"]

FOR STRINPUT = 0 TO NUMSIZE

HSEROUT [TELENUM[STRINPUT] ]

NEXT STRINPUT

HSERIN [DEC STRINPUT]

SELECT CASE STRINPUT

CASE 3

                GOSUB NOCARR

                GOTO GTNUM

CASE 4

                GOSUB ERR

                GOTO GTNUM

CASE 6

                GOSUB NODIALT

                GOTO GTNUM

CASE 7

                GOSUB BUSY

                GOTO GTNUM

CASE 8

                GOSUB NOANSW

                GOTO GTNUM

END SELECT

 

SEROUT2 SO,BAUD,["A connection was established. Now try to receive a call.",10,13]

GOSUB FIN

GOTO MENU

 

 

 

               

RVCALL:

'

' Connect the modem          

'

 

GOSUB INITALZ

 

'

' Set modem to answer after 3 rings

'

 

THREERING:

SEROUT2 SO,BAUD,["The PicStic 5 will now set the modem to answer after 3 rings",10,13]

SEROUT2 SO,BAUD,["This is done by sending the following AT Command",10,13,10,13]

SEROUT2 SO,BAUD,["ATS0=3",10,13,10,13]

 

'

' Send the command to the modem and receive acknowledgement

'

 

HSEROUT ["ATS0=3",10,13]

HSERIN [ STRINPUT]

IF STRINPUT<>48 THEN

                SEROUT2 SO,BAUD,["An error has occurred, press ENTER",10,13,10,13]

                SERIN2 SI,BAUD,[ STRINPUT ]

                GOTO THREERING

ENDIF

 

'

' Wait for incoming call

'

INCOMING:

SEROUT2 SO,BAUD,["When called, the modem will transmit '2'(short-form for RING) to the ",10,13]

SEROUT2 SO,BAUD,["controller 3 times before answering. After the modems answers, there ",10,13]

SEROUT2 SO,BAUD,["will be a 10 to 20 sec delay while a connection is established.",10,13,10,13]

SEROUT2 SO,BAUD,["Dial the modem now.",10,13]

NUMSIZE = 0                       'Set counter to zero

 

RWAIT:

HSERIN [STRINPUT]

SELECT CASE STRINPUT

CASE 50

                GOTO RINGCNT

CASE 51

                GOSUB NOCARR

                GOTO INCOMING

CASE 52

                GOSUB ERR

                GOTO INCOMING

CASE ELSE

                GOTO RWAIT

END SELECT

 

RINGCNT:

NUMSIZE = NUMSIZE + 1

IF NUMSIZE = 3 THEN

                SEROUT2 SO,BAUD,[" ",10,13]

                GOTO RECCALL

ELSE

                SEROUT2 SO,BAUD,["Ring number " , NUMSIZE , "has occurred",10,13]

                GOTO RWAIT

ENDIF

 

RECCALL:

SEROUT2 SO,BAUD,["A connection was established. Now try to make a call.",10,13]

GOSUB FIN

GOTO MENU

 

 

'

'

' SHARED ROUTINES

'

'

 

 

 

 

FIN:

SEROUT2 SO,BAUD,["The escape command will be sent to break the connection.",10,13]

SEROUT2 SO,BAUD,["Then the hang-up command will be issued.",10,13]

SEROUT2 SO,BAUD,["By default the escape command is '+++'.",10,13]

SEROUT2 SO,BAUD,["The hang-up command is ATH",10,13,10,13]

 

HSEROUT ["+++",10,13]

HSERIN [ STRARRAY[0] ]

HSEROUT ["ATH",10,13]

HSERIN [ STRARRAY[1] ]

 

SEROUT2 SO,BAUD,["Press any key to continue"]

SERIN2 SI,BAUD,[STRINPUT]

FOR STRINPUT =0 TO 40

SEROUT2 SO,BAUD,[" ",10,13]

NEXT STRINPUT

RETURN

 

INITALZ:

'

' Connect the modem          

'

 

SEROUT2 SO,BAUD,["Make sure all connections to the modem are correct",10,13]

SEROUT2 SO,BAUD,["Apply power to modem then press ENTER",10,13,10,13]

SERIN2 SI,BAUD,[ STRINPUT ]

 

'

' ECHO OFF

'

 

RETRY:

SEROUT2 SO,BAUD,["The PicStic 5 will now disable the ECHO on the modem",10,13]

SEROUT2 SO,BAUD,["This is done by sending the following AT Command",10,13,10,13]

SEROUT2 SO,BAUD,["ATE0",10,13,10,13]

 

 

'

' Send the command to the modem and receive acknowledgement

'

 

HSEROUT ["ATE0",10,13]

HSERIN [STR STRARRAY\2]

IF (STRARRAY[0]<>111) OR (STRARRAY[1]<>107) THEN

                SEROUT2 SO,BAUD,["Verify that the connections to the modem are correct and press ENTER",10,13,10,13]

                SERIN2 SI,BAUD,[ STRINPUT ]

                GOTO RETRY

ENDIF

 

'

' Enable short-form

'

SHRTFRM:

SEROUT2 SO,BAUD,["The PicStic 5 will now enable short-form response on the modem",10,13]

SEROUT2 SO,BAUD,["This is done by sending the following AT Command",10,13,10,13]

SEROUT2 SO,BAUD,["ATV0",10,13,10,13]

 

'

' Send the command to the modem and receive acknowledgement

'

 

HSEROUT ["ATV0",10,13]

HSERIN [ STRINPUT]

IF STRINPUT<>48 THEN

                SEROUT2 SO,BAUD,["An error has occurred, press ENTER",10,13,10,13]

                SERIN2 SI,BAUD,[ STRINPUT ]

                GOTO SHRTFRM

ENDIF

RETURN

 

NOCARR:

SEROUT2 SO,BAUD,["A NO CARRIER error has been generated. Verify connections and retry.",10,13]

SEROUT2 SO,BAUD,["Press any key to continue",10,13,10,13]

SERIN2 SI,BAUD,[STRINPUT]

RETURN

 

ERR:

SEROUT2 SO,BAUD,["An ERROR has been generated. Verify connections and retry.",10,13]

SEROUT2 SO,BAUD,["Press any key to continue",10,13,10,13]

SERIN2 SI,BAUD,[STRINPUT]

RETURN

 

NODIALT:

SEROUT2 SO,BAUD,["A NO DIAL TONE error has been generated. Verify connections and retry.",10,13]

SEROUT2 SO,BAUD,["Press any key to continue",10,13,10,13]

SERIN2 SI,BAUD,[STRINPUT]

RETURN

 

BUSY:

SEROUT2 SO,BAUD,["The number dialed is busy wait 10 seconds and retry.",10,13]

SEROUT2 SO,BAUD,["Press any key to continue",10,13,10,13]

SERIN2 SI,BAUD,[STRINPUT]

FOR STRINPUT = 10 TO 1 STEP -1

SEROUT2 SO,BAUD,[STRINPUT]

PAUSE 990

SEROUT2 SO,BAUD,[" ",8,8]

NEXT STRINPUT

RETURN

 

NOANSW:

SEROUT2 SO,BAUD,["There was no answer at the number dialed. Lets try again.",10,13]

SEROUT2 SO,BAUD,["Press any key to continue",10,13,10,13]

SERIN2 SI,BAUD,[STRINPUT]

RETURN

 

END