+ Post New Thread
Page 2 of 2 FirstFirst 1 2
Results 21 to 38 of 38
  1. #21
    Super Moderator
    Points: 85,268, Level: 71
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    14,032
    Helped
    4671 / 4671
    Points
    85,268
    Level
    71

    Re: PIC serial port receive Problem, please help

    This would be my approach:
    Code:
    // adjust this to the length of the longest response + 1
    #define BUFFERSIZE 20 
    
    // this is the ISR
    void __interrupt() ISR(void)
    {
      if(PIR1bits.RCIF)
      {
        if(RCSTAbits.OERR)
        {
          RCSTAbits.CREN = 0;
          RCSTAbits.CREN = 1;
        }
        else
        {
          ByteReceived = RXREG;
          gsmFlag = 1;
        }
    }
    
    // this is in your main loop
    if(gsmFlag)
    {
      if(ByteReceived == '+') GSMindex = 0;   // start of message found
      if(ByteReceived == '\n') STAT = !STAT;  // or whatever you want to do with the data
      else
      {
        if(GSMindex < BUFFERSIZE) 
        {
          GSMbuff[GSMindex++] = ByteReceived;
          GSMbuff[GSMindex] = 0;
        }
      }
    }
    This should capture everything after a '+' to the end of the line, it clears the buffer at each new line, checks the buffer doesn't overflow and the result in 'GSMbuff' is a terminated string.

    Reset 'gsmFlag' when you have processed the string so it is ready for next time.

    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.



  2. #22
    Super Moderator
    Points: 30,356, Level: 42
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    9,105
    Helped
    1143 / 1143
    Points
    30,356
    Level
    42
    Blog Entries
    9

    Re: PIC serial port receive Problem, please help

    Quote Originally Posted by betwixt View Post
    Code:
    if(GSMindex < BUFFERSIZE) 
        {
          GSMbuff[GSMindex++] = ByteReceived;
          GSMbuff[GSMindex] = 0;
        }
    With the addition of an 'otherwise' option...

    Code:
    else  
        {
         GSMindex = 0;
        }
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  3. #23
    Advanced Member level 4
    Points: 8,194, Level: 21
    Achievements:
    7 years registered

    Join Date
    Jan 2015
    Posts
    1,145
    Helped
    356 / 356
    Points
    8,194
    Level
    21

    Re: PIC serial port receive Problem, please help

    (Also being discussed at https://www.microchip.com/forums/m1129931.aspx)
    Susan



  4. #24
    Super Moderator
    Points: 85,268, Level: 71
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    14,032
    Helped
    4671 / 4671
    Points
    85,268
    Level
    71

    Re: PIC serial port receive Problem, please help

    With the addition of an 'otherwise' option...
    There is no harm done but no advantage in that Andre as the overflowing data is lost anyway. The array pointer gets reset to zero by the next string arriving. It is there just in case an unterminated or over-length string arrives so it doesn't overflow the buffer.

    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

        
       

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

    Re: PIC serial port receive Problem, please help

    Quote Originally Posted by betwixt View Post
    There is no harm done but no advantage in that Andre as the overflowing data is lost anyway. The array pointer gets reset to zero by the next string arriving. It is there just in case an unterminated or over-length string arrives so it doesn't overflow the buffer.

    Brian.
    Code:
    /******************************************************************************/
    /* Files to Include                                                           */
    /******************************************************************************/
    #include              /* XC8 General Include File */
    #include          /* For uint8_t definition */
    #include         /* For true/false definition */
    #include "system.h"         /* System funct/params, like osc/peripheral config */
    #include "user.h"           /* User funct/params, such as InitApp */
    #include "lcd.h"            /* LCD functions*/
    #include "usart.h"          /* Serial Port Functions*/
    /******************************************************************************/
    /* User Global Variable Declaration                                           */
    /******************************************************************************/
    unsigned char pass[MAX_PASS_LEN],regPhoneNumber[MAX_PHONE_LEN+1],regIbId[MAX_IBID_LEN]; 
    /******************************************************************************/
    /* Main Program                                                               */
    /******************************************************************************/
    void main(void){
        unsigned char temp,data;
        unsigned long timeout = 1500000;
        /* Initialize I/O and Peripherals for application */
        InitApp();
        STAT = false;
        lcd_clear();
        lcd_goto(0X00);
        lcd_puts("GSM Debug");
        lcd_goto(0X40);
        temp = 3;   //three retries
        do{ 
            lcd_goto(0X00);
            lcd_puts("ATE0 SENT...");
            lcd_goto(0X40);
            data = gsmTest();
            flushGsmBuff();
            lcd_putXnum(data);
            lcd_putch(',');
            if(data)
                break;
            temp--;
            
        }while(!data);
        lcd_goto(0X40);
        lcd_puts("WAITING FOR SMS");
        
        putstr("AT+CMGF=1\r");
        __delay_ms(1000);
        putstr("AT+CMGD=0\r");
        __delay_ms(1000);
        putstr("AT+CNMI=2,2,0,0,0\r");
        __delay_ms(1000);
        PIR1bits.RCIF = 0;
        PIE1bits.RCIE = 1;
        INTCONbits.PEIE = 1;
        INTCONbits.GIE = 1;
        lcd_clear();
        lcd_goto(0x00);
        GSMindex = 0;
        gsmFlag = 0;
        while(1){
            if(gsmFlag){
                STAT = true;
                while(1){
                    if(GSMbuff[GSMindex - 1] == EOD){
                        gsmFlag = 0;
                        break;
                    }
                    if(GSMindex >= MAX_BUF_LEN)
                        break;
                    timeout --;
                    if(!timeout)
                        break;
                }
                STAT = false;
                lcd_putch('*');
                __delay_ms(500);
                PIE1bits.RCIE = 0;
                lcd_clear();
                lcd_goto(0X00);
                temp = GSMindex;
                GSMindex = 0;
                while(GSMindex < temp){
                    lcd_putch(GSMbuff[GSMindex]);
                    GSMindex ++;
                    if(GSMindex%60 == 0){
                        lcd_goto(0X54);
                    }
                    else if(GSMindex%40 == 0){
                        lcd_goto(0X14);
                    }
                    else if(GSMindex%20 == 0){
                        lcd_goto(0X40);
                    }
                }
                lcd_putXnum(temp);
                GSMindex = 0;
                timeout = 1500000;
                gsmFlag = 0;
            }
        }
    }
    this is my entire code.

    - - - Updated - - -

    Click image for larger version. 

Name:	circuit.png 
Views:	2 
Size:	107.3 KB 
ID:	158009
    this is my entire circuit diagram
    Electronics roles the world. When he stops his work what will happen. Recycle electronics, leave the future for your baby also



  6. #26
    Super Moderator
    Points: 85,268, Level: 71
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    14,032
    Helped
    4671 / 4671
    Points
    85,268
    Level
    71

    Re: PIC serial port receive Problem, please help

    Problem: your serial link is entirely missing from the schematic - how are we to diagnose a possible electrical problem when it isn't even shown.

    What does the line " PIE1bits.RCIE = 0;" do? I can't see any point in disabling serial interrupts at that place in the program.

    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.



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

    Re: PIC serial port receive Problem, please help

    Click image for larger version. 

Name:	IMG_20200303_164432.jpg 
Views:	5 
Size:	559.2 KB 
ID:	158010
    this is my GSM modem

    - - - Updated - - -

    Quote Originally Posted by betwixt View Post

    What does the line " PIE1bits.RCIE = 0;" do? I can't see any point in disabling serial interrupts at that place in the program.

    Brian.
    during the lcd printing i am disabling the interrupt, i am not expecting any reception in this time, is there any problem with that?

    - - - Updated - - -

    Quote Originally Posted by betwixt View Post
    Problem: your serial link is entirely missing from the schematic - how are we to diagnose a possible electrical problem when it isn't even shown.

    Brian.
    sir, i named it as gsm modem in the circuit
    Click image for larger version. 

Name:	gsm connection.png 
Views:	1 
Size:	3.8 KB 
ID:	158011
    Electronics roles the world. When he stops his work what will happen. Recycle electronics, leave the future for your baby also



    •   AltAdvertisement

        
       

  8. #28
    Super Moderator
    Points: 85,268, Level: 71
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    14,032
    Helped
    4671 / 4671
    Points
    85,268
    Level
    71

    Re: PIC serial port receive Problem, please help

    Disabling RCIE is not a problem but it isn't necessary and you need to re-enable it before any more serial data can be received.

    The reason I wanted the full schematic is we could not tell what kind of interface was on the GSM module, some have RS232 interfaces which are incompatible with the PIC TX and RX pins. As the picture shows CTS and RTS pads connected directly to the SIM900 I think we can assume it does not have an intermediate interface to the row of pins on the right. I presume you are using those pins and not the 'D' connector.

    Next question: you seem to be running the PIC from a 7805 regulator so it has a 5V VCC. The SIM900A will be destroyed by applying 5V, it has an absolute maximum supply of 4.5V and typically runs from 4V. Are you sure the voltage levels between them are compatible?

    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

        
       

  9. #29
    Full Member level 5
    Points: 3,731, Level: 14
    Achievements:
    7 years registered
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    242
    Helped
    32 / 32
    Points
    3,731
    Level
    14

    Re: PIC serial port receive Problem, please help

    Quote Originally Posted by betwixt View Post
    Disabling RCIE is not a problem but it isn't necessary and you need to re-enable it before any more serial data can be received.

    The reason I wanted the full schematic is we could not tell what kind of interface was on the GSM module, some have RS232 interfaces which are incompatible with the PIC TX and RX pins. As the picture shows CTS and RTS pads connected directly to the SIM900 I think we can assume it does not have an intermediate interface to the row of pins on the right. I presume you are using those pins and not the 'D' connector.

    Next question: you seem to be running the PIC from a 7805 regulator so it has a 5V VCC. The SIM900A will be destroyed by applying 5V, it has an absolute maximum supply of 4.5V and typically runs from 4V. Are you sure the voltage levels between them are compatible?

    Brian.
    i am giving the power externally using a separate adapter, not giving 5 V directly
    Electronics roles the world. When he stops his work what will happen. Recycle electronics, leave the future for your baby also



  10. #30
    Super Moderator
    Points: 85,268, Level: 71
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    14,032
    Helped
    4671 / 4671
    Points
    85,268
    Level
    71

    Re: PIC serial port receive Problem, please help

    But what about the signal levels between the PIC and the GSM module.

    If the module is running on a lower supply voltage, the levels from the PIC may be high enough to 'latch-up' its pins. Equally, if the GSM levels are too low, the PIC may simply ignore or misinterpret them.

    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.



  11. #31
    Full Member level 5
    Points: 3,731, Level: 14
    Achievements:
    7 years registered
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    242
    Helped
    32 / 32
    Points
    3,731
    Level
    14

    Re: PIC serial port receive Problem, please help

    by debugging the system i got an error as FERR (framing error), i am using a board rate of 9600 both in GSM and PIC microcintroller.
    Electronics roles the world. When he stops his work what will happen. Recycle electronics, leave the future for your baby also



  12. #32
    Super Moderator
    Points: 85,268, Level: 71
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    14,032
    Helped
    4671 / 4671
    Points
    85,268
    Level
    71

    Re: PIC serial port receive Problem, please help

    FERR can indicate a speed error or that the data is corrupted. It just tells you that the stop bit wasn't detected 8 bits after the start bit in each byte. It can still be an electrical problem as I said in post #30 so eliminate that first or you will never get the software to work.

    It would be worth checking your crystal really is 20.0MHz, that the BRGH bit is really '1' and the SPBRG register really holds 129 (0x81).

    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.



  13. #33
    Full Member level 5
    Points: 3,731, Level: 14
    Achievements:
    7 years registered
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    242
    Helped
    32 / 32
    Points
    3,731
    Level
    14

    Re: PIC serial port receive Problem, please help

    Hai all, I thank everyone for helping me and stand along with me. I am happy to say that I solved my the problem.thanks all



  14. #34
    Super Moderator
    Points: 85,268, Level: 71
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    14,032
    Helped
    4671 / 4671
    Points
    85,268
    Level
    71

    Re: PIC serial port receive Problem, please help

    For the benefit of others reading this forum, please tell us what you found was wrong.

    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.



  15. #35
    Full Member level 5
    Points: 3,731, Level: 14
    Achievements:
    7 years registered
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    242
    Helped
    32 / 32
    Points
    3,731
    Level
    14

    Re: PIC serial port receive Problem, please help

    Quote Originally Posted by betwixt View Post
    For the benefit of others reading this forum, please tell us what you found was wrong.

    Brian.
    The problem was not my in my code, or in my hardware ( conceptually). And also in GSM. The problem was GSM module is working on 3.3 -3.9v logic. I thought that pic can handle this. But it producing an FERR error. So I added a buffer between GSM tx and PIC Rx.
    Now the code and hardware working perfectly.
    Thanks to everyone who helped me for this task...



  16. #36
    Super Moderator
    Points: 83,894, Level: 70
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    17,062
    Helped
    3854 / 3854
    Points
    83,894
    Level
    70

    Re: PIC serial port receive Problem, please help

    Hi,

    From post #2:
    * or wrong voltage levels.
    --> but you don't give none of the above informations.
    This is why the datasheets specify: V_IL, V_lH, V_OL, V_OH.

    ***

    Maybe you recognize that giving full informations could have speed up to find the solution...
    So this thread is a good example for others looking for help...

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



    •   AltAdvertisement

        
       

  17. #37
    Newbie level 1
    Points: 15, Level: 1

    Join Date
    Mar 2020
    Location
    Ludhiana
    Posts
    1
    Helped
    0 / 0
    Points
    15
    Level
    1

    Re: PIC serial port receive Problem, please help

    Quote Originally Posted by thunderboympm View Post
    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.
    According to me your issue related to, while programming Arduino uses serial ports to load program from the Arduino IDE. If these pins are used in wiring, the program will not be loaded successfully to Arduino. So you have to disconnect wiring in Rx and Tx each time you burn the program to Arduino. When the program get loaded successfully, you need to reconnect these pins and hopefully, your system gets started.



  18. #38
    Super Moderator
    Points: 85,268, Level: 71
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    14,032
    Helped
    4671 / 4671
    Points
    85,268
    Level
    71

    Re: PIC serial port receive Problem, please help

    According to me your issue related to, while programming Arduino uses serial ports to load program from the Arduino IDE. If these pins are used in wiring, the program will not be loaded successfully to Arduino. So you have to disconnect wiring in Rx and Tx each time you burn the program to Arduino. When the program get loaded successfully, you need to reconnect these pins and hopefully, your system gets started.
    Please read the question Technowiz, it relates to a PIC18F452 connecting to a GSM module, there is no mention of Arduino at all.

    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.



--[[ ]]--