Weird behaviour of SEROUT2


+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    77

    Default Weird behaviour of SEROUT2

    Hi to everyone. I'm experiencing a really weird behaviour of the SEROUT2 command.
    I'm using PIC18F4550 and it was originally connected to a GPRS Modem SIM908 and everything was working fine.
    Now, I've changed the modem to a newer SIM868 and then something weird start to happening.
    Before go on, I'll make clear that the hardware specifications are met, in terms of voltage levels on the communication pins.
    All the commands sent to the NEW modem (SIM868) are working as expected and also answers are as expected.
    Everything seems to working fine except when I try to send data to the GPRS newtork.
    I mean: even using the new modem, everythings works: modem configuration, connection to the GPRS, opening the HTTP session, but then when I try to send the relevant data I want to store, the command AT+HTTPPARA="URL", "http://somewhere:99/page.aspx?ev=blablablaDATA" fails reporting +CME ERROR Invalid Index.
    The URL portion is made reading chunks of data from EEPROM and send it immediately to the modem using the SEROUT2.
    This approach worked fine with the old modem.
    With the new modem, using the usual approach I've just described, it fails. What is really weird, is that if I collect all the chunks of data I need inside an array, mixing ARRAYWRITE and direct array filling and issuing EVERYTHING with a SINGLE SEROUT2 statement, then IT WORKS PERFECTLY even with the new modem!!!!
    Even more, looking at the data sent to the modem in both cases (multiple SEROUT2 statements VS single SEROUT2 statement using array) the data looks exactly the same!

    Time for some code.
    The following is the chunk of code that works with the OLD modem and do not work anymore with the new one:

    Code:
        serout2 TOGSM,84, ["AT+HTTPPARA=", 34,"URL",34, "," ,34, "http://"]
        
        serout2 TXPC,6,   ["AT+HTTPPARA=", 34,"URL",34, "," ,34, "http://"]  'JUST for DEBUG only
    
        for j = 0 to 30              'HTTP listener web address. Here is were somewhere:99/ is stored into the EEPROM
            read 680 + j, TMP
            if (TMP != "#") and (TMP != $FF) then
                serout2 TOGSM,84,[TMP]
                serout2 TXPC,6,[TMP]  'JUST for DEBUG only
            else
                j = 31
            endif
        next
        serout2 TOGSM,84,["page.aspx?"]:    serout2 TXPC,6, ["page.aspx?"]  'JUST for DEBUG only
        serout2 TOGSM,84,["ev="]
    
        for j = 0 to TXBufCount      'Data that need to be sent
            TMP = TxBuffer[j]
            if (TMP != 13) and (TMP != 10) then
                select case TMP  'A little URL Encoding...
                    case "$", ";", "+", "-", "#", " ", 13, 10, "@"
                        SEROUT2 TOGSM, 84,["%", HEX2 TMP]                        
                    case else
                        serout2 TOGSM, 84,[TMP]
                end select
            endif
        next
        pause 100
        serout2 TOGSM,84, [34,13,10]

    This is how I had to change the code in order to work with the new modem TOO:
    Code:
        ARRAYWRITE BUFF, ["AT+HTTPPARA=", 34,"URL",34, "," ,34, "http://"]
        c = 26
        for j = 0 to 30              'HTTP listener web address. Here is were somewhere:99/ is stored into the EEPROM
            read 680 + j, TMP
            if (TMP != "#") and (TMP != $FF) then
                x = c + j
                BUFF[x] = TMP
                serout2 TXPC,6,[TMP]  'JUST for DEBUG only
            else
                j = 31
            endif
        next
        x = x + 1
        BUFF[x] = "p": x = x + 1
        BUFF[x] = "a": x = x + 1
        BUFF[x] = "g": x = x + 1
        BUFF[x] = "e": x = x + 1
        BUFF[x] = ".": x = x + 1
        BUFF[x] = "a": x = x + 1
        BUFF[x] = "s": x = x + 1
        BUFF[x] = "p": x = x + 1
        BUFF[x] = "x": x = x + 1
        BUFF[x] = "?": x = x + 1
        BUFF[x] = "e": x = x + 1
        BUFF[x] = "v": x = x + 1
        BUFF[x] = "=": x = x + 1                                                               
        for j = 0 to TXBufCount      'Data that need to be sent
            TMP = TxBuffer[j]
            if (TMP != 13) and (TMP != 10) then
                select case TMP  'A little URL Encoding...
                    case "$", ";", "+", "-", "#", " ", 13, 10, "@"
                        DummyByte = Tmp / 16
                        gosub ConvertHEX
                        buff[x] = "%": x = x + 1
                        buff[x] = DummyHEX: x = x + 1
                        DummyByte = TMP // 16
                        Gosub ConvertHEX
                        buff[x] = DummyHEX: x = x + 1
                    case else
                        buff[x] = tmp: x = x + 1
                end select
            endif
        next
        BUFF[x] = 0  'Array termination
        serout2 TOGSM, 84, [STR BUFF]
        pause 100
        serout2 TOGSM,84, [34,13,10]
    
    
    ConvertHEX:
        LOOKUP DummyByte,["0123456789ABCDEF"],DummyHEX
        return
    So, the question is: WHAT multiple SEROUT2 statements does, or maybe READ command interfer in some way with the SEROUT2 command?
    Is there something I'm missing and need to be considered in order to avoid other subtle problems?

    Thank you all.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    1,510

    Default Re: Weird behaviour of SEROUT2

    serout2 TOGSM,84, ["AT+HTTPPARA=", 34,"URL",34, "," ,34, "http://"]

    serout2 TXPC,6, ["AT+HTTPPARA=", 34,"URL",34, "," ,34, "http://"] 'JUST for DEBUG only
    I wonder if using multiple serout2 instances like that with opposite data polarity might cause unintentional "breaks" on the data line .

    why not use DEBUG for the debug messages ?

    read 680 + j, TMP
    how many bytes of eprom on your chip ?


    x = x + 1
    BUFF[x] = "p": x = x + 1
    BUFF[x] = "a": x = x + 1
    BUFF[x] = "g": x = x + 1
    BUFF[x] = "e": x = x + 1
    BUFF[x] = ".": x = x + 1
    BUFF[x] = "a": x = x + 1
    BUFF[x] = "s": x = x + 1
    BUFF[x] = "p": x = x + 1
    BUFF[x] = "x": x = x + 1
    BUFF[x] = "?": x = x + 1
    BUFF[x] = "e": x = x + 1
    BUFF[x] = "v": x = x + 1
    BUFF[x] = "=": x = x + 1
    not heard of arraywrite

  3. #3
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    77

    Default Re: Weird behaviour of SEROUT2

    Hi Richard, thank you for your reply.
    The Serout2 for debug purposes was inserted just to see if I was picking the correct data. I've also tried to take it off completely, the result is the same.
    The bytes for the address from the EEPROM are at most 30.
    The arraywrite statement is the first line of the second chunk of code I've posted. It is used to prepare the first bytes of the sentence need to be sent to the modem.
    IF you look at the code you will see:
    Code:
    ARRAYWRITE BUFF, ["AT+HTTPPARA=", 34,"URL",34, "," ,34, "http://"]
    The next BUFF[x] = "p": x = x + 1 etc is used to continue populating the array. Unless you have a better method to continue filling an array with multiple use of ARRAYWRITE, but this is out of the scope of the current issue.

    The current issue is that talking with the modem using multiple SEROUT2 does not works, while sending to it a pre-filled buffer with a single SEROUT2 call, it works as expected.

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    1,510

    Default Re: Weird behaviour of SEROUT2

    read 680 + j, TMP
    The bytes for the address from the EEPROM are at most 30.
    so how does an offset of 680 fit into the scheme when there are only 256 bytes of eprom




    snippets of code seldom help to resolve issues
    this seems to works as expected on a 18f45k20 , there are no detectable glitches on the output with my logic analyser . unless your modem has
    some special interbyte timeout feature there is something else going on





    Code:
    #CONFIG
      CONFIG  FOSC = INTIO67
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRT = OFF
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 18
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 512
      CONFIG  CCP2MX = PORTC
      CONFIG  PBADEN = OFF
      CONFIG  LPT1OSC = OFF
      CONFIG  HFOFST = ON
      CONFIG  MCLRE = ON
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
    DEFINE OSC 64
       
       osccon=$70   '32 mhz
       OSCTUNE.6=1
       
      
       ANSELH=0
    data @0,  "s","o","m","e","w","h","e","r","e",":","9","9","/" ,0
    j var byte
    tmp var byte
    togsm var  portc.1
    txpc var  portc.2
    trigger var portc.3
    TXBufCount var byte
    txbuffer    var byte[10]
    trisc=%11110001
    arraywrite txbuffer,["message#",10]
    TXBufCount=7
    txpc=1
    togsm=1
    trigger=1
    pause 100
     
    
    loopy:
    trigger=0
    trigger=1 
    serout2 TOGSM,6, ["AT+HTTPPARA=", 34,"URL",34, "," ,34, "http://"]
     
    serout2 TXPC,84,   ["AT+HTTPPARA=", 34,"URL",34, "," ,34, "http://"]  'JUST for DEBUG only
        for j = 0 to 30              'HTTP listener web address. Here is were somewhere:99/ is stored into the EEPROM
            read j, TMP
            if TMP  then
                serout2 TOGSM,6,[TMP]
                serout2 TXPC,84,[TMP]  'JUST for DEBUG only
            else
                j = 31
            endif
        next
        serout2 TOGSM,6,["page.aspx?"]:    serout2 TXPC,84, ["page.aspx?"]  'JUST for DEBUG only
        serout2 TOGSM,6,["ev="]
        for j = 0 to TXBufCount      'Data that need to be sent
            TMP = TxBuffer[j]
            if (TMP != 13) and (TMP != 10) then
                select case TMP  'A little URL Encoding...
                    case "$", ";", "+", "-", "#", " ", 13, 10, "@"
                        SEROUT2 TOGSM, 6,["%", HEX2 TMP]                        
                    case else
                        serout2 TOGSM, 6,[TMP]
                end select
            endif
        next
      ;  pause 100
        serout2 TOGSM,6, [34,13,10]
         pause 1000
         goto loopy

    you can concatenate strings like this
    Code:
    DEFINE OSC 64
       
       osccon=$70   '32 mhz
       OSCTUNE.6=1
       
      
       ANSELH=0
    data @0,  "s","o","m","e","w","h","e","r","e",":","9","9","/" ,0
    j var byte
    tmp var byte
    togsm var  portc.1
    txpc var  portc.2
    trigger var portc.3
    TXBufCount var byte
    txbuffer    var byte[10]
    urlbuff     var byte[31]
    buff        var byte[64]
    binx       var byte ext
    trisc=%11110001
    arraywrite txbuffer,["message#",10]
    TXBufCount=7
    txpc=1
    togsm=1
    trigger=1
    @binx=_buff+26
    pause 100
     arraywrite buff,["AT+HTTPPARA=", 34,"URL",34, "," ,34, "http://"]
      gosub seturl
     arraywrite binx,[str urlbuff,0]
    loopy:
    trigger=0
    trigger=1 
    serout2 TOGSM,6, [str buff,"page.aspx?"]
     
        serout2 TOGSM,6,["ev="]
        for j = 0 to TXBufCount      'Data that need to be sent
            TMP = TxBuffer[j]
            if (TMP != 13) and (TMP != 10) then
                select case TMP  'A little URL Encoding...
                    case "$", ";", "+", "-", "#", " ", 13, 10, "@"
                        SEROUT2 TOGSM, 6,["%", HEX2 TMP]                        
                    case else
                        serout2 TOGSM, 6,[TMP]
                end select
            endif
        next
      ;  pause 100
        serout2 TOGSM,6, [34,13,10]
         pause 1000
         goto loopy
         
     seturl:    
           for j = 0 to 30              'HTTP listener web address. Here is were somewhere:99/ is stored into the EEPROM
            read j, TMP
            if TMP  then
               urlbuff[j]=tmp
            else
                urlbuff[j]=0
                j = 31
            endif
        next  
     return

    or

    Code:
    DEFINE OSC 64
       
       osccon=$70   '32 mhz
       OSCTUNE.6=1
       
      
       ANSELH=0
    data @0,  "s","o","m","e","w","h","e","r","e",":","9","9","/" ,0
    j var byte
    tmp var byte
    togsm var  portc.1
    txpc var  portc.2
    trigger var portc.3
    TXBufCount var byte
    txbuffer    var byte[10]
    urlbuff     var byte[31]
    trisc=%11110001
    arraywrite txbuffer,["message#",10]
    TXBufCount=7
    txpc=1
    togsm=1
    trigger=1
    pause 100
    
     gosub seturl
    loopy:
    trigger=0
    trigger=1 
    serout2 TOGSM,6, ["AT+HTTPPARA=", 34,"URL",34, "," ,34, "http://",str urlbuff,"page.aspx?"]
     
        serout2 TOGSM,6,["ev="]
        for j = 0 to TXBufCount      'Data that need to be sent
            TMP = TxBuffer[j]
            if (TMP != 13) and (TMP != 10) then
                select case TMP  'A little URL Encoding...
                    case "$", ";", "+", "-", "#", " ", 13, 10, "@"
                        SEROUT2 TOGSM, 6,["%", HEX2 TMP]                        
                    case else
                        serout2 TOGSM, 6,[TMP]
                end select
            endif
        next
      ;  pause 100
        serout2 TOGSM,6, [34,13,10]
         pause 1000
         goto loopy
         
     seturl:    
           for j = 0 to 30              'HTTP listener web address. Here is were somewhere:99/ is stored into the EEPROM
            read j, TMP
            if TMP  then
               urlbuff[j]=tmp
            else
                urlbuff[j]=0
                j = 31
            endif
        next  
     return
    This is more entertaining than Free to Air TV

  5. #5
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    77

    Default Re: Weird behaviour of SEROUT2

    Hi Richard,
    thank you again.
    I've erroneously named the micro I'm using. It is a PIC 18F4685 running at 20MHz and NOT the one I've mentioned PIC4550.... Actually does not even know how and why that name came out from my mind.... Sorry for the confusion. So, the 18F4685 have 1024 bytes of eeprom.
    I'm doing more experiments and got to your same conclusion about how to combine the strings.
    More likely the combination of READ x,y and conseguent SEROUT2 it is where something weird happen. At least with the 18F4685. I've tried different chips and different modems over different boards. So, it is definitively nothing to do with the hardware.
    ASAP I'll try the code that prepare the URL and send it via ARRAYWRITE preparation in one instruction only, just to have a better clue on what's going with READ+SEROUT2.

    BTW, the whole sentence I'm giving to the modem is something like this:
    AT+HTTPPARA="URL","http://somewhere:99/page.aspx?ev=%24%2D0.00%3B%20%20%20%200%3B%2B00.00 00000,%2B00.0000000"

    Thank you again for your help.

  6. #6
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    991

    Default Re: Weird behaviour of SEROUT2

    AT commands end with the return (0x13). Why would you want to send a new line to the device?

    https://www.arcelect.com/GSM%20Devel...Rev%20%20A.pdf

    I understand it’s working one way nevertheless, but still...

    One code will be faster than the other, so perhaps your device times out before being fully received from one version of your codes,
    or since the modem has hardware flow control, maybe one version of your code sends the command too fast, while the modem is de-asserting CTS trying to tell your program to wait.

    There’s definitely no problem using multiple serial commands to send the same string. I only ever use one to send a single variable, and then keep calling that to send entire strings.
    Reading from EEPROM in-between has never caused problems for me either.

    It shouldn’t be hard to deliberately delay between bytes for the non working version to at least rule out the flow control, at least if you were sending everything byte by byte.

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,158

    Default Re: Weird behaviour of SEROUT2

    Quote Originally Posted by mikebar View Post
    ......

    BTW, the whole sentence I'm giving to the modem is something like this:
    AT+HTTPPARA="URL","http://somewhere:99/page.aspx?ev=%24%2D0.00%3B%20%20%20%200%3B%2B00.00 00000,%2B00.0000000"

    Thank you again for your help.
    AT+HTTPPARA="URL","http://somewhere:99/page.aspx?ev=%24%2D0.00%3B%20%20%20%200%3B%2B00.00 00000,%2B00.0000000

    This sentence is longer than 100 chars.
    If this whole thing is getting into BUFF array, how about the size of BUFF?
    Last edited by sayzer; - 10th November 2018 at 14:16.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  8. #8
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    77

    Default Re: Weird behaviour of SEROUT2

    Quote Originally Posted by sayzer View Post
    AT+HTTPPARA="URL","http://somewhere:99/page.aspx?ev=%24%2D0.00%3B%20%20%20%200%3B%2B00.00 00000,%2B00.0000000

    This sentence is longer than 100 chars.
    If this whole thing is getting into BUFF array, how about the size of BUFF?
    BUFF is declared as below:
    Code:
    BUFF        VAR BYTE[800]
    Also, I've forgot to mention that I'm using PBP 2.60c. It makes some difference/sense?

    Thank you all.

  9. #9
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    77

    Default Re: Weird behaviour of SEROUT2

    Hi Richard,
    could you please explain the meaning of the following line of code, that you used in one of your posts as reply:
    Code:
    @binx=_buff+26
    Thank you.

  10. #10
    Join Date
    May 2013
    Location
    australia
    Posts
    1,510

    Default Re: Weird behaviour of SEROUT2

    @ invokes inline assembler
    binx [in pos0] creates an asm label called binx
    _buff is a pbp label whose numerical value = the address of buff var

    so binx = address of buff + 26


    so
    binx var byte ext
    simply points to an array located inside the buff array at the 26th address in


    somewhere in the forum there is a good explanation of use of ext modifier by dt
    another sadly underused feature of pbp along with user command
    see here
    http://www.picbasic.co.uk/forum/showthread.php?t=3891
    Last edited by richard; - 14th November 2018 at 22:38.
    This is more entertaining than Free to Air TV

  11. #11
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    77

    Default Re: Weird behaviour of SEROUT2

    Quote Originally Posted by richard View Post
    @ invokes inline assembler
    binx [in pos0] creates an asm label called binx
    _buff is a pbp label whose numerical value = the address of buff var

    so binx = address of buff + 26


    so
    binx var byte ext
    simply points to an array located inside the buff array at the 26th address in


    somewhere in the forum there is a good explanation of use of ext modifier by dt
    another sadly underused feature of pbp along with user command
    see here
    http://www.picbasic.co.uk/forum/showthread.php?t=3891
    Thank you VERY much!

Similar Threads

  1. Weird PWM Behaviour on 16F1825
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th October 2012, 21:59
  2. Strange IT behaviour
    By MikeBZH in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th February 2012, 10:00
  3. Strange behaviour
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th October 2009, 22:35
  4. pauseus behaviour, 18f2455
    By mark_wotton in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th September 2006, 15:39
  5. strange int behaviour
    By tom in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th November 2005, 16:41

Members who have read this thread : 25

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