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] Interfacing GSM using AT89S52, C Program

Status
Not open for further replies.

apache79

Newbie level 6
Joined
Mar 4, 2012
Messages
14
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,387
Hi,

I am using the MC to accept and transmit the data serially. I have used port 1 as the dataport for lcd and 3 pins of port 2 as command lines for lcd. I am using the baud rate as 9600.

Now the problem is that whenever I send any ASCII codes from the computer to the MC or vice versa, the codes get changed.

For example,

for ascii codes 0 to 47 (decimal) the codes increments by 32. i.e 0 to 47 becomes, 32 to 79 (decimal)
but from 48 (decimal), the code gets incremented by 64. i.e 48 becomes 112, 49 becomes 113 n so on


Any help on the above matter will be highly appreciated,

Thank You
 

One common bug in RS232 communication with PC, is not matched baudrates. So verify that the baudrate from PC's side is the same as the baudrate from MCU's side. Since you are getting wrong characters in hyperterminal, this could be a possible reason.

Check the setting of com port at device manager of windows XP (I dont know if you use XP)
--------------------------------------------------------------------------------
On thing : Your thread heading does not match with the content
 
Sorry about the heading, I am a new member so didnt realize it, will keep in mind next time.

Thanks for the reply.

I had set the GSM at 9600 baud rate and in the program i had mentioned 0xfd for 9600 baud rate. Still I am getting the problem, What could be the problem, please guide.

Thanks
 

Check the ground connection. Since you are receiving characters, it appears that the problem is with the settings.
Try budrate higher than 9600.

Make sure:
Pairty: None
Stopbit:1
Flow control:None
Publish the code. What is TMOD,SCON,TH1,L1 and TR1 settings.

---------- Post added at 01:20 ---------- Previous post was at 01:18 ----------

After making change at PCs side, reboot and try
 
I have initialized the Serial Port as follows,

TMOD=0x20;
TH1=0xfd;
SCON=0x50;
TR1=1;

We didnt use L1
 


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
#include<8051.h>
#include<delay.c>
void sendx(unsigned char x);
 
main(){
TMOD=0x20;
TH1=0xFA;
SCON=0x50;
TR1=1;
 
while(1){
sendx('a');
sendx('b');
sendx('c');
sendx('A');
sendx('B');
sendx('C');
}
}
 
void sendx(unsigned char x){
SBUF=x;
while(TI==0);
TI=0;
DelayMs(200);
}


Try this. Its working on my hardware.(from Mazidi)

---------- Post added at 01:46 ---------- Previous post was at 01:33 ----------

What is the frequency of your crystal?
 
Last edited:
Our Crystal is 12 MHz.

Thank You for your help.
 

Thanks, Mazidi says to use 11.092MHz osscilator. We are using 12MHz. We have put TH1 as -3(decimal).

We tried the calculations and we get the answer as 11.0592.

Can we use a 11MHz oscillator if we don't get the 11.0592?

Thank You for your help.

---------- Post added at 15:20 ---------- Previous post was at 14:21 ----------

Thanks, Mazidi says to use 11.092MHz osscilator. We are using 12MHz. We have put TH1 as -3(decimal).

We tried the calculations and we get the answer as 11.0592.

Can we use a 11MHz oscillator if we don't get the 11.0592?

Thank You for your help.
 

see Setting the Serial Port Baud Rate at **broken link removed**
Thanks for the helpful ratings
 
Thank You Sir, the problem was with the baud rate, the oscillator we were using was a 12MHz one, we tried with a 11.0592Mhz and it worked fine when connected to the hyperterminal.

When we tried the same thing on the GSM Module, but it didnt generate a call. We are connecting Pin 2 for Tx, Pin 3 for Rx and Pin 5 for ground, these are the only three connections we are doing with the RS232 and the MAX232.

Is there anything we are doing wrong? Should we connect some other pins of the RS232?

Thank You for your help.
 

Ok now your "PC--Serial port--Micro " is working.

Now what is not working? PC to GSM connection?

I dont know the GSM module type you are using.
There are cases where GSM modules have a software modem and can not be controlled with any Terninal software (like Hyper Terminal) directly. You have to use the soft modem driver/software of your module. Check manual first
 
Now the AT commands from the program is being displayed without any error in the HyperTerminal window. But when we connected the microcontroller to the GSM module. so that the module gets the AT commands and generate the call, then the call isnt being generated.

We are using the SIMCOM300 GSM module.

Is the problem occuring due to some connection problem with the RS232?
 

We want to send AT Command ATD+ (Mobile Number), We tried sending this command through the HyperTerminal and it generated a successful call. Then we also took the output from the uC and got it displayed on the HyperTerminal, which gave us the output as ATD+ (Mobile Number), which is the desired output.

But when we connected the GSM module to the uC and tried giving the output to the Module, it failed to generate a call.

I am attaching the part where we are sending the AT command to the GSM Module,

Code:
init_serial();
	transmit_data('A');	  				// Transmit 'A' to serial port
	delay(1);
	
	transmit_data('T');	 				// Transmit 'T' to serial port
	delay(1);
	transmit_data(0x0d); 					// Transmit carriage return to serial port
	delay(500);
	lcd_cmd(0x01);
	lcd_data_string("Calling Rizvi");
	delay(100);

	lcd_cmd(0xC0);	 
	lcd_data_string("ATD+ 96892587929");
	delay(100);							// Initialize LCD
	lcd_cmd(0x01);							// Initialize serial port
	

	transmit_data('A');	  				// Transmit 'A' to serial port
	delay(1);
	
	transmit_data('T');	 				// Transmit 'T' to serial port
	delay(1);

	transmit_data('D');	  				// Transmit 'D' to serial port
	delay(1);
	
	transmit_data('+');	  				// Transmit '+' to serial port
	delay(1);

	transmit_data(32);	  				// Transmit Space to serial port
	delay(1);

	transmit_data('9');	  				// Transmit '9' to serial port
	delay(1);

	transmit_data('1');	  				// Transmit '1' to serial port
	delay(1);

	transmit_data('1');	  				// Transmit '1' to serial port
	delay(1);

	transmit_data('9');	 				// Transmit '9' to serial port
	delay(1);
	
	transmit_data('2');	  				// Transmit '2' to serial port
	delay(1);
	
	transmit_data('2');	 				// Transmit '2' to serial port
	delay(1);
	
	transmit_data('8');	  				// Transmit '8' to serial port
	delay(1);
	
	transmit_data('3');	 				// Transmit '3' to serial port
	delay(1);
	
	transmit_data('9');	  				// Transmit '9' to serial port
	delay(1);
	
	transmit_data('2');	 				// Transmit '2' to serial port
	delay(1);
	
	transmit_data('2');	  				// Transmit '2' to serial port
	delay(1);

	transmit_data(';');	  				// Transmit ';' to serial port
	delay(1);

	transmit_data(0x0d);  					// Transmit carriage return to serial port
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	delay(500);
	
	lcd_cmd(0x80);
	lcd_cmd(0x01);
	lcd_data_string("Disconnecting");
	delay(100);
	transmit_data('A');	 				// Transmit 'A' to serial port
	delay(1);
	transmit_data('T');	  				// Transmit 'T' to serial port
	delay(1);
	transmit_data('H');	 				// Transmit 'H' to serial port
	delay(1);
	transmit_data(0x0d); 
	lcd_cmd(0xC0);
	lcd_data_string("DISCONNECTED");
	while(1);
}
 

The cable by which you interface your GSM module with HyperTerminal is different
The cable by which you interface your GSM module with microcontroller will be different

---------- Post added at 12:23 ---------- Previous post was at 12:16 ----------

The cable that you use with GSM module and with Hyper Terminal has no cross over connection, but when GSM module and micro will be communicating, RTS and CTS pins should be short at the GSM module side, additionally TX and RX must be swap.

---------- Post added at 12:26 ---------- Previous post was at 12:23 ----------

Autobauding option is another PROBLEM with communication, when autobauding is enabled, the GSM uses other pins for communications rather than just TX,RX which create another issues.So what you have to do, is that make baud rate constant of your GSM module, there will be AT command for doing this, after this YOU JUST SAVE THIS INFORMATION INTO THE GSM MODULE FLASH.Or else, you still won't be getting the correct results.There are so many little things, that are necessary for making successfull communication.

For idea:-

1. Connect Modem to PC and start your terminal
2. Change Flow Control by typing "AT+IFC=1,1"
3. Save config with "AT&W"
4. Change baud rate from auto into your desired baud rate. e.g. 19200 by sending "AT+IPR=19200"
5. Save config with "AT&W"
6. Short RTS and CTS at Sim300

Hope that helps.
 
Thank You Sir, I feel this is the problem, We will do as per your advice and check if it works correctly.

Thank You for you invaluable Help and Guidance
 

Thank You Sir, It has started Working, Thanks for the Help.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top