AN #31 - Sending SMS using Siemens GSM C35i
Information about PDU formated SMS: http://www.dreamfabric.com/sms/
Equipment on which programs were tested:
- Bascom test board
- LCD 2x16
- crystal 22118400 Hz
- Siemens GSM C35i data cable for RS232 connection
- BASCOM-8051 Version 2.0.8.0
Download source code in an31.zip
You do not need much to send simple message. You also do not need to know everything, what PDU is capable to do. When my message is gone successfully, I stopped to analyze PDU format.
The result is here, a quick and dirty way to send a SMS from uP with my BASCOM-8051.
The telephone number and the message text are in program ROM at the end of the program, these are constants and we have to save as much RAM as possible.
For preprocess we need to know the length of the number, how many characters it contains. And the same we need to know for the message text itself. When we have this data, we are able to calculate the length of the command itself. We need it to inform the C35i in AT+CMGS= statement.
Then the PDU formated message follows, beginning with prefix Print "000100"; (do not forget semicolon! If so, then Print statement of Bascom adds two characters, carriage return character and new line character, which is here not in place. It wouldn't work.)
What these three bytes of message command mean, i don't know. I just recall, that first x00 byte says, we are sending message via SMS Service Center, whose telephone number is already in the memory of C35i, so we do not need to specify it.
Then the recipients telephone number follows, a little modified. First the length of this number in figures, (386 41 123456 has 11 figures, so x0B is 11), next byte x91 means, the number itself is in international form and begins with country code - (Slovenia - 386)
The no 38641123456 should result into
8346113254F6
each figure into halfbyte, and if the number of figures is odd, then the least significant number is followed by F.
This conversion is made by special routine in the program, which also contains Print statements.
The Print statement for some attributes follows. x0000 does fine.
At last message text follows. While ASCII character occupy only the values under 128, they need only 7 bits of information. So some compress is done this way, that 8 characters are send in 7 bytes, where all bits are significant. How it has to be done, you can read on the web site I already mentioned. This work is done by the bascom statements following the statement
Printhex Dolzspor; They also contain the necessary Print statements.
We end with Print char(26) ;
which is the
ctrl-z character to end the command.
Why to process on and on the same data, to get on and on the same result? We process it once on the Bascom simulator, we catch the result and then we put it in the appropriate Print statements of the new program. C35i would not mind.
Well both these two samples don't bother, is C35i happy with our commands or not. Both programs do not read the C35i answers.
Well, i did not succeed to catch the answers with bascom Input commands. It may be so, I do not master bascom enough.
Well i wrote for this purpose a Serial Interrupt routine, which catches each character from RS232 and put it on the end of the XX1(1) to XX1(16) big character area, well it first moves all characters for one byte to the left, and puts the newly read character at the end. Serial interrupt routine does no more than this. So i always have in XX1 area the last 16 characters from RS232.
With the help of second subroutine Prikazi (it means Show me! ) i get the last 16 characters on the first line of 2x16 LCD, and the last 8 bytes of it in second line of LCD in hexa format. The call of subroutine Prikazi is followed by wait statement, so the LCD can be visually checked.
Well nothing is so complicated at it seems, but more. So Serial Interrupt routine is not coexistent with print statements, so I always disabled serial interrupt before print statement and enabled after like this:
Enable Serial
Disable Serial
Set Scon.1
Print "AT+CMGS=" ; Dolztele
Reset Scon.1
Enable Serial
All three programs are written as main programs, but you will make subroutines out of it and you will call them from your main program when needed .