Pic to GSM Phone connection (HSerin problems)


Closed Thread
Results 1 to 40 of 289

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Stuttgart, Germany
    Posts
    24

    Default

    Discovered strange thing. Works with S55. If i connect Tx line from the phone trough 1k resistor to one of the ports, serin2 will hang, waiting for an answer on that port. But when i quickly shorten this serin2 port to the ground, it starts working! And then hangs until the next command, then i short it and after it goes without problem to the end of the program. This trick does not work with HSERIN or SERIN. And only sometimes works with S65 phone.
    With max232 doesnt work anyways.

    Any ideas??



    Here is my code:


    DEFINE LOADER_USED 1

    'UART hardware defines
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLROERR 1


    'LCD defines
    DEFINE LCD_DREG PORTA 'set LCD data port
    DEFINE LCD_DBIT 0 'set starting data bit (0 or 4) if 4 bit bus
    DEFINE LCD_RSREG PORTA 'set LCD register select port
    DEFINE LCD_RSBIT 4 'set LCD register select bit
    DEFINE LCD_EREG PORTB 'set LCD enable port
    DEFINE LCD_EBIT 3 'set LCD enable bit
    DEFINE LCD_BITS 4 'set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 'set number of LCD lines
    DEFINE LCD_COMMANDUS 2000 'set command delay time in us
    DEFINE LCD_DATAUS 50 'set data delay time in us
    DEFINE OSC 20 'set crystal speed



    b0 var byte
    include "modedefs.bas"



    'Main program


    pause 1000 'wait for screen to sort get started

    lcdout $FE,1, "Sending AT.."
    pause 2000
    HSEROUT ["AT", 13]
    pause 500
    HSEROUT ["ATE0", 13]
    serin2 portc.4, 84, [str b0\10]
    lcdout $FE, $C0, str b0\10
    pause 3000

    b0=0
    lcdout $FE,1, "Asking model.."
    pause 2000
    HSEROUT ["at+cgmm", 13]
    serin2 portc.4, 84, [SKIP 2, str b0\20]
    lcdout $FE, $C0, str b0\20
    pause 5000

    b0=0
    lcdout $FE,1,"Asking IMEI.."
    pause 2000
    Hserout ["at+cgsn", 13]
    serin2 portc.4, 84, [SKIP 2, str b0\20]
    lcdout $FE, $C0, str b0\20
    pause 5000

    b0=0
    lcdout $FE,1,"Asking capabilities:"
    pause 2000
    Hserout ["at+gcap", 13]
    serin2 portc.4, 84, [SKIP 2, str b0\20]
    lcdout $FE, $C0, str b0\20
    pause 5000


    b0=0
    lcdout $FE,1,"Asking time.."
    pause 2000
    Hserout ["at+cclk?", 13]
    serin2 portc.4, 84, [SKIP 2, str b0\20]
    lcdout $FE, $C0, str b0\20
    end

  2. #2
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762

    Default

    Rufinus,
    I hate to say that, but you have got to do some homework.

    Make yourself familiar with the principles of serial communitation and the datasheet of a MAX232.

    Pay special attention on the MODES, (TRUE/INVERTED)

    If you receiver is expecting the data line to be ILDE HIGH and your transmitter IDLES LOW, (and vice versa) you will see all kinds of strange phenomenon.

    You are not really connecting one of the RS232 Outputs of the MAX to the phone or PIC, are you?
    (you are about to kill the PIC and/or the Mobile)
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  3. #3
    Join Date
    Oct 2005
    Location
    Stuttgart, Germany
    Posts
    24

    Default

    RS232 output of max i do connect to the pic, but through 22k resistor.
    Pic to phone both ways goes through 1k resistor.
    There is no reason to connect rs232 straight to phone anyways, so i dont and would not. There is no problem now with the phone receiving commands. The problem is to receive answers on pic.

    Regarding modes - tried both true and inverted, tried different baud rates.

    Now it is connected to the pic without MAX. I still think it is the problem of levels.

    If you have a good link in mind about serial communication, i would appreciate. Otherwise, gonna google.

    Thanks for adwise anyways.
    Last edited by Rufinus; - 17th October 2005 at 21:50.

  4. #4
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762

    Default

    Quote Originally Posted by Rufinus
    RS232 output of max i do connect to the pic, but through 22k resistor.
    A simple NPN Transistor and two resistors would do here.
    (Invert the logic and shift the level to 5V)

    Regarding modes - tried both true and inverted, tried different baud rates.
    I still think it is the problem of levels.
    Find out what level the Phones TX Pin has in Idle state, and what it is in active state.



    If you have a good link in mind about serial communication, i would appreciate. Otherwise, gonna google.
    Sorry, I don't have any link, but there are some good books, i.e.
    "Serial Port Complete" by: Jan Axelson
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  5. #5
    Join Date
    Oct 2005
    Location
    Stuttgart, Germany
    Posts
    24

    Default

    I should report now, that the problem is solved!!
    My thanks and respect goes to NavMicroSystems and Ioannis for helping me out.
    Problem was solved by making a simple level shifter (so i can use phone with USART), using two BC 547 transistors.

    Perhaps should make a simple conclusion, for those, who will work with Siemens S55/S65 phones.
    There is no need in MAX232. Rx line of the phone can be connected to the PIC through 1k resistor. Tx line of the phone must be connected through simple level shifter. Written above is valid for PICs with USART onboard.
    Pins 5 and 7 of the phone should be connected trough 10k resistors to pin 2.
    Otherwise the phone will not detect the cable and will not accept commands from the PIC.

    As a hint: if you dont have a spare connector for the phone, you can make one from AGP slot of the old PC motherboard, pin spacing is the same

    -----------------------------------------------------------------------
    And, of course, if you are not sure what are you doing, better dont do it!You can damage a lot of expensive things!
    -----------------------------------------------------------------------

    So now i will move on to next step - sending messages in PDU format.

  6. #6
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762

    Default

    Rufinus,

    I'm glad to hear you have got it to work!

    Why do you want to use PDU format, doesn't the S55 support TEXT?
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,184

    Default

    Ralph is right about the serial kwnoledge Rufinus. I was about to say almost the same things. If you don't own the Serial Complete, do so as soon as possible. It will help you the most.

    Now, about your phone, it is sure a problem of levels, no question about it. It is just that we cannot guess anything. You have to find data sheets and read them from A to Z. Then you sure find why it behaves like the way you describe.

    Regards,
    Ioannis

  8. #8
    Join Date
    Oct 2005
    Location
    Stuttgart, Germany
    Posts
    24

    Default

    Well, S55/S65 suports only PDU, unfortunately


    I will get the book, because this is not my last project related to this matter.

    Regarding datasheets. It is quite a tricky one, to find a complete datasheet for the phone. Even service manual i managed to find in internet, has the stamp on it: "For internal use only". So it is pretty much of poking and trying here and there, or call it guessing, if you will. And if the models of the phone are relatively new..

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,184

    Default

    OK. PDU is one thing. Some phone do support ASCII some do not.
    That's why I choose modules like Telit or Wavecom for serious projects or Nokia for experimenting.

    But EVERY phone should answer 'OK' if addressed by 'AT'.

    Ioannis

  10. #10
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762

    Default

    Ioannis is right.

    There are two GSM-Terminals I can recommend:

    SIEMENS TC35i Terminal

    and the Telit Terminal Ioannis has already mentioned.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  11. #11
    Russell's Avatar
    Russell Guest

    Unhappy Please help

    i need a circuit diagram showing the connection between rs232 and pic16f84 for sending and receiving sms. ofcourse the phone is nokia.(AT supported). i am in desperate need of it.
    thanks.

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,184

    Default

    Have you ever used MAX232? (do a search on the forum and you will find a lot)

    Have you an RS-232 cable for your Nokia Model?

    Have you read the relevant AT commands for controlling you phone first through Windows terminal so to get familiar with the commands?

    All these are necessary...

    Ioannis

  13. #13
    rexilen's Avatar
    rexilen Guest

    Unhappy Need Help

    i used pic16f873..nokia modem n30..lcd 2x16..3 sensors which give an input to pic +5V. this 3 sensor connected to portA from portA 0-2.rx and tx connected to max232 and used 4.5Mhz Crystal with 33pF capacitor. the LCD pins which are E connected to RB0, RS to RB3, DB4 to RB4, DB5 to RB5, DB6 to RB6, and DB7 to RB7.
    well..my project do like this..if sensor 1,2,and 3 detect it will give an input to pic and LCD will diplay a message and nokia modem will send sms text message to specific phone number. well below is my program and it didnt work..the LCD didnt display anything and the modem didnt send any message.someone please help which part is wrong..

    Pause 1000
    DEFINE LCD_DREG PORTB 'Define PIC port used for LCD data line
    DEFINE LCD_DBIT 4 'Define first pin of portC connected to LCD DB4
    DEFINE LCD_RESREG PORTB 'Define PIC port used for RS line of LCD
    DEFINE LCD_RSBIT 3 'Define PortC pin used for RS connection
    DEFINE LCD_EREG PORTB 'Define PIC prot used for E line of LCD
    DEFINE LCD_EBIT 0 'define the 3 bit communication
    DEFINE LCD_LINES 2 'Define using a 2 line LCD
    DEFINE LCD_COMMANDUS 2000 'define delay between sending LCD commands
    DEFINE LCD_DATAUS 50 'Define delay time between data sent

    DEFINE OSC 4

    DEFINE HSER_TXSTA 20h
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLROERR 1

    GSMBUFFER VAR BYTE[16]
    Caller VAR BYTE[13]
    GSMTime VAR BYTE[17]

    Init:

    trisa = %11111111 'set portA-RA1 input
    porta = %00000000 'set portA high to give an input sensor


    SEN1 :
    if portA.0 = 0 then SEN2 'If sensor 1 dont detect then jump to SEN2
    if portA.0 = 1 then LCD1 'Sensor at level1 detect then go to LCD 1
    goto SEN1

    SEN2 :
    if portA.1 = 0 then SEN3 'If sensor 2 dont detect then jump to SEN3
    if portA.1 = 1 then LCD2 'Sensor at level2 detect then go to LCD2
    goto SEN1

    SEN3 :
    if portA.2 = 0 then SEN1 'If sensor 3 dont detect then jump to SEN1
    if portA.2 = 1 then LCD3 'Sensor at level3 detect then go LCD3
    goto SEN1

    LCD1:

    LCDOut$fe,1 'Clear LCD
    LCDOut$fe,2 'Position cursor at home

    LCDOut "LEVEL 1 HAZARD"
    Pause 1000
    Goto SEND1

    lcd2:

    LCDOut$fe,1 'Clear LCD
    LCDOut$fe,2 'Position cursor at home

    LCDOut "lEVEL 2 HAZARD"
    Pause 1000
    Goto SEND2

    LCD3:
    LCDOut$fe,1 'Clear LCD
    LCDOut$fe,2 'Position cursor at home

    LCDoUT "lEVEL 3 HAZARD"
    Pause 1000
    Goto SEND3

    SEND1:
    'Send SMS Test-Message LEVEL 1
    HSerout ["ATZ",13,10]
    Pause 1000

    HSerout ["AT+CMGF=1",13,10] 'Set Text Mode
    Pause 500

    HSerout ["AT+CMGS=",34,"+01234567890",34,",129",13,10]
    Pause 500

    HSerout ["LEVEL 1 HAZARD",10,13]
    HSerout [26]
    Pause 1000
    goto SEN1

    SEND2:
    'Send SMS Test-Message LEVEL 2
    HSerout ["ATZ",13,10]
    Pause 1000

    HSerout ["AT+CMGF=1",13,10] 'Set Text Mode
    Pause 500

    HSerout ["AT+CMGS=",34,"+01234567890",34,",129",13,10]
    Pause 500

    HSerout ["LEVEL 2 HAZARD",10,13]
    HSerout [26]
    Pause 500
    goto SEN1

    SEND3:
    'Send SMS Test-Message LEVEL 3
    HSerout ["ATZ",13,10]
    Pause 1000

    HSerout ["AT+CMGF=1",13,10] 'Set Text Mode
    Pause 500

    HSerout ["AT+CMGS=",34,"+01234567890",34,",129",13,10]
    Pause 500

    HSerout ["LEVEL 3 HAZARD",10,13]
    HSerout [26]
    Pause 1000
    goto SEN1

    Please someone took a look which part is wrong..

  14. #14
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,184

    Default

    For starters I would suggest to use crystal at 8MHz or better at 16MHz EXACTLY. Not 4.5 or other. May be 4MHz would work, but don't recommend it. Too slow. It is important to have correct frequency, otherwise the UART will be out of sync.

    Then use these Defines

    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h '9600 baud rate, BRGH=1
    DEFINE HSER_BAUD 9600
    DEFINE HSER_SPBRG 129
    DEFINE HSER_CLROERR 1

    DEFINE OSC 8 'or 16

    What are you trying to do here?

    this makes the A port input :trisa = %11111111 'set portA-RA1 input
    and this makes the port output (?): porta = %00000000 'set portA high to give an input sensor

    Then I see at your code that you send a ATZ to the mobile. Have you checked how long does it take for a mobile to RESET? I found that the Wavecom needs about 17 seconds for the GSM engine to be accessible. In the meantime the AT commands are working OK!!!

    First you have to check if the mobile is responding with its name like this:

    HSerout ["AT+CGMI",13] 'Get Manufacturer ID
    Hserin 1500,err1,[wait("WAV")] 'Wait for Wavecom Module <<<--- Put here the name of your modem!!!
    lcdout com,line1,"Module found!"

    One trick to succesfully realize that you can send SMS is to check if at the command AT+CMGF=1 the device responds with OK like this:

    HSerout ["AT+CMGF=1",13] 'Text SMS mode
    HSerin 5000,error,[wait("OK")]

    The devices have different respond times for different commands.

    You have to check with a terminal programm like Hyperterminal sending AT+ commands. Also always wait for a response from the mobile. Either OK or another character.

    Ioannis

Similar Threads

  1. Serial VB 2005 pic 16f877a problems
    By Snap in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 8th July 2013, 00:52
  2. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 14:46
  3. problem with the GSM controller
    By Dariolo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th May 2009, 20:33
  4. Automatic VB6 to pic serial connection
    By arniepj in forum Code Examples
    Replies: 13
    Last Post: - 10th January 2008, 07:57
  5. Pic to GSM Phone connection
    By samertop in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th July 2005, 13:40

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts