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.

UART Data read Error for GPS with SIM908 and PIC18F4550

Status
Not open for further replies.

Mithun_K_Das

Advanced Member level 3
Advanced Member level 3
Joined
Apr 24, 2010
Messages
899
Helped
24
Reputation
48
Reaction score
26
Trophy points
1,318
Location
Dhaka, Bangladesh, Bangladesh
Visit site
Activity points
8,254
I'm using PIC18F4550 at 115200 baud rate to get GPS information from SIM908. It works fine with commands sent from PC. Also it works fine with commands from MCU. But the problem is, the MCU can not read the GPS data sent from SIM908.

I checked the MCU, it can read data if I send the data from PC UART. But can not read SIM module. It reads some noise or blank space.

Data communication from MCU:
asd.JPG

Here you can find that all the communication is ok from MCU's side.

Also here is the data while SIM908 is connected with MCU:
sdf.png

Also the code:

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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*******************************************************************************
*                   Program for 'GPS Position Tracker for Car accident'        *
*                          Compiler: MicroC Pro for PIC v.5.6.1                *
*                         Program Written by Engr. Mithun K. Das               *
*                        e-mail: [email]mithun060@gmail.com[/email]; 01722448270              *
*                          MCU: PIC18F4550; X-Tal:20MHz                        *
*                                     25-Jan,2014                              *
*******************************************************************************/
 
/*
 
$GPGGA,025526.000,0653.409140,N,07954.150015,E,1,7 ,1.08,22.013,M,-96.608,M,,*4D
$GPGLL,0653.409140,N,07954.150015,E,025526.000,A,A *58
$GPGSA,A,3,21,29,18,24,22,25,15,,,,,,1.98,1.08,1.6 7*0F
$GPGSV,4,1,14,21,58,020,36,14,56,246,25,29,38,173, 36,18,32,354,36*7E
$GPGSV,4,2,14,24,30,071,49,22,25,317,34,06,19,304, 20,25,11,157,33*7E
$GPGSV,4,3,14,15,06,035,32,03,04,310,,31,03,205,,3 0,00,240,*78
$GPGSV,4,4,14,42,,,39,50,,,39*7F
$GPRMC,025526.000,A,0653.409140,N,07954.150015,E,0 .000,115.0,260313,,,A*6F
$GPVTG,115.0,T,,M,0.000,N,0.000,K,A*08
$GPZDA,025526.000,26,03,2013,,*57
 
*/
 
unsigned char text[64];
int i = 0;
short ready = 0;
 
 
 
#define    LED_ON    PORTD = 0xFF
#define    LED_OFF   PORTD = 0x00
 
void UART_Write_CText(const char *cptr)
{
    char chr;
    for ( ; chr = *cptr ; ++cptr ) UART1_Write(chr);
}
 
void Delay2s()
{
   int d;
   for(d=0;d<200;d++)
   {
      Delay_ms(10);
      asm CLRWDT;
   }
}
 
void GPS_Int(void);
void SMS_Int(void);
void GPS_OFF(void);
void interrupt() 
{
    if (RCIF_bit)
    {       // If interrupt is generated by RCIF
            text[i] = UART1_Read(); // Read data and store it to txrt string
            i++;             // Increment string index
            if (i >= 64)
            {                 // If index = 768,
                 i = 0;        //   set it to zero
                 ready = 1;    // Ready for parsing GPS data
            }
            RCIF_bit = 0;    // Set RCIF to 0
 
    }
 
}
 
void main() 
{
 
  TRISD1_bit = 0;//set as output
 
 
  ADCON0 = 0x00;
  ADCON1 = 0x07;//all digital
 
 
  LED_ON;
 
  UART1_Init(115200);//initialize UART at br 9600 bps
  Delay_ms(1000);// leave some time for UART
  
 
  GIE_bit = 1; // Enable Global interrupt
  PEIE_bit = 1; // Enable Peripheral interrupt    
  RCIE_bit = 1; // Enable USART Receiver interrupt
  RCIF_bit = 0;//clear flag
  
 
  LED_OFF;
  
   for(i=0;i<2;i++)
   {
       GPS_Int(void);
   }
   
    for(i=0;i<64;i++)
    {
       text[i] = ' ';
    }
    UART_Write_CText("AT+IPR=0\r\n");
    
 while(1)
 {
      OERR_bit = 0;// clear Overrun Error bit
      FERR_bit = 0;//clear Farming Error bit
      asm CLRWDT;
      GPS_Int(void);
      Delay2s();
      LED_ON;
      
      for(i=0;i<64;i++)
      {
         text[i] = ' ';
      }
      Delay2s();
      UART_Write_CText("AT+CGPSINF=32");
      RCIE_bit = 1; // Enable USART Receiver interrupt
      RCIF_bit = 0;//clear flag
      for(i=0;i<64;i++)
      {
         text[i] = ' ';
      }
      Delay2s();
      UART_Write_CText("\r\n");
      Delay2s();
      Delay2s();
 
      RCIE_bit = 0; // Disable USART Receiver interrupt
      RCIF_bit = 0;//clear flag
      if(ready == 1)
      {
          UART_Write_CText("GPS DATA:");
          for(i=0;i<64;i++)
          {
               UART1_Write(text[i]);
               Delay_ms(10);
          }
          
          UART_Write_CText("\n");
          
          for(i=0;i<64;i++)
          {
             text[i] = ' ';
          }
        ready = 0;
      }
      LED_OFF;
 
 
 }//while(1)
}//void main
 
void GPS_Int(void)
{
      LED_ON;
      UART_Write_CText("AT+CGPSPWR=1\r\n");//send AT+CGPSPWR=1 and Enter
      Delay2s();
      LED_OFF;
      UART_Write_CText("AT+CGPSRST=1\r\n");//select GPS mode, 1 = Autonomous, 0 = Cold
      Delay2s();
      UART_Write_CText("AT+CGPSIPR=115200\r\n");// set data rate
      Delay2s();
      UART_Write_CText("AT&W\r\n");//save recent settings
      Delay2s();
}
void GPS_OFF(void)
{
      UART_Write_CText("AT+CGPSPWR=0\r\n");//send AT+CGPSPWR=1 and Enter
      Delay2s();
}
 
void SMS_Int(void)
{
     UART_Write_CText("AT+cmgf=1\r\n");
     Delay2s();
     UART_Write_CText("AT+cmgs=");
     UART1_Write((char)'"');
     UART_Write_CText("01722448270");
     UART1_Write((char)'"');
     UART1_Write((char)13);
     UART1_Write((char)10);
     Delay2s();
}
 
//end of the program



I assumed that it may be the data rate problem with GPS section with MCU as GPS is working at data rate 115200. But unfortunately if I extract data at that rate, it doesn't find any thing rather than a noise.

I'm working at a board with ICD connection. So there is no ISIS simulation file. But I checked it with virtual terminal and its all ok.

If you need the PCB image, I can show it here:


Capture.JPG

And the real testing circuit image is here:
DSCN1212.JPG

DSCN1213.JPG

Now the question is, what is the mistake I've done or what is the problem here. Need your valuable advice. I'm still working on it...
 

After 2days of works with this issue, I found that the GPS works fine. Even MCU can read the data very fine. But the problem is whenever I'm trying to use the GSM part to send that data via SMS, it can not read the GPS data. It reads it as a noise or blank space.

Then what may be the solution of this issue? Should I keep a time gap between reading GPS and Sending SMS?
 

Which Baud rate did you use for your GsM?. its Much better If you Use the Same Baudrate for Both GSM and GPS, I just finished working on same Project using sim908...

Code:
AT+CGPSPWR=1;
AT+CGPSRST=0;
AT+CGPSINF=2;
 

Not related to your issue. What software are you using to make the PCB layout ? It looks better that eagle.

This piece of code

Code:
for(i=0;i<64;i++)
          {
             text[i] = ' ';
          }

can be replaced with

Code:
memset(text, '\0', sizeof(text));

- - - Updated - - -

It seems problem is with baudrate. mikroC gives message that there is 3.5% error in baudrate generated.

Try this

Code:
UART1_Init(111111);
 
OK, Let me try. I'll post the result after modification and testing the system soon.

I used baud rate 115200 that time, but now I'm using 9600 @ Pulsetronics. Also both same for GPS and GSM. In my case it generates an error of 0.16% only. I think its normal @ milan.

Anyway, let me try again.

- - - Updated - - -

I use Sprint Layout for PCB design. Its more friendly to me than anything else. @ milan.
 

If you use 9600 bps baudrate you get 0.16% error in mikroC. So use 9615 bps in mikroC.
 

I found that if the power supply of the module I'm using is kept at 4.8V then it can get the GPS data and can send SMS. Anyway I'm using a breakout board for SIM908. It takes 5V as input. But if I supply 5V then all those troubles occurs. Again if I supply below 4.8V, its trouble again. So its working little bit better than those troubles at 4.8V.

A capture of the data communication right now:
Capture.JPG

You can see that there is some mistakes in reading GPS data. But if the don't initialize SMS, that means I don't use GSM part, it works fine. Can read all the data clearly.

Here is a screen shot:
h.JPG

So it really becoming complex step by step. I used Li-Ion Batteries, DC Lab power supply, PC USB 5V, but all the same result. The most odd result comes if the supply voltage is 5V or greater. Should I try with only the SIM908 module?

I made a breakout board few months ago. As the components made it bulky I didn't used it too far. Also, I found this breakout board in the market at around $62. So I used it. I hope this board is a trouble itself.

DSCN1118.jpg
 

Oh! Your one a good one I think. I didn't got a good module like yours. So I've to work with it. And I badly hanged up with this project. Its taking so much time than I thought. :(
 

Hi,

Did you connect GPS to the second UART?
I mean GSM with his UART and GPS with a second UART?

Dan
 

Not actually. Because SIM datasheet says communication is possible with the same UART. Also it works fine with PC with same UART.
Recently I tested with another SIM module, its working fine. There was a problem at the module I was working with.
 

Is this due to voltage level error?

The module Tx is 0-3.3V max as the datasheet says. But the microcontroller Rx is 0-5V. I think its a voltage level error. So should I use any opto coupler or MAX232?
 

Because of the voltage level issue, this type of error should not occurred, because all of your other AT commands are working well with it. How you are using the same serial port for both gps and gsm? You mentioned some power supply issue in your system? Could you please explain more clearly? And there is an autobaud command for the sim 908 . Pls refer the at command manual
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top