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.

Serial Monitor to check feedback of GSM Sim900a

Status
Not open for further replies.

electronicnoob

Junior Member level 1
Joined
Jul 4, 2019
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
142
Hey guys, Im trying to interface the GSM Sim900a module with my PIC16F887 microcontroller. I have trouble with the connection of the GSM so I tried to use serial monitoring to check for feedback. I am currently using the Arduino Ide for serial monitoring.

Annotation 2020-05-18 210758.jpg

After typing AT command, it is supposed to reply OK but replies AT instead
Please help. Thank you.
 

Hi,

maybe the error is in line 223 of your code. I don´t know.
How can we help?

Klaus
 

This is my code I used to enable user to type their phone number using a matrix keypad.
Code:
#include <stdio.h>
#include <stdlib.h>
#include "config.c"
 
//LCD module connections
#define LCD_RS       RD0
#define LCD_EN       RD1
#define LCD_D4       RD2
#define LCD_D5       RD3
#define LCD_D6       RD4
#define LCD_D7       RD5
#define LCD_RS_DIR   TRISD0
#define LCD_EN_DIR   TRISD1
#define LCD_D4_DIR   TRISD2
#define LCD_D5_DIR   TRISD3
#define LCD_D6_DIR   TRISD4
#define LCD_D7_DIR   TRISD5
//End LCD module connections
 
//matrix keypad connections
#define X_1    RB0
#define X_2    RB1
#define X_3    RB2
#define X_4    RB3
#define Y_1    RB4
#define Y_2    RB5
#define Y_3    RB6
#define Y_4    RB7
#define Keypad_PORT          PORTB
#define Keypad_PORT_Direction     TRISB   

void InitKeypad(void);
char switch_press_scan(void);

 
#include <xc.h>
#define _XTAL_FREQ 8000000
#include <stdint.h>        // include stdint header
#include "LCD_Lib.c"       // include LCD driver source file
 

/******************* Matrix keypad Functions *******************/
// Function declarations
void InitKeypad(void);
char switch_press_scan(void);
char switch_press_scan_num(void);
void InitKeypad(void)
{
	Keypad_PORT	    = 0x00;    // Set Keypad port pin values zero
    ANSELH = 0; 
	Keypad_PORT_Direction = 0xF0;	// Last 4 pins input, First 4 pins output
	nRBPU  = 0;                     // clear RBPU bit (OPTION_REG.7)
    OPTION_REG &= 0X7F;
    WPUB   = 0xF0;            // WPUB register = 0b11110000
}


char keypad_scanner(void)
{
    PORTB = 0X0E;  // PORTBbits -> 0000001, D0 is high
    if      ((Y_1 == 0)&&(X_1 == 0))  {return '1';}             // S1  is pressed    
    else if ((Y_2 == 0)&&(X_1 == 0))  {return '2';}             // S2  is pressed     
    else if ((Y_3 == 0)&&(X_1 == 0))  {return '3';}             // S3  is pressed            
    else if ((Y_4 == 0)&&(X_1 == 0))  {return 'A';} 			// S4  is pressed
    

    PORTB = 0X0D;  // PORTBbits -> 00000010, D1 is high
    if      ((Y_1 == 0)&&(X_2 == 0))  {return '4';}             // S5  is pressed    
    else if ((Y_2 == 0)&&(X_2 == 0))  {return '5';} 			// S6  is pressed    
    else if ((Y_3 == 0)&&(X_2 == 0))  {return '6';} 			// S7  is pressed   
    else if ((Y_4 == 0)&&(X_2 == 0))  {return 'B';} 			// S8  is pressed
    
 
    PORTB = 0X0B;  // PORTBbits -> 00000100, D2 is high
    if      ((Y_1 == 0)&&(X_3 == 0))  {return '7';} 			// S9  is pressed
    else if ((Y_2 == 0)&&(X_3 == 0))  {return '8';} 			// S10 is pressed
    else if ((Y_3 == 0)&&(X_3 == 0))  {return '9';} 			// S11 is pressed
    else if ((Y_4 == 0)&&(X_3 == 0))  {return 'C';} 			// S12 is pressed

  
    PORTB = 0X07;  // PORTBbits -> 00001000, D3 is high
    if      ((Y_1 == 0)&&(X_4 == 0))  {return '*';} 			// S13 is pressed
    else if ((Y_2 == 0)&&(X_4 == 0))  {return '0';} 			// S14 is pressed
    else if ((Y_3 == 0)&&(X_4 == 0))  {return '#';} 			// S15 is pressed
    else if ((Y_4 == 0)&&(X_4 == 0))  {return 'D';} 			// S16 is pressed
  
    return 'n';  
}

char keypad_scanner_num(void)
{
    PORTB = 0X0E;  // PORTBbits -> 0000001, D0 is high
    if      ((Y_1 == 0)&&(X_1 == 0))  {return '1';}             // S1  is pressed    
    else if ((Y_2 == 0)&&(X_1 == 0))  {return '2';}             // S2  is pressed     
    else if ((Y_3 == 0)&&(X_1 == 0))  {return '3';}             // S3  is pressed            
    else if ((Y_4 == 0)&&(X_1 == 0))  {return 'n';} 			// S4  is pressed
    

    PORTB = 0X0D;  // PORTBbits -> 00000010, D1 is high
    if      ((Y_1 == 0)&&(X_2 == 0))  {return '4';}                     // S5  is pressed    
    else if ((Y_2 == 0)&&(X_2 == 0))  {return '5';} 			// S6  is pressed    
    else if ((Y_3 == 0)&&(X_2 == 0))  {return '6';} 			// S7  is pressed   
    else if ((Y_4 == 0)&&(X_2 == 0))  {return 'n';} 			// S8  is pressed
    
 
    PORTB = 0X0B;  // PORTBbits -> 00000100, D2 is high
    if      ((Y_1 == 0)&&(X_3 == 0))  {return '7';} 			// S9  is pressed
    else if ((Y_2 == 0)&&(X_3 == 0))  {return '8';} 			// S10 is pressed
    else if ((Y_3 == 0)&&(X_3 == 0))  {return '9';} 			// S11 is pressed
    else if ((Y_4 == 0)&&(X_3 == 0))  {return 'n';} 			// S12 is pressed

  
    PORTB = 0X07;  // PORTBbits -> 00001000, D3 is high
    if      ((Y_1 == 0)&&(X_4 == 0))  {return 'n';} 			// S13 is pressed
    else if ((Y_2 == 0)&&(X_4 == 0))  {return '0';} 			// S14 is pressed
    else if ((Y_3 == 0)&&(X_4 == 0))  {return '#';} 			// S15 is pressed
    else if ((Y_4 == 0)&&(X_4 == 0))  {return 'n';} 			// S16 is pressed
  
    return 'n';  
}

// Read pressed key value from keypad and return its value
char switch_press_scan(void)           	 // Get key from user
{
	char key = 'n';              // Assume no key pressed

	while(key=='n')              // Wait until a key is pressed
		key = keypad_scanner();   // Scan the keys again and again

	return key;                  //when key pressed then return its value
}

char switch_press_scan_num(void)           	 // Get key from user
{
	char key = 'n';              // Assume no key pressed

	while(key=='n')              // Wait until a key is pressed
		key = keypad_scanner_num();   // Scan the keys again and again

	return key;                  //when key pressed then return its value
}

/**************** end matrix keypad functions ******************/

/********************* GSM UART Functions **********************/
void InitGSM();
void sms(unsigned char *msg);
void tx(char a);
unsigned char rx(void);
void tx_str(const char *s);
char phoneno[10];

void InitGSM(){
    TRISCbits.TRISC6 = 0; //Set RC6 (TX) as output
    TRISCbits.TRISC7 = 1; //Set RC7 (RX) as input
    TXSTA = 0b00100100; //Refer one note
    RCSTA = 0b10010000; //Refer one note
    SPBRG = 10; 
    TXIF = RCIF = 0; //Disable interrupt(For reseting purpose)
}

void sms(unsigned char *msg){
    tx_str("AT\r\n"); 
    __delay_ms(500);
    
    tx_str("AT+CMGF=1\r\n"); //Enter GSM SMS TEXT MODE
    __delay_ms(500);
    
    tx_str("AT+CMGS="); //SEND SMS to Phone number
    tx('"');
    
    for(int l = 0; l <= 9; l++){
        tx(phoneno[l]); //Enter phone number with size 10 array
    }
    
    tx('"');
    tx_str("\r\n"); //After enter will be entering SMS
    __delay_ms(1000);
    
    while(*msg)
        tx(*msg++); //Send SMS
    tx(0x1A); //CTRL Z ASCII code to send
    __delay_ms(500);
}

void tx(char a) //Function to send one byte of data to UART
{
 while(TXIF==0) continue; //Hold the program until TX buffer is free to transmit
	TXREG=a; 
}

unsigned char rx(void){
    while(PIR1bits.RCIF == 0); //Hold the program until RX buffer is free to receive
    return RCREG;
}

void tx_str(const char *s) //Function to convert string to byte
{
 while(*s)
	tx(*s++);
}

/******************* end GSM UART Functions ********************/



void main(void)
{
    int a,b;
    a = b = 0;
    static char PHnum[11];
    char Key = 'n';
    
    LCD_Begin(); 
    InitKeypad();
    
    LCD_Cmd(LCD_CLEAR);
    LCD_Print("Enter Phone No.");
    while(a<10){
        Key = switch_press_scan_num();
        if ((Key == '#')&&(t>0))
        {   
            PHnum[a-1]=" ";
            LCD_Goto(1, 2);
            LCD_Printr(PHnum);
            __delay_ms(200);
            t--;
        }
        else if (Key != '#')
        {
            LCD_Goto(1, 2);
            PHnum[a] = Key;
            LCD_Printr(PHnum);
            __delay_ms(200);
            a++;
        }
    };
    while (b<10){
        phoneno[b]=PHnum[b];
        b++;
    }
    sms("Hello World");
}
however, Im not sure about the TXSTA and RCSTA register as well as the SPBRG value. Can you help me with it?

the lcd library I used
Code:
#pragma warning disable 520

#include <stdint.h>

#define LCD_FIRST_ROW          0x80
#define LCD_SECOND_ROW         0xC0
#define LCD_THIRD_ROW          0x94
#define LCD_FOURTH_ROW         0xD4
#define LCD_CLEAR              0x01
#define LCD_RETURN_HOME        0x02
#define LCD_ENTRY_MODE_SET     0x04
#define LCD_CURSOR_OFF         0x0C
#define LCD_UNDERLINE_ON       0x0E
#define LCD_BLINK_CURSOR_ON    0x0F
#define LCD_MOVE_CURSOR_LEFT   0x10
#define LCD_MOVE_CURSOR_RIGHT  0x14
#define LCD_TURN_ON            0x0C
#define LCD_TURN_OFF           0x08
#define LCD_SHIFT_LEFT         0x18
#define LCD_SHIFT_RIGHT        0x1E

#ifndef LCD_TYPE
   #define LCD_TYPE 2           // 0=5x7, 1=5x10, 2=2 lines
#endif

__bit RS;

void LCD_Write_Nibble(uint8_t n);
void LCD_Cmd(uint8_t Command);
void LCD_Goto(uint8_t col, uint8_t row);
void LCD_PutC(char LCD_Char);
void LCD_Print(char* LCD_Str);
void LCD_Printr(const char* LCD_Str);
void LCD_Begin();

void LCD_Write_Nibble(uint8_t n)
{
  LCD_RS = RS;
  LCD_D4 = n & 0x01;
  LCD_D5 = (n >> 1) & 0x01;
  LCD_D6 = (n >> 2) & 0x01;
  LCD_D7 = (n >> 3) & 0x01;

  // send enable pulse
  LCD_EN = 0;
  __delay_us(1);
  LCD_EN = 1;
  __delay_us(1);
  LCD_EN = 0;
  __delay_us(100);
}

void LCD_Cmd(uint8_t Command)
{
  RS = 0;
  LCD_Write_Nibble(Command >> 4);
  LCD_Write_Nibble(Command);
  if((Command == LCD_CLEAR) || (Command == LCD_RETURN_HOME))
    __delay_ms(2);
}

void LCD_Goto(uint8_t col, uint8_t row)
{
  switch(row)
  {
    case 2:
      LCD_Cmd(LCD_SECOND_ROW + col - 1);
      break;
    case 3:
      LCD_Cmd(LCD_THIRD_ROW  + col - 1);
      break;
    case 4:
      LCD_Cmd(LCD_FOURTH_ROW + col - 1);
    break;
    default:      // case 1:
      LCD_Cmd(LCD_FIRST_ROW  + col - 1);
  }

}

void LCD_PutC(char LCD_Char)
{
  RS = 1;
  LCD_Write_Nibble(LCD_Char >> 4);
  LCD_Write_Nibble(LCD_Char );
}

void LCD_Print(char* LCD_Str)
{
  uint8_t i = 0;
  RS = 1;
  while(LCD_Str[i] != '\0')
  {
    LCD_Write_Nibble(LCD_Str[i] >> 4);
    LCD_Write_Nibble(LCD_Str[i++] );
  }
}

void LCD_Printr(const char* LCD_Str)
{
  uint8_t i = 0;
  RS = 1;
  while(LCD_Str[i] != '\0')
  {
    LCD_Write_Nibble(LCD_Str[i] >> 4);
    LCD_Write_Nibble(LCD_Str[i++] );
  }
}

void LCD_Begin()
{
  RS = 0;

  LCD_RS     = 0;
  LCD_EN     = 0;
  LCD_D4     = 0;
  LCD_D5     = 0;
  LCD_D6     = 0;
  LCD_D7     = 0;
  LCD_RS_DIR = 0;
  LCD_EN_DIR = 0;
  LCD_D4_DIR = 0;
  LCD_D5_DIR = 0;
  LCD_D6_DIR = 0;
  LCD_D7_DIR = 0;

  __delay_ms(40);
  LCD_Cmd(3);
  __delay_ms(5);
  LCD_Cmd(3);
  __delay_ms(5);
  LCD_Cmd(3);
  __delay_ms(5);
  LCD_Cmd(LCD_RETURN_HOME);
  __delay_ms(5);
  LCD_Cmd(0x20 | (LCD_TYPE << 2));
  __delay_ms(50);
  LCD_Cmd(LCD_TURN_ON);
  __delay_ms(50);
  LCD_Cmd(LCD_CLEAR);
  __delay_ms(50);
  LCD_Cmd(LCD_ENTRY_MODE_SET | LCD_RETURN_HOME);
  __delay_ms(50);
}
 

Hi,

How is COM7 of your PC (?) connected to your SIM900?

A simple drawing could help.

Klaus
 

oh sorry, I forgot to mention that I am using a PL2303 USB to TTL Module to connect my PC to the GSM Sim900a module. The only connections used are cross connection between the Tx and Rx as well as power and ground
 

Hi,

did you verify that the signal voltage levels match?

Klaus
 

It's not possible to achieve 115k baud rate with 16F887 and 8MHz crystal. Review baud rate table in datasheet. Select a lower baud rate or a different crystal.
 

@KlausST, can I do that with a multimeter, I don't have an oscilloscope that I can use for now
@FvM, I have a 20Mhz oscillator that I can use, do u know which configuration should I choose for the baud rate.
99285146_792867688077910_7166840939892178944_n.jpg
 

Hi,

Without reading the datasheets .. even a multimeter won´t help.
But when reading the datasheets you most probably don´t need a multimeter...as long as you kept on typical circuits and part values.

*****
Baud rate....
You post several pages of the datasheet. showing almost 150 combinations.
You should be able to find the columns with FOsc = 20MHz and the lines for 115kBaud.
Then you get just 3 options: Two of them show an error of 1.36% the other 0.94%.
If you want to be on the safe side, then use the option with 0.94% error.

***
I´m sure the datasheet gives formulas... you may use them, too.

***
You are always free to do an internet search on your own: "pic online baud rate calculator". ;-)



Klaus
 

O.k., according to the table, 8 MHz works too. But not with the settings used in your code.

For debugging of serial interfaces, I prefer a dual channel USB-to-UART bridge to monitor RX and TX line.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top