Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC serial port receive Problem, please help

Status
Not open for further replies.
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.
 

Code:
if(GSMindex < BUFFERSIZE) 
    {
      GSMbuff[GSMindex++] = ByteReceived;
      GSMbuff[GSMindex] = 0;
    }

With the addition of an 'otherwise' option...

Code:
else  
    {
     GSMindex = 0;
    }
 

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.
 

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 <xc.h>             /* XC8 General Include File */
#include <stdint.h>         /* For uint8_t definition */
#include <stdbool.h>        /* 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 - - -

circuit.png
this is my entire circuit diagram
 

Attachments

  • circuit od isecure lock.png
    circuit od isecure lock.png
    99.6 KB · Views: 71

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.
 

IMG_20200303_164432.jpg
this is my GSM modem

- - - Updated - - -

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 - - -

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
gsm connection.png
 

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.
 

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
 

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.
 

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.
 

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.
 

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
 

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...
 

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
 

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.
8-O8-O

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.
 

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.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top