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.

Help me with interfacing PIC18F252 with GSM Modem

Status
Not open for further replies.
Re: Help: Problems on interfacing PIC18F252 with GSM Modem.

Hi,

Connection seems to be ok. Code is also seems to be ok. But do one thing. Put one led to any of the port pin for testing and Check for the ok response for every command like,

putsUSART("AT")
putch(0x0a)
if(getch=='O')
{
if(getch=='K')
{
LED BLINK // ok recevied.
}

Do this thing for every command. You will get to know that where the problem is.

NIKS
 

Re: Help: Problems on interfacing PIC18F252 with GSM Modem.

any reasons why I couldn't get it work? is my code alright?
I configured both to be in 9600,8,n,1,n for the Port Settings.

I need to get it done before I can proceed to others.
 

Re: Help: Problems on interfacing PIC18F252 with GSM Modem.

Code:
#include <p18f252.h>
#include <delays.h>
#include <usart.h>
#include <stdlib.h>
#include <stdio.h>
   
#pragma config OSC = XT						// Configured oscillator as XT
#pragma config WDT = OFF					// Disabled watch dog timer
#pragma config LVP = OFF					// Disabled low voltage programming


unsigned char TxCheck[] = "AT";				// Perform a simple check on the connection
unsigned char TxText[] = "AT+CMGF=1";		// Set short message format as Text mode
unsigned char TxSend[] = "AT+CMGS=";		// Send message to a phone number
unsigned char TxNumber[] = "546879123";		// User phone number	
unsigned char TxExample[] = "abcdef";    	// Example


void main(void)
{   
	// Configure USART
	OpenUSART( USART_TX_INT_OFF  & 
			   USART_RX_INT_OFF  & 
			   USART_ASYNCH_MODE & 
		       USART_EIGHT_BIT 	 & 
		       USART_CONT_RX	 & 
			   USART_BRGH_HIGH,
			   25 );						// Asynchronous mode, high speed: 
											// [Fosc / (16 * Desired Baudrate)] - 1 = [4 MHz / (16 * 9600)] - 1 = 25 (approx.)
	while(1)
	{
		putsUSART((char*)TxCheck);				
		putcUSART(0x0D);					// Pressed Enter Key
		Delay10KTCYx(0);
		if(getcUSART()=='O')
		{
			if(getcUSART()=='K')
			{
				putsUSART((char*)TxText);
				Delay10KTCYx(0);
				break;
			}
		}
		putcUSART(0x0D);
		Delay10KTCYx(0);
		if(getcUSART()=='O')
		{
			if(getcUSART()=='K')
			{
				putsUSART((char*)TxSend);
				Delay10KTCYx(0);
				putcUSART('"');
				Delay10KTCYx(0);
				putsUSART((char*)TxNumber);
				Delay10KTCYx(0);
				putcUSART('"');
				Delay10KTCYx(0);
				break;
			}
		}
		Delay10KTCYx(0);
		putsUSART((char*)TxExample);
		Delay10KTCYx(0);
		putcUSART(0x1A);					// Pressed Ctrl+Z
		Delay10KTCYx(0);
		Delay10KTCYx(0);
		Delay10KTCYx(0);
		Delay10KTCYx(0); 
		Delay10KTCYx(0);
		putcUSART(0x0D);
   	}  

    CloseUSART();   						// Close USART
}

tried this it's still the same. no sms message from the sim card.
 

Re: Help: Problems on interfacing PIC18F252 with GSM Modem.

I changed my code to this but.. it's still not working with GSM Modem but with Hyperterminal it works. Please help me solve my problems. Thanks!

Code:
#include <p18f252.h>
#include <usart.h>
#include <delays.h>

#pragma config OSC = XT						// Configured oscillator as XT
#pragma config WDT = OFF					// Disabled watch dog timer
#pragma config LVP = OFF					// Disabled low voltage programming

void delay(unsigned int n)
{
	while(n--);
}

void main()
{   
	TRISC=0x80;
	TXSTA=0x24;
	RCSTA=0x90;

	OpenUSART(	USART_TX_INT_OFF	&
				USART_RX_INT_OFF	&
				USART_ASYNCH_MODE	&
				USART_EIGHT_BIT		&
				USART_CONT_RX		&
				USART_BRGH_HIGH,
				25	);

	while(1)
	{
		// AT
		TXREG='A';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='T';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG=0x0D;
		while(TXSTAbits.TRMT == 0);
		Delay10KTCYx(0);

		// AT+CMGF=1
		TXREG='A';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='T';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='+';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='C';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='M';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='G';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='F';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='=';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='1';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG=0x0D;
		while(TXSTAbits.TRMT == 0);
		Delay10KTCYx(0);

		// AT+CMGS="87742984"
		TXREG='A';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='T';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='+';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='C';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='M';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='G';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='S';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='=';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='"';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='8';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='7';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='7';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='4';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='2';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='9';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='8';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='4';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='"';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG=0x0D;
		while(TXSTAbits.TRMT == 0);
		Delay10KTCYx(0);

		// abcde
		TXREG='a';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='b';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='c';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='d';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		TXREG='e';
		while(TXSTAbits.TRMT == 0);
		delay(1000);
		Delay10KTCYx(0);
		TXREG=0x1A;
		while(TXSTAbits.TRMT == 0);
		Delay10KTCYx(0);
		Delay10KTCYx(0);
		Delay10KTCYx(0);
		TXREG=0x0D;
		while(TXSTAbits.TRMT == 0);
		Delay10KTCYx(0);
	}
	
	CloseUSART();
}
 

Re: Help: Problems on interfacing PIC18F252 with GSM Modem.

Hi,

In your code when you need to give enter, you have given 0x0d.. Try with 0x0a and then 0x0d. For example, call a function like given below to give enter to every commands..


void ENTER()
{
uart_putc(0x0A);
uart_putc(0x0D);
}

NIKS
 

Re: Help: Problems on interfacing PIC18F252 with GSM Modem.

Nikunj Tanna said:
Hi,

In your code when you need to give enter, you have given 0x0d.. Try with 0x0a and then 0x0d. For example, call a function like given below to give enter to every commands..


void ENTER()
{
uart_putc(0x0A);
uart_putc(0x0D);
}

NIKS

okay i'll try it.

Added after 2 hours 39 minutes:

i tried yr method, remove the putcUSART(0x0D) that I had in my main statement and replaced it with enter();

it's okay on hyperterminal but gsm modem didnt get the message in the sim card.

Added after 38 minutes:

It's got to do with the RS-232 serial link cable of the modem to check the sequence i.e DTR or something etc. Or the timing diagram for RS-232?
 

Problem with Hyperterminal

Hello,

Could you help me out. I am using Windows XP, but the hperterminal does not give the 'OK' when I connect the modem and enter 'AT.' Why could this be?

Thanks
 

Re: Problem with Hyperterminal

mathewkyle said:
Hello,

Could you help me out. I am using Windows XP, but the hperterminal does not give the 'OK' when I connect the modem and enter 'AT.' Why could this be?

Thanks

did you power up your modem? is the modem in the correct COM port either 1 or 2.

in the hyperterminal select the COM port that you have your modem connected to.
see your modem settings in the manual for the baud rate, data bits, parity, stop bits, flow control. for mine is 115200bps,8,none,1,hardware.
 

Re: Problem with Hyperterminal

mathewkyle said:
Hello,

Could you help me out. I am using Windows XP, but the hperterminal does not give the 'OK' when I connect the modem and enter 'AT.' Why could this be?

Thanks


Check the RS232 cable first.... if its working fine then proceed..also check the setting of the Modem
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top