[PIC] Need a help on PIC18f4550 and SIM300S

Status
Not open for further replies.

blackpearl87

Newbie level 5
Joined
Jun 8, 2014
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
91
Hi all, I'm interfacing sim300s with pic18f4550. I wrote the below program with some online help. But so far I couldn't get any result. I tried connecting the modem to picdem 2 plus demo board (where pic18f4550 is mounted), but it doesn't seem to be working.

Is there any other way that I can get a TTL output from sim300s (since the gsm modem also has a max232 on board)? So I can directly connect the output to the Tx and Rx pins of MCU.

Does anyone have a circuit diagram of sim300s?

Please help me to find if there's any error in the program.

Thank you everyone in advance



Code:
/********************************************************************/

#include "Lcd.h"
#include "General.h"
#include "DisplayMacros.h"

#include <p18f4550.h>
#include <delays.h>
	

#define FREQ 		12000000
#define BAUD 		9600
#define SPBRG_VALUE (((FREQ/64)/BAUD)-1)
#define PB1	PORTAbits.RA4
#define PB2	PORTBbits.RB0


void Wait2s(void);					///< 2s delay used to display splash screen
void Wait1s(void);

void DisplaySplashText(void);				      ///< Display the welcome Text
void StateInitial(void);					           ///< Go to initial state

void gsmCode(void);
/*void gsmInit(void);
void gpsCode(void);
void gpsInit(void); */

unsigned char rx_data(void);
void tx_data(unsigned char);
void gsm_cmd(unsigned char *);
void output(void);
void interrupt(void);


unsigned char value = 0;
int i = 0,j,k,temp,flag;
unsigned char *starting_text = "Enter Choice =";
unsigned char *dial_text = "Dialing...";
unsigned char *at_cmd = "AT";
unsigned char *imei_cmd = "AT+GSN";
unsigned char *call_cmd = "ATDxxxxxxxxxx"; // Provide a 10-Digit Mobile Number
unsigned char *sms_format = "AT+CMGF=1";
unsigned char *sms_write = "AT+CMGS=\"xxxxxxxxxx\""; // 10-Digit Mobile Number
unsigned char *sms = "Hello";
unsigned char *sms_report = "SMS Sent...";
unsigned char sms_terminate = 0x1A;
unsigned char enter = 0x0D;

unsigned char *data;

unsigned char longi_data[12];
unsigned char lati_data[12];

void main(void)
{ 
  TRISA = 0xFF;
  TRISB = 0xF1;
  TRISC = 0x80;
  TRISD = 0x00;
  SPBRG = SPBRG_VALUE; 		// Fill SPBRG register to set the baud rate
  RCSTAbits.SPEN = 1; 		// To activate serial port (Tx and Rx pins)
  TXSTAbits.TXEN = 1; 		// Activate Transmissiom
  RCSTAbits.CREN = 1; 		// Activate Reception
  PIE1bits.RCIE = 1; 		// Enable Reception interrupt
  INTCONbits.GIE = 1;       // Peripheral Interrupt enable
  INTCONbits.PEIE = 1;      // General Interrupt enable
  
  LATA = 0; LATB = 0; LATC = 0; LATD = 0; 
  LCDInit();
 
  gsmCode();
  
}	// End of main function


void gsmCode(void)
{
  while(1)		// Main Infinite loop
  {                 
	StateInitial();

	if(!PB1)
	{
		PORTBbits.RB1 = 1;
		gsm_cmd(at_cmd);
		output();
		Wait1s();
	}	

	if(!PB2)
	{
		LATB = 0;
		PORTBbits.RB2 = 1; 
		gsm_cmd(sms_format);
		output(); 
		Wait1s();
	
		gsm_cmd(sms_write);
		output();
		Wait1s();

		gsm_cmd(sms);
		output();
		tx_data(sms_terminate);  // Send ASCII code for 'Ctrl+z' key
		Wait1s();
	}
  }		// Main infinite loop
}


void gsm_cmd(unsigned char *string)
{
i = 0; j = 0; temp = 0;
while(string[i] != '\0')
{
temp = 0;
if(string[i] == 0x5C) // Not to send '\' character
i++;
tx_data(string[i]); // Send by serial communication
i++;
while(temp != 1);
}
tx_data(enter); // Send ASCII code for 'Enter' key
interrupt();
while(temp != 1);
}


void output(void) // To print data on LCD
{
i = 0; flag = 0;  
LCDClear();		// Clear LCD for next display
while(i < j)
{
if(flag > 1)
{
flag = 0;
Delay10KTCYx(10);	// 500ms delay
LCDClear();		// Clear LCD for next display
LCDGoto(0,0);
}

/* This condition is to avoid double Enter during execution of a command */
if(data[i] == 0x0A)
{
flag++;
LCDGoto(0,1);
}

/* Not to print this character */
if(data[i]=='>' || data[i]=='"') 
{
i++;
LCDGoto(0,1);
}

/* Condition to print the data, except 'Enter','New line' and 'Submit' */
if(data[i]!=0x0D && data[i]!=0x0A && data[i]!=0x1A) 
{
LCDPutChar(data[i]);
i++;
}
else
i++;

Delay10KTCYx(6);	// 300ms delay
}

LCDClear();		// Clear LCD for next display
}


void tx_data(unsigned char serial_data) // Transmit data function
{
  TXREG = serial_data;
  while(PIR1bits.TXIF == 0);
}


void interrupt(void)
{
data[j] = RCREG; // Store the data into array when Reception interrupt occurs
value = data[j];
j++;
temp = 1;
}


void StateInitial(void)
{
	DisplaySplashText();                // Welcome message
	Wait2s();                  			// Leave splash screen for 2 s
}


void DisplaySplashText(void)
{
  	LCDClear();
	WELCOME();
}


void Wait2s(void)
{
	Delay10KTCYx(40);
}

void Wait1s(void)
{
	Delay10KTCYx(20);
}
 

does anything display on the LCD?
have you checked the baudrate by connecting the SIM300 to a PC?

by using polled UART receive you are probably loosing data while you transmit the AT commands and you will get receive overrun on the UART

it is recommended to interrupt drive the UART receiver with received charcaters placed in a ring buffer
 

hi horace1, when i press the first push button (PB1), just one character is displayed (don't know what it is) and when press the second push button (PB2), the same character is displayed for three times.

according to the code, when i press PB1, pic controller should send the AT command and receive 'OK', instead of any other character. the same goes for the PB2. (set the format and number, send the sms) but so far, i only tried connecting the sim300s DB9 output to the demo board DB9 (RS232). im not sure my program is coded for rs232 interfacing, and i have no idea how to do it, even though i've heard about uart, usart....etc.

my question is, is there anyway i can get a TTL output from sim300s, so that i can connect directly to the Rx and Tx pins of the pic controller?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…