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.