+ Post New Thread
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 38
  1. #1
    Full Member level 4
    Points: 3,686, Level: 14
    Achievements:
    7 years registered
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    238
    Helped
    32 / 32
    Points
    3,686
    Level
    14

    PIC serial port receive Problem, please help

    hai,
    I am reading the return back from a GSM Module (SIM900A) using PIC18f452, the module is AE GSM MODULE. the problem is when I am connecting the GSM module through the ft232 module by serial GSM modem is working, and also my program is also OK, but when I am connecting to the AE GSM MODULE the program is not getting the return back. anyone has faced similar problems and can anyone give any clues.
    Electronics roles the world. When he stops his work what will happen. Recycle electronics, leave the future for your baby also

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 82,053, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,651
    Helped
    3774 / 3774
    Points
    82,053
    Level
    69

    Re: PIC serial port receive Problem, please help

    Hi,

    I don't understand:
    * when you say you use ft232, then your PIC needs to have an USB_host to operate it.
    If it does work with FT232, then why not use it this way?

    but when I am connecting to the AE GSM MODULE
    Connecting what to the GSM module?

    A simple (hand drawn) sketch of the two situations (working and not_working) could be useful.

    I assume you already read some UART troubleshooting threads here. Then you already should know that in 95% of the cases the problem is:
    * wrong interface setting (baud rate, baud rate tolerance, bits per byte, start bits, stop bits, parity, handshaking...)
    * or wrong voltage levels.
    --> but you don't give none of the above informations.

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  3. #3
    Super Moderator
    Points: 84,045, Level: 70
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,828
    Helped
    4590 / 4590
    Points
    84,045
    Level
    70

    Re: PIC serial port receive Problem, please help

    Are you confusing FT232 and MAX232 perhaps?

    FT232 = serial to USB converter
    MAX232 = Voltage level converter usually used in serial TTL to RS232 applications.

    Normally you don't need a voltage level converter between GSM modules and a PIC and you should also be aware that if it is a MAX232 it inverts the signal and could result in voltages that can damage one or both connected devices.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  4. #4
    Full Member level 4
    Points: 3,686, Level: 14
    Achievements:
    7 years registered
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    238
    Helped
    32 / 32
    Points
    3,686
    Level
    14

    Re: PIC serial port receive Problem, please help

    Quote Originally Posted by KlausST View Post
    Hi,

    I don't understand:
    * when you say you use ft232, then your PIC needs to have an USB_host to operate it.
    If it does work with FT232, then why not use it this way?


    Connecting what to the GSM module?

    A simple (hand drawn) sketch of the two situations (working and not_working) could be useful.

    I assume you already read some UART troubleshooting threads here. Then you already should know that in 95% of the cases the problem is:
    * wrong interface setting (baud rate, baud rate tolerance, bits per byte, start bits, stop bits, parity, handshaking...)
    * or wrong voltage levels.
    --> but you don't give none of the above informations.

    Klaus
    Thanks for reply sir,
    My problem is when I am connecting my pic(pic18f452) to GSM module using serial port at a board rate of 9600, pic producing OERR, that causes data loss. I am getting good results in pc.

    - - - Updated - - -

    Quote Originally Posted by betwixt View Post
    Are you confusing FT232 and MAX232 perhaps?

    FT232 = serial to USB converter
    MAX232 = Voltage level converter usually used in serial TTL to RS232 applications.

    Normally you don't need a voltage level converter between GSM modules and a PIC and you should also be aware that if it is a MAX232 it inverts the signal and could result in voltages that can damage one or both connected devices.

    Brian.
    Thanks for reply sir,
    My problem is when I am connecting my pic(pic18f452) to GSM module using serial port at a board rate of 9600, pic producing OERR, that causes data loss. I am getting good results in pc



  5. #5
    Super Moderator
    Points: 265,435, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    46,376
    Helped
    14115 / 14115
    Points
    265,435
    Level
    100

    Re: PIC serial port receive Problem, please help

    OERR means overrun error, a new character arrived before the UART buffer has been read. Apparently your code isn't able to process the data in time. Did you consider an interrupt driven RX ring buffer?

    A trivial point is that your code should monitor UART errors, e.g. OERR, and reset it if they occur sporadically.



  6. #6
    Full Member level 4
    Points: 3,686, Level: 14
    Achievements:
    7 years registered
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    238
    Helped
    32 / 32
    Points
    3,686
    Level
    14

    Re: PIC serial port receive Problem, please help

    Quote Originally Posted by FvM View Post
    OERR means overrun error, a new character arrived before the UART buffer has been read. Apparently your code isn't able to process the data in time. Did you consider an interrupt driven RX ring buffer?

    A trivial point is that your code should monitor UART errors, e.g. OERR, and reset it if they occur sporadically.
    Sir, I am resetting OERR and giving a NOP period.

    - - - Updated - - -

    Quote Originally Posted by FvM View Post
    OERR means overrun error, a new character arrived before the UART buffer has been read. Apparently your code isn't able to process the data in time. Did you consider an interrupt driven RX ring buffer?

    A trivial point is that your code should monitor UART errors, e.g. OERR, and reset it if they occur sporadically.
    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    
    void __interrupt() ISR(void){
        GIE = 0;
        if(RCIF){
            RCIF = 0;
            GSMtemp = RCREG;
            if(GSMtemp == '+'){
                plusFlag = 1;
                GSMindex = 0;
            }
            if(plusFlag){
                GSMbuff[GSMindex] = GSMtemp;
                GSMindex ++;
            }
            if(GSMtemp == 'K')
                OKFlag = 1;
            if(OERR){
                CREN = 0;
                NOP();
                CREN = 1;
            }
        }
        GIE = 1;
    }
    This is my interrupt subroutine



  7. #7
    Super Moderator
    Points: 84,045, Level: 70
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,828
    Helped
    4590 / 4590
    Points
    84,045
    Level
    70

    Re: PIC serial port receive Problem, please help

    Remove the two lines that contain 'GIE', they are not needed and could cause other problems including possible 'deaf' periods where serial data is lost.

    I think you are trying to capture all the characters between '+' and 'OK' but you face two problems, the first is no check for the data overflowing the size of 'GSMbuff' and other is it will fail if 'K' appears in the data before it is used as the terminator.


    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  8. #8
    Full Member level 4
    Points: 3,686, Level: 14
    Achievements:
    7 years registered
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    238
    Helped
    32 / 32
    Points
    3,686
    Level
    14

    Re: PIC serial port receive Problem, please help

    Quote Originally Posted by betwixt View Post
    Remove the two lines that contain 'GIE', they are not needed and could cause other problems including possible 'deaf' periods where serial data is lost.

    I think you are trying to capture all the characters between '+' and 'OK' but you face two problems, the first is no check for the data overflowing the size of 'GSMbuff' and other is it will fail if 'K' appears in the data before it is used as the terminator.


    Brian.
    Sir, I made a buffer GSMbuff of 80.
    Actually my application was to capture the terminal messages after I giving the command at+cnmi=2,2,0,0,0. So the message will suddenly send to terminal with a format with a starting of +CMT:.........
    I made a code for this and successfully simulated and tested successfully in hardware (by connecting to pc). But when I connecting to GSM module the problem arises...



  9. #9
    Super Moderator
    Points: 265,435, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    46,376
    Helped
    14115 / 14115
    Points
    265,435
    Level
    100

    Re: PIC serial port receive Problem, please help

    I made a code for this and successfully simulated and tested successfully in hardware (by connecting to pc). But when I connecting to GSM module the problem arises.
    That's a bit more of information.

    1. There may be a hardware problem, e.g. wrong or incomplete connection of the modem module, missing handshake lines etc.

    2. In any case, it's useful to think about debugging options. I prefer to have two UART-to-TTL channels to capture RX and TX data in a PC application. You may also use a PIC hardware debugger to trace code operation, e.g. content of the receive buffer.

    All in all, it's just regular embedded developing work. Code runs rarely at first try.



    •   AltAdvertisement

        
       

  10. #10
    Full Member level 4
    Points: 3,686, Level: 14
    Achievements:
    7 years registered
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    238
    Helped
    32 / 32
    Points
    3,686
    Level
    14

    Re: PIC serial port receive Problem, please help

    Quote Originally Posted by FvM View Post
    That's a bit more of information.

    1. There may be a hardware problem, e.g. wrong or incomplete connection of the modem module, missing handshake lines etc.
    i am not using any handshake lines, only RX -> TX, TX -> RX, and GND -> GND
    Electronics roles the world. When he stops his work what will happen. Recycle electronics, leave the future for your baby also



  11. #11
    Super Moderator
    Points: 265,435, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    46,376
    Helped
    14115 / 14115
    Points
    265,435
    Level
    100

    Re: PIC serial port receive Problem, please help

    Yes, but modem may need a certain wiring of handshake lines. As previously mentioned, without some debugging means you can only guess.



  12. #12
    Newbie level 1
    Points: 13, Level: 1

    Join Date
    Feb 2020
    Posts
    1
    Helped
    0 / 0
    Points
    13
    Level
    1

    Re: PIC serial port receive Problem, please help

    do need more of debugging to get the solutions else its just gona be random guessing



  13. #13
    Advanced Member level 3
    Points: 3,642, Level: 14
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    728
    Helped
    54 / 54
    Points
    3,642
    Level
    14

    Re: PIC serial port receive Problem, please help

    That is because in Proteus Virtual Terminal "\r\n" is not sent and you cannot send it. In real hardware the GSM commands and responses will contain one or more pairs of "\r\n".



  14. #14
    Super Moderator
    Points: 265,435, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    46,376
    Helped
    14115 / 14115
    Points
    265,435
    Level
    100

    Re: PIC serial port receive Problem, please help

    Nothing has been said about Proteus simulation in this thread. As far as I understand, thunderboympm is reporting real hardware tests.



  15. #15
    Advanced Member level 3
    Points: 3,642, Level: 14
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    728
    Helped
    54 / 54
    Points
    3,642
    Level
    14

    Re: PIC serial port receive Problem, please help

    Quote Originally Posted by thunderboympm View Post
    I made a code for this and successfully simulated and tested successfully in hardware (by connecting to pc). But when I connecting to GSM module the problem arises...
    He mentions simulated.



  16. #16
    Full Member level 4
    Points: 3,686, Level: 14
    Achievements:
    7 years registered
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    238
    Helped
    32 / 32
    Points
    3,686
    Level
    14

    Re: PIC serial port receive Problem, please help

    Yea sir,
    I simulated it correctly in Proteus, and I fused the program through pikit3 to pic. And in hardware I send GSM returns though serial port (using ft232). At that time it is working as in my simulation in Proteus. But when I am connecting to GSM module the program is not working...



  17. #17
    Advanced Member level 3
    Points: 3,642, Level: 14
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    728
    Helped
    54 / 54
    Points
    3,642
    Level
    14

    Re: PIC serial port receive Problem, please help

    Why don't you reserve a 200 or 300-byte buffer and receive the whole GSM response data for a command and then parse it and do whatever is needed?



  18. #18
    Super Moderator
    Points: 30,284, Level: 42
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    9,061
    Helped
    1143 / 1143
    Points
    30,284
    Level
    42
    Blog Entries
    9

    Re: PIC serial port receive Problem, please help

    At that time it is working as in my simulation in Proteus.
    But when I am connecting to GSM module the program is not working...
    It has to be asked: Are you simulating exactly with the same 'AT' sentences used with a previously tested manual connection? If so, it is most likely a matter of timing, which could be avoided by using the flow control mentioned before.

    As per the sippet you posted, it is almost senseless. Was your intent is to decode some specific sentence on the fly? Seems like you wanted to check reception of both '+' and 'K' characters not in sequence, the if's are not cascaded with else's, so any other incoming character - garbage or not (as expected on real world) would make your code act erratically (e.g: After evaluating plusFlag as true, you do not take any action otherwise) .

    Just a tip: Try to simulate and validate each part of the code incrementally, not the whole, so that you can determine at what stage of the 'conversation' among microcontroller and Modem it fails.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  19. #19
    Full Member level 4
    Points: 3,686, Level: 14
    Achievements:
    7 years registered
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    238
    Helped
    32 / 32
    Points
    3,686
    Level
    14

    Re: PIC serial port receive Problem, please help

    Quote Originally Posted by andre_teprom View Post
    It has to be asked: Are you simulating exactly with the same 'AT' sentences used with a previously tested manual connection? If so, it is most likely a matter of timing, which could be avoided by using the flow control mentioned before.

    As per the sippet you posted, it is almost senseless. Was your intent is to decode some specific sentence on the fly? Seems like you wanted to check reception of both '+' and 'K' characters not in sequence, the if's are not cascaded with else's, so any other incoming character - garbage or not (as expected on real world) would make your code act erratically (e.g: After evaluating plusFlag as true, you do not take any action otherwise) .

    Just a tip: Try to simulate and validate each part of the code incrementally, not the whole, so that you can determine at what stage of the 'conversation' among microcontroller and Modem it fails.
    Sir, as per the whole consideration.
    Code:
    void __interrupt() ISR(void){
        
        if(PIR1bits.RCIF){
            if(RCSTAbits.OERR){
                RCSTAbits.CREN = 0;
                NOP();
                RCSTAbits.CREN = 1;
            }
            GSMbuff[GSMindex] = RCREG;
            GSMindex++;
            gsmFlag = 1;
        }
    }
    This is my modified interrupt subroutine
    Code:
    while(1){
            if(gsmFlag){
                while(1){
                    if(GSMbuff[GSMindex - 1] == EOD){
                        gsmFlag = 0;
                        break;
                    }
                    if(GSMindex >= MAX_BUF_LEN)
                        break;
                    STAT = !STAT;
                }
    This is the code sippet in my main program

    have EOD as '*' and MAX_BUF_LEN as 200 .
    GSMbuff is a char array of size of 200.STAT is a LED.

    Still the results are same.



    •   AltAdvertisement

        
       

  20. #20
    Advanced Member level 4
    Points: 8,101, Level: 21
    Achievements:
    7 years registered

    Join Date
    Jan 2015
    Posts
    1,137
    Helped
    351 / 351
    Points
    8,101
    Level
    21

    Re: PIC serial port receive Problem, please help

    Don't forget that the UART Rx baud rate must be within +/-2% of whatever the sender is using. You have not shown us the UART setup and the CONFIG settings, nor what the Fosc is that you are using.
    I am pleased to see that you are reducing the size of the ISR and moving the parsing into the main line. However I would recommend that you check for the terminator character (probably '\n or whatever the last character is on the line sent by the GSM module) and trigger the parsing on that; not on every character received. the advantage of this approach is that you can scan from the first received character to find the '+' which starts the response (thus skipping over any trailing characters - one document I read just now shows that the GSM module ends and "OK" line after the response), interpret the received characters until you get to the line terminator. You should have all of the characters in the buffer and not need to do the parsing a bit at a time.
    Also, you probably should read up on how to properly do the parsing. Parsing even well documented strings such as these is not trivial (specialise when you need to take into count all sorts of variations within each response string sad well as incomplete messages and errors) and it is very easy to do the job really badly. Bad code will work for a while (perhaps long enough to get a 'pass' mark for an assignment) but will fail in time.
    Susan



--[[ ]]--