Wavecom with 16F628 communication problem


Closed Thread
Results 1 to 4 of 4
  1. #1
    ericbeaugiuet's Avatar
    ericbeaugiuet Guest

    Default Wavecom with 16F628 communication problem

    Hello , i use a 16f628 with a wavecom modem and i must read sms messages with serin and the 4 Mhz internal oscillator. When i receive the sms , the pic must receive 4 caracters with this:
    SERIN RX,N9600,consigne,sms,ordre,valeur

    can you help me because it doesn't work correctly.

    Here is an extract of my program that use 4 output and 4 input

    Sorry for my english. I'm a french student.


    DEFINE OSC 4 ; utilisation de l'oscillateur à quartz 4 Mhz intégré

    INCLUDE "modedefs.bas"

    sms var byte ; octet de reception série
    sms2 VAR BYTE
    memo var byte
    i VAR BYTE ; variable de travail pour les boucles if
    ordre VAR BYTE ; type ordre demandé ? ou =
    valeur VAR BYTE ; état demandé d'une sortie relais
    relais VAR BYTE ; variable de masquage pour l'écriture sur les sorties TOR
    consigne VAR BYTE ; variable de valeur Q ou E pour entrée ou sortie
    alerte VAR BYTE ; variable désignant coupure edf = 2 ou sms mal tapé = 1
    nbrenum VAR BYTE ; si nbrenum = 1 then 1 seul numéro possible
    coupure VAR bit;indique si une détection de coupure edf a été traité par SMS
    venvoi VAR BYTE
    rw VAR byte ; indique si on veut accéder aux entrées ou aux sorties

    code VAR BYTE [4] ; code secret à 4 chiffres
    codeb VAR BYTE [4] ; code reçu
    phone_number VAR BYTE [11] ; numéro de téléphone en utilisation
    phone_numberb var BYTE [11] ; numéro de téléphone unique défini à la config
    TX VAR PORTB.7 ; envoie RS232 sur PORTB7
    RX VAR PORTB.6 ; réception RS232 sur PORTB.6

    debut var byte
    fin var byte

    initialisationa: ; programme d'initialisation au démarrage du pic
    PORTA = $00
    TRISA = %11110000 ; init des 4 sorties relais
    PORTB = %111111 ; 4 entrée TOR et 2 jumpers donc 6 entrée
    rw = 0
    WRITE 46,"="
    FOR i = 1 to 11 ; copie du numéro de téléphone en ram
    call lecture_eeprom
    phone_number[i] = valeur
    NEXT i
    FOR i = 12 to 15 ; copie du code secret en ram
    CALL lecture_eeprom
    code [i] = valeur
    NEXT i
    alerte = 0 ; initialisation des variables d'indication defaut
    if PORTA.4 = 1 then setup ; si jumper 1 placé sur on mode config
    pause 5000 ; on laisse le modem s'initialiser pendant 5 secondes
    PAUSE 10
    SEROUT TX,N9600,["AT+CPIN=3795",13] ; envoi du code pin
    SERIN RX,N9600,["OK"] ; attente de la réponse
    PAUSE 5000
    call purge
    goto reception_message

    main: ; sous programme pricipal
    If coupure = 0 then
    call test_perte_reseau ; test de présence EDF
    ENDIF
    IF coupure = 1 THEN
    CALL test_perte_reseau_retour
    ENDIF

    IF alerte > 0 then reponse ; si une alerte est apparu on envoi un sms
    PAUSE 3000
    attente_sms:
    SERIN RX,N9600,["+CMTI: ",$22,"SM",$22,","],memo
    SEROUT TX,N9600,["AT+CMGR=",memo,13]
    goto lecture


    retour:
    PAUSE 4000
    goto main
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; sous programmes de réception des sms
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    reception_message: ; on commence par lire les messages en mémoire
    SEROUT TX,N9600,["AT+CMGL=",$22,"REC UNREAD",$22,13] ;liste les messages stockés
    lecture:
    SERIN RX,N9600,5000,retour,[",",34,"+"] ;
    for i = 1 to 11
    SERIN RX,N9600,phone_numberb [i] ;on mémorise dans la ram le numéro de tel
    next i
    SERIN RX,N9600,5000,main,[13,10],codeb [1],codeb [2],codeb [3],codeb [4]; test du code secret à 4 chiffres
    SERIN RX,N9600,consigne,sms,ordre,valeur
    FOR i = 1 to 4 ; vérification des 4 chiffres du code secret
    if codeb [i] != code [i] then main
    NEXT i
    if PORTA.4 = 1 then lecture_suite ; test du cavalier num_unique
    FOR i = 1 to 11 ; vérification des 11 chiffres du numéro de tel
    IF phone_number[i] != phone_numberb[i] then main
    NEXT i ; Ce test est fait si on souhaite que la carte ne

    lecture_suite:
    if consigne = "q" then commande_relais ; test de l'orde demandée
    if consigne = "e" then lecture_entree_tor ; q pour les sortie et e pour les entrées

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    i must read sms messages with serin and the 4 Mhz internal oscillator. When i receive the sms , the pic must receive 4 caracters with this:
    SERIN RX,N9600,consigne,sms,ordre,valeur
    9600 baud with 4mhz internal crystal... no way... you need a faster crystal... 2400 baud is starting to push the limit. Sometimes if things are right, 4800.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Eric,
    As Dwayne said, 9600 baud @ 4MHZ is certainely not good.. even worst with the internal one AND by using SERIN. A better practice is to use the internal USART of your PIC and an external Crystal or ceramic resonator.

    PIC16F628 have an internal USART, look for HSERIN/HSEROUT

    Bonne chance et a bientot!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jun 2006
    Posts
    6


    Did you find this post helpful? Yes | No

    Thumbs up Code

    LEGGISMS:

    MESS=0
    HSEROUT ["AT+CMGL=",34,"ALL",34,13]
    hserin 800,EXITLEGGISMS,[SKIP 10, wait(34,",",34),TMP]
    MESS=1
    NUMERO[0]=TMP
    LUNGNUM=1
    while TMP<>34 AND LUNGNUM<20
    hserin 10000,EXITLEGGISMS,[TMP]
    NUMERO[LUNGNUM]=TMP
    LUNGNUM=LUNGNUM+1
    wend

    hserin 10000,EXITLEGGISMS2,[SKIP 5, WAIT(34),TMP,tmp]
    LUNGSMS=0
    while LUNGSMS<60
    hserin 10000,EXITLEGGISMS2,[TMP]
    D[LUNGSMS]=TMP
    LUNGSMS=LUNGSMS+1
    wend


    EXITLEGGISMS2:
    LUNGNUM=LUNGNUM-2

    LUNGSMS=LUNGSMS-1

    FOR TMP=0 TO 60
    IF D[TMP]=";" THEN
    TMP=TMP+1
    FOR TMP1=0 TO 4
    PWD[TMP1]=D[TMP+TMP1]
    NEXT TMP1
    TMP=61
    ENDIF
    NEXT TMP


    FOR TMP=0 TO 10
    toggle led
    pause 200
    NEXT TMP
    low led


    PAUSE 3000
    HSEROUT ["AT+CMGD=0,4",13] 'CANCELLO TUTTI I MESSAGGI
    HSERIN 10000,EXITLEGGISMS,[wait ("OK")]
    PAUSE 1000
    PAUSE 2000


    EXITLEGGISMS:
    RETURN

Similar Threads

  1. Strange problem with Serin/Serout on 16F628
    By Atom058 in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 22nd August 2008, 00:16
  2. Replies: 3
    Last Post: - 12th February 2007, 18:32
  3. Replies: 5
    Last Post: - 20th March 2006, 01:34
  4. Replies: 8
    Last Post: - 11th November 2004, 20:08
  5. 16F628 on-chip eeprom problem
    By atomski in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 4th March 2004, 07:43

Members who have read this thread : 2

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