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.

[PIC] Pic18F4550 & SIM300 (Monitor & control device using SMS). problem in reading "OK"

Status
Not open for further replies.

KVN1477

Junior Member level 3
Joined
Nov 18, 2013
Messages
26
Helped
4
Reputation
8
Reaction score
4
Trophy points
3
Activity points
184
Pic18F4550 & SIM300 (Monitor & control device using SMS). problem in reading "OK"

I have developed code to establish communication between SIM 300 GSM modem & PIC 18F4550 code is as follows...in Micro C pro.
i am sending AT command to Gsm modem & trying to DISPLAY "0K" ON lcd....
BUT PROGRAM STOPS DISPLAYING "Testing com..."
i am unable to understand weather "AT" is getting send to GSM modem and weather Modem is replaying with "OK"......

pls, help me to read & display "OK" from GSM modem..

// LCD module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATD4_bit;
sbit LCD_D5 at LATD5_bit;
sbit LCD_D6 at LATD6_bit;
sbit LCD_D7 at LATD7_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

char gsm_response[20];

void gsm_send_command(char *command)
{
while(*command)
{
uart1_write(*command++);
}
uart1_write(10);
uart1_write(13);
//Delay_ms(700);
}
void main()
{
PORTB = 0x00;
LATB = 0x00;
ADCON1 = 0x0F; // Configure AN pins as digital
CMCON=0; // comparator off
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(200); // Wait for UART module to stabilize
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display

Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

Lcd_Out(1,1,"Smart Home..."); // Write text in first row

Delay_ms(2000);

Lcd_Cmd(_LCD_CLEAR); // Clear display

lcd_out(1,1,"Testing com...");

gsm_send_command("AT");//send AT to modem using subroutin
do
{
UART1_Read_Text(gsm_response,"OK ",2);// read response from Modem until OK received and save in variable gsm_response

}while (UART1_Data_Ready()==1);

Lcd_cmd(_Lcd_clear);
Lcd_out(1,1,gsm_response);// Display OK
delay_ms(5000);
}
 
Last edited:

Re: Pic18F4550 & SIM300 (Monitor & control device using SMS). problem in reading "OK"

Try this code. If this doesn't work then connect your modem to PC and send AT from Terminal software. It should give response like >OK. Just post the screenshot of the response you get.


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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// LCD module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATD4_bit;
sbit LCD_D5 at LATD5_bit;
sbit LCD_D6 at LATD6_bit;
sbit LCD_D7 at LATD7_bit;
 
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
 
unsigned char gsm_response[5], i = 0;
 
 
void main()
{ 
    PORTB = 0x00;
    LATB = 0x00;
 
    ADCON1 = 0x0F; // Configure AN pins as digital
    CMCON=0; // comparator off
 
    UART1_Init(9600); // Initialize UART module at 9600 bps
    Delay_ms(200); // Wait for UART module to stabilize
 
    Lcd_Init(); // Initialize LCD
    Lcd_Cmd(_LCD_CLEAR); // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
    Lcd_Out(1,1,"Smart Home..."); // Write text in first row
    Delay_ms(2000);
    Lcd_Cmd(_LCD_CLEAR); // Clear display
    LCD_Out(1,1,"Testing com...");
 
    
 
    while(1)
    {
        UART_Write_Text("AT\r\n");
        
        while(gsm_response != ">OK"){
            gsm_response[i++] = UART1_Read();
            gsm_response[i] = '\0';
            
        }
    
        Lcd_cmd(_LCD_CLEAR);
        Lcd_out(1, 1, gsm_response);
        Delay_ms(5000);     
 
    }   
}

 

Re: Pic18F4550 & SIM300 (Monitor & control device using SMS). problem in reading "OK"

Is SIM300 working ok on hyper terminal in all condition such SMS sending Receiving. If yes then test controller code on Hyper terminal & check it show require data on hyper terminal if both above condition work then only send data from controller to sim300
 
Re: Pic18F4550 & SIM300 (Monitor & control device using SMS). problem in reading "OK"

thanks.....

compiler is sending error for ur code for "while(gsm_response!="OK")" as - - Operator '' is not applicable to these operands



Try this code. If this doesn't work then connect your modem to PC and send AT from Terminal software. It should give response like >OK. Just post the screenshot of the response you get.


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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// LCD module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATD4_bit;
sbit LCD_D5 at LATD5_bit;
sbit LCD_D6 at LATD6_bit;
sbit LCD_D7 at LATD7_bit;
 
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
 
unsigned char gsm_response[5], i = 0;
 
 
void main()
{ 
    PORTB = 0x00;
    LATB = 0x00;
 
    ADCON1 = 0x0F; // Configure AN pins as digital
    CMCON=0; // comparator off
 
    UART1_Init(9600); // Initialize UART module at 9600 bps
    Delay_ms(200); // Wait for UART module to stabilize
 
    Lcd_Init(); // Initialize LCD
    Lcd_Cmd(_LCD_CLEAR); // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
    Lcd_Out(1,1,"Smart Home..."); // Write text in first row
    Delay_ms(2000);
    Lcd_Cmd(_LCD_CLEAR); // Clear display
    LCD_Out(1,1,"Testing com...");
 
    
 
    while(1)
    {
        UART_Write_Text("AT\r\n");
        
        while(gsm_response != ">OK"){
            gsm_response[i++] = UART1_Read();
            gsm_response[i] = '\0';
            
        }
    
        Lcd_cmd(_LCD_CLEAR);
        Lcd_out(1, 1, gsm_response);
        Delay_ms(5000);     
 
    }   
}


- - - Updated - - -

Thanks GE.....
Modem is working properly with Hyper terminal
As per ur guidance i must check Circuit by connecting it to PC
i will let u know o/p afterward...
 

Re: Pic18F4550 & SIM300 (Monitor & control device using SMS). problem in reading "OK"

Replace

Code C - [expand]
1
while(gsm_response != ">OK"){



by


Code C - [expand]
1
while((gsm_response[0] != '>') && (gsm_response[1] != 'O') && (gsm_response[2] != 'K')){

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top