Shop OBEX P1 Docs P2 Docs Learn Events
Can u help me see what is wrong in this code? — Parallax Forums

Can u help me see what is wrong in this code?

ice-egozice-egoz Posts: 55
edited 2004-08-17 03:11 in BASIC Stamp
The AT commands to read SMS keep repeating. How do i download the program to the BS2p if there is a serin which I believe does not allow the downloading?

thruModem CON 14
toModem CON 15
flowControl CON 13
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Constants''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Baud CON 16624 '8-bit, no-parity, inverted
pauses CON 2000
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Variables''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
serData VAR Byte(9)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
GOTO readSMS
readSMS:····· 'Read Message
SEROUT toModem, Baud, [noparse][[/noparse]"AT+CMGR=1",CR,LF]··· 'Read Message = "Shut Down" ' this keeps repeating
DEBUG "AT+CMGR=1"
PAUSE 2000
GOTO a
'SEROUT toModem, Baud, [noparse][[/noparse]CR,LF]
'DEBUG CR,LF
a:
SERIN thruModem\flowControl, Baud,Bad_Data,10000,readSMS, [noparse][[/noparse]WAIT("Shut d"), STR serData\8]·· 'the data is saved in serData as WORD
DEBUG "serData"
GOTO b
Bad_Data:
DEBUG "Parity error",CR,LF
b:
SEROUT toModem, Baud, [noparse][[/noparse]"AT+CMGD=1",CR,LF]···· 'delete message after getting in the data
DEBUG "AT+CMGD=1"
'SEROUT toModem, Baud, [noparse][[/noparse]CR,LF]
'DEBUG CR,LF
GOTO checking

''''''''''''''''''''''''''''''''something--> Data'''''''''''''''''''''''''''''''''''''''''''''''''''''''
checking:
'IF (serData = true ) THEN shutDown
·GOTO shutDown
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
shutDown:············ ' Off the Alarm
'sirenPin LOW··········· ' Put Siren to LOW/%00
·GOTO secMessage····· ' Go to reply owner 2nd time

secMessage:············· '2nd msg to owner informing about succesful switching off the alarm
· SEROUT toModem, baud, [noparse][[/noparse]"AT"]
· DEBUG "AT"
· SEROUT toModem, baud, [noparse][[/noparse]CR,LF]
· DEBUG CR,LF
· PAUSE pauses

· SEROUT toModem, baud, [noparse][[/noparse]"AT+CMGF=1"]·········· 'Assign Text Mode
· DEBUG "AT+CMGF=1"
· SEROUT toModem, baud, [noparse][[/noparse]CR,LF]
· DEBUG CR,LF···················· ' Carraige Return ot 'Enter'
· PAUSE pauses
· 'AT+CMGS=90225042[noparse][[/noparse]ENTER]
· SEROUT toModem, baud, [noparse][[/noparse]"AT+CMGS"]············ 'Send 2nd Message to Owner
· DEBUG "AT+CMGS"
· SEROUT toModem, baud, [noparse][[/noparse]61]
· DEBUG 61····································· 'ASCII Equivalent for =
· SEROUT toModem, baud, [noparse][[/noparse]"90225042"]············ 'Liling's number
· DEBUG "91918287"······························ 'dest(Liling) mobile no
· SEROUT toModem, baud, [noparse][[/noparse]CR,LF]
· DEBUG CR,LF
· PAUSE pauses
· '>MSG^Z
· SEROUT toModem, baud, [noparse][[/noparse]"Alarm Off Successful"]·········· 'MSG Successful.
· DEBUG "Alarm off Successful"···························· 'msg
· SEROUT toModem, baud, [noparse][[/noparse]26]
· DEBUG 26
· PAUSE pauses

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I need all ya guidance Masters. [noparse]:)[/noparse]

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-16 00:57
    There SERIN is not interfering with the download process. So long as you're using a standard programming connection (the ATN line of the BASIC Stamp must be connected to the DTR pin of the serial port; typically through a 0.1 uF cap), the compiler can reset the BASIC Stamp and reprogram it -- no matter what the BASIC Stamp is doing at that moment. If you've built a cable that disconnects the ATN line, you are preventing the compiler from resetting the BASIC Stamp.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 8/16/2004 1:19:11 AM GMT
    599 x 555 - 16K
  • ice-egozice-egoz Posts: 55
    edited 2004-08-16 02:07
    Hi I'm like very blur in this cabling. The ATN on the demo board? Im not using sout or sin.Im using normal pins on the demo board for transmitting and receiving.
    Pin 15 to modem pin 2, Pin 14 to modem pin 3, pin 13 to modem pin4(dtr)and VSS to modem pin 5.

    The 4 wires are going to the bread board. The serial port of BS2p will be used to download the program to it.
    How do i attach the ATN from the breadboard to the modem DTR which i have already reserve it for serin for flow control.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I need all ya guidance Masters. [noparse]:)[/noparse]

    Post Edited (ice-egoz) : 8/16/2004 3:04:06 AM GMT
    640 x 480 - 124K
  • dlborgmandlborgman Posts: 11
    edited 2004-08-16 16:37
    It appears you may already know that the stamp program can only be loaded
    thru the serin/serout pins using the standard stamp to PC cable.

    You send an "AT" command to the modem, but pause 2000 (2 seconds) before
    you go read the reply. The stamp family has no means to buffer serial input
    data, so by the time you go to read the reply, the data has come and gone.

    Try removing the 2 second pause between the send to modem and the recieve
    from modem.

    hope this helps,
    Dennis
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-16 17:48
    ice-egoz said...


    The 4 wires are going to the bread board. The serial port of BS2p will be used to download the program to it.
    How do i attach the ATN from the breadboard to the modem DTR which i have already reserve it for serin for flow control.
    You don't -- I was referring to the PC's DTR which is used to reset the BASIC Stamp before programming.· Since you're using a BS2p demo board, you should never have any problems programming your BASIC Stamp, no matter what your code is doing ... unless your PC has a faulty serial port.

    My best suggestion, as your code is getting a bit convoluted, is to remove everything (via comments), and start to add things back in, testing as you go.·


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • ice-egozice-egoz Posts: 55
    edited 2004-08-17 03:11
    Hi there. The error was that I had fixed the wiring wrongly. Anyway, the problem now is that it doesn't check for the data in the sms. serData shud store the "Shut down" ryte? It just shows parity error and just sends an sms when it shud send an sms only when it receives "Shut down".
    My code:

    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}

    toModem CON 15
    thruMOdem CON 14
    flowControl CON 13

    baud CON 16624

    serData VAR Byte(9)


    GOSUB readSMS
    GOSUB seeData
    'GOSUB checking
    'GOSUB shutDown
    'GOSUB secMessage ' Go to reply owner 2nd time



    readSMS:
    SEROUT toModem, baud, [noparse][[/noparse]"AT"]
    DEBUG "AT"

    SEROUT toModem,baud, [noparse][[/noparse]CR,LF]
    DEBUG CR,LF
    PAUSE 2000

    'Making sure that the GSM module is in text mode.
    SEROUT toModem, baud, [noparse][[/noparse]"AT+CMGF"]
    DEBUG "AT+CMGF"

    SEROUT toModem, baud, [noparse][[/noparse]61]
    DEBUG 61 'ASCII Equivalent for =

    SEROUT toModem, baud, [noparse][[/noparse]"1"]
    DEBUG "1"

    SEROUT toModem, baud, [noparse][[/noparse]CR,LF]
    DEBUG CR,LF ' Carraige Return ot 'Enter'
    PAUSE 1000

    SEROUT toModem,baud, [noparse][[/noparse]"AT+CMGR"]
    DEBUG "AT+CMGR"

    SEROUT toModem, baud, [noparse][[/noparse]61]
    DEBUG 61

    SEROUT toModem, baud, [noparse][[/noparse]"1"]
    DEBUG "1"

    SEROUT toModem, baud, [noparse][[/noparse]CR,LF]
    DEBUG CR,LF
    'PAUSE 200





    seeData:
    'SERIN thruModem, baud, [noparse][[/noparse]STR serData\8]
    'SERIN thruModem, baud, [noparse][[/noparse]WAIT("Shut d"), STR serData\8]
    'SERIN thruModem\flowControl,baud,Bad_Data,25000,readSMS, [noparse][[/noparse]WAIT("Shut d"), STR serData\8] 'the data is saved in serData as WORD
    SERIN thruModem,baud,Bad_Data,25000,readSMS, [noparse][[/noparse]WAIT("Shut d"), STR serData\8] 'the data is saved in serData as WORD
    DEBUG serData

    Bad_Data:
    DEBUG "Parity error"
    GOTO checking





    'SEROUT toModem, baud, [noparse][[/noparse]"AT+CMGD=1"] 'delete message after getting in the data
    'DEBUG "AT+CMGD=1"
    'SEROUT toModem, baud, [noparse][[/noparse]CR,LF]
    'DEBUG CR,LF



    checking:
    'IF (serData = true ) THEN shutDown
    GOTO shutDown

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

    shutDown: ' Off the Alarm
    'sirenPin LOW ' Put Siren to LOW/%00
    GOTO secMessage



    secMessage: '2nd msg to owner informing about succesful switching off the alarm
    SEROUT toModem, baud, [noparse][[/noparse]"AT"]
    DEBUG "AT"

    SEROUT toModem, baud, [noparse][[/noparse]CR,LF]
    DEBUG CR,LF
    PAUSE 2000


    SEROUT toModem, baud, [noparse][[/noparse]"AT+CMGF=1"] 'Assign Text Mode
    DEBUG "AT+CMGF=1"

    SEROUT toModem, baud, [noparse][[/noparse]CR,LF]
    DEBUG CR,LF ' Carraige Return ot 'Enter'
    PAUSE 2000

    'AT+CMGS=90225042[noparse][[/noparse]ENTER]
    SEROUT toModem, baud, [noparse][[/noparse]"AT+CMGS"] 'Send 2nd Message to Owner
    DEBUG "AT+CMGS"

    SEROUT toModem, baud, [noparse][[/noparse]61]
    DEBUG 61 'ASCII Equivalent for =

    SEROUT toModem, baud, [noparse][[/noparse]"90225042"] 'Liling's number
    DEBUG "90225042" 'dest(Liling) mobile no

    SEROUT toModem, baud, [noparse][[/noparse]CR,LF]
    DEBUG CR,LF
    PAUSE 2000

    '>MSG^Z
    SEROUT toModem, baud, [noparse][[/noparse]"Alarm Off Successful"] 'MSG Successful.
    DEBUG "Alarm off Successful" 'msg
    SEROUT toModem, baud, [noparse][[/noparse]26]
    DEBUG 26
    PAUSE 2000

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I need all ya guidance Masters. [noparse]:)[/noparse]
Sign In or Register to comment.