' ============================================================================== ' ' File...... GSMModemTest.BSP ' Purpose... Send a SMS from Stamp using Nokia ' mobile phone ' ' ' {$STAMP BS2p} '{$PBASIC 2.5} ' ' ============================================================================== ' ------------------------------------------------------------------------------ ' Program Description ' ------------------------------------------------------------------------------ ' Send a text message from the BS2p using a Nokia 6310i ' with DLR-3 serial adapter cable ' ------------------------------------------------------------------------------ ' Revision History ' ------------------------------------------------------------------------------ ' ------------------------------------------------------------------------------ ' I/O Definitions ' ------------------------------------------------------------------------------ RX CON 12 ' receive (from modem) TX CON 13 ' transmit (to modem) RTS CON 14 ' Request To Send (from modem) CTS CON 15 ' Clear To Send (to modem) ' ------------------------------------------------------------------------------ ' Constants ' ------------------------------------------------------------------------------ Baud CON 240 ' 9600-N-8-1 ControlZ CON 26 ' Escape character ' ------------------------------------------------------------------------------ ' Variables ' ------------------------------------------------------------------------------ ' ------------------------------------------------------------------------------ ' EEPROM Data ' ------------------------------------------------------------------------------ ' ------------------------------------------------------------------------------ ' Initialization ' ------------------------------------------------------------------------------ HIGH CTS ' not ready to receive yet ' ------------------------------------------------------------------------------ ' Program Code ' ------------------------------------------------------------------------------ Main: GOSUB SendText STOP ' ------------------------------------------------------------------------------ ' Subroutines ' ------------------------------------------------------------------------------ SendText: DEBUG "Initialise modem!",CR,LF ' For PC display PAUSE 2000 ' Wait for modem to power up SEROUT TX, Baud, ["AT",CR] ' send "Attention" command to modem DEBUG "Sent AT",CR,LF PAUSE 5000 ' Wait 5 seconds before looking for the "OK" reply SERIN RX\CTS, Baud, 50, RX_Error, [WAIT ("OK")] ' to test flow control DEBUG "Got OK from modem",CR,LF PAUSE 1000 DEBUG "Putting phone into text mode",CR,LF SEROUT TX, Baud, ["AT+CMGF=1",CR] SERIN RX\CTS, Baud, 50, RX_Error, [WAIT ("OK")] DEBUG "Got OK from modem",CR,LF PAUSE 2000 DEBUG "Setting receiving number",CR,LF SEROUT TX, Baud, ["AT+CMGS=",34,"+123456789",34,CR] PAUSE 2000 DEBUG "Should be at '>' now",CR,LF DEBUG "Writing message string",CR,LF SEROUT TX, Baud, [CR,"Testing from STAMP",CR,LF] PAUSE 2000 SEROUT TX, Baud, [ControlZ,CR] 'Send esc character DEBUG "sent ctrl-z",CR,LF SERIN RX\CTS, Baud, 50, RX_Error, [WAIT ("OK")] DEBUG "Got OK from modem",CR,LF PAUSE 1000 DEBUG "Should get text now!",CR,LF RETURN RX_Error: DEBUG "Modem Error",CR,LF STOP