| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| pathmasugu 
 
 
 Joined: 21 Feb 2014
 Posts: 25
 
 
 
			            
 
 | 
			
				| Problem in receiving data from GSM |  
				|  Posted: Sun Mar 30, 2014 9:58 am |   |  
				| 
 |  
				| Hi I have problem in receiving data from gsm. I'm using sim 300 module.
 I tested my gsm in hyperterminal, its working fine. But in project board i have received what command i send.   Please someone help me.
 
 Note,
 before i referred  gsm driver from Gabriel.
 
 My hyperterminal output:
 
  	  | Code: |  	  | AT
 
 
 OK
 
 AT+CMGF=1
 
 
 OK
 
 AT+CNMI=2,1,0,0
 
 
 OK
 
 
 
 +CMTI: "SM",3
 
 AT+CMGR=3
 
 
 +CMGR: "REC UNREAD","+911111115343",,"14/03/30,21:08:18+22"
 
 Dfbgbjf
 
 
 
 OK
 
 AT+CMGD=1
 
 
 OK
 
 AT+CMGD=
 
 +CMTI: "SM",1
 
 2
 
 
 OK
 
 AT+CMGD=3
 
 
 OK
 
 AT+CMGR=1
 
 
 +CMGR: "REC UNREAD","+9111111343",,"14/03/30,21:09:15+22"
 
 Hgththtg
 
 
 
 OK
 
 
 
 +CMTI: "SM",2
 
 AT+CMGR=2
 
 
 +CMGR: "REC UNREAD","+911111115343",,"14/03/30,21:10:13+22"
 
 Fdhcvj
 
 
 
 OK
 
 
 
 +CMTI: "SM",3
 
 | 
 My testing code:
 
  	  | Code: |  	  | #include <18F452.h>
 #use delay(clock=20000000)
 #Fuses HS
 #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=GSM,errors)
 #byte portb=0xf81
 #byte trisb=0xf93
 #byte porta=0xf80
 #byte trisa=0xf92
 #BYTE TRISC=0XF94
 #include "flex_lcd.c"
 
 #define buff 70
 char gsm_rx[buff+1];
 char count_wr=0;
 
 #int_rda
 void serial_rx_isr()
 {
 gsm_rx[++count_wr]=getch(GSM);
 }
 
 void comm_check()
 {
 lcd_gotoxy(1,1);
 lcd_putc("COMP CHECK");
 printf("AT");                //send command
 putchar(0x0D);
 delay_ms(2000);
 }
 
 
 void main()
 {
 int i;
 trisb=0;
 trisa=0x01;
 TRISC=0x80;
 DELAY_MS(100);
 lcd_init();
 
 enable_interrupts(GLOBAL);
 enable_interrupts(INT_RDA);
 
 while(1)
 {
 comm_check();
 delay_ms(2000);
 
 if(count_wr>1)
 {
 lcd_gotoxy(1,2);
 for(i=0;i<8;i++)
 {
 lcd_putc(gsm_rx[i]);
 }
 delay_ms(5000);
 count_wr=0;
 lcd_init();
 }
 }
 }
 
 | 
 _________________
 ROCK RAJ
 |  |  
		|  |  
		| ezflyr 
 
 
 Joined: 25 Oct 2010
 Posts: 1019
 Location: Tewksbury, MA
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Mar 31, 2014 6:36 am |   |  
				| 
 |  
				| Hi Pathmasugu, 
 I'm a bit reluctant to even get into this thread because your code has so many 'oddities', and 'inconsistencies' that it suggests you aren't studying the forum archives, or reading the documentation.....
 
 Anyway.....  First of all, are you sure, absolutely sure that your PIC is running, and running at the correct speed? Let's just say that a single Fuse (!) declaration is a bit 'suspicious'! To check, connect an LED to an unused I/O pin (with a suitable current limiting resistor), and add this code to the top of Main():
 
 
  	  | Code: |  	  | // Here we blip the Power LED at power-up to show that the interface is working
 for ( iIndex = 0 ; iIndex < 3 ; iIndex++ )
 {
 output_high(PWR_LED);
 delay_ms(500);
 output_low(PWR_LED);
 delay_ms(500);
 }
 
 // Here we leave the Power LED ON
 output_high(PWR_LED);
 
 | 
 
 Your 'PWR_LED' should turn On for 1/2 second, and Off for 1/2 second. Does it?
 
 Why all the #byte definitions in your code? Get rid of them!
 
 Why are you manually trying to manipulate the TRIS registers? Get rid of all that!
 
 You are using 'getch(stream)' to fetch a character from the hardware UART. I don't use that function, so I don't know if it's OK or not, but the CCS manual defines 'fgetc(stream)' as the proper function to use. Use it!
 
 Your buffer definition is a bit 'odd'. It will work, but it's non-standard. Also, your buffer has no 'overflow' protection, so if you exceed the allotted space then you'll start to overwrite other areas of memory. Here are some code snippets to help you with that...
 
 
  	  | Code: |  	  | 
 #define RX_SIZE 10            // RS232 buffer for serial reception
 char RxBuffer[RX_SIZE];       // RS232 serial RX buffer
 int Index = 0;              // RS232 RX data IN index
 
 // Save the character to the receive buffer.
 RxBuffer[Index]=temp;
 
 // Check for buffer overflow.
 if ( Index >= (RX_SIZE - 1) )
 Index = 0;
 else
 Index++;
 
 | 
 
 You should be using printf to send data to the LCD by re-directing using lcd_putc. This is a much more flexible and powerful method.
 
 
  	  | Code: |  	  | printf(lcd_putc, "COMP CHECK\n\r");
 
 | 
 
 You've defined a stream, 'GSM', but you aren't using it consistently. Use this line instead:
 
 
  	  | Code: |  	  | fprintf(GSM, "AT\r");                //send command "AT" plus <CR>.
 
 | 
 
 Likewise, in Main(), use printf to display received characters:
 
 
  	  | Code: |  	  | printf(lcd_putc, "Rcv. Char.: %c\n\r", gsm_rx[i]);
 
 | 
 
 I haven't even addressed the design of your code, which is poor, or whether it might even work as intended, but this initial clean-up is necessary before anything else.....
 
 John
 |  |  
		|  |  
		|  |  
  
	| 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 
 |  
 Powered by phpBB © 2001, 2005 phpBB Group
 
 |