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] UART problem in sim800

Status
Not open for further replies.

yogeshnand

Newbie level 4
Joined
Dec 22, 2016
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
83
hi
my task is simply check the received message from particular number, if yes then relay will be operated and there is acknowledgement message from sim800 module to sender that inform that
relay has operated .
my problem message function i can operate relay but as i inserted a function to send a message
code will not work properly, why this happening i could not understand
please help me out

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
///////////////////////////////////////////
 //LCD decleration//
#define LCD_DIR   TRISD
#define CTRL_DIR1   TRISB.F0
#define CTRL_DIR2 TRISB.F1
#define LCD_DIR TRISD
 
#define LCD       PORTD
#define RS        PORTB.F0
#define E         PORTB.F1
#include"lcd.h"
//////////////////////////////////////////////////////
 #define STRLEN 55
volatile unsigned char flag=0;
unsigned char flag1=0;
unsigned char t;
volatile unsigned char rcindex;
volatile unsigned char rcbuf[STRLEN];
unsigned char num[]="918208996450";
unsigned char i,j;
unsigned char rcvd[13];
unsigned char Msg[]="Relay On";
 
 
 void UART_Init(void)
 {
 TXSTA.TXEN=1;     // enable transmitter
 TXSTA.BRGH=1;     // enable high baud rate
 RCSTA.CREN=1;     // continuous data receiption
 
 //configure input output
 TRISC.TRISC6=1;   // rRX pin as a input
 TRISC.TRISC7=1;   // TX pin as a input
 TRISC.TRISC0=1;
 SPBRG=103;         // set buad rate 9600
 
 PIE1.RCIE=1;      //enable USART receive interrupt
 RCSTA.SPEN=1;     //enable USART
 
 }
 ///////////Initialise Message///////////////
 
 void Init_Msg()
 {
      UART1_Write_Text("AT\r\n");           // turn disable the echo
      delay_ms(500);
      UART1_Write_Text("AT+CMGF = 1\r");        // set text mode
      Delay_ms(100);
      UART1_Write_Text("AT+CMGS="+918446323311"\r");
      delay_ms(500);
      UART1_Write_text("Relay Opearted \r");
      UART1_Write(26);
      UART1_Write(0x1A);
 }
 
 
 
void main() {
 
      INTCON.PEIE=1;                          //enable interrupt
     INTCON.GIE=1;                             // enable globle interrupt
     CTRL_DIR1=CTRL_DIR2=0X00;
     LCD_DIR=0X00;
     TRISB.F6=0x00;
     TRISB.F7=0xFF;
     init_lcd();
     delay_ms(500);
     
      //Init_gsm();
      UART_Init();
      delay_ms(500);
      UART1_Write_Text("ATE0\r\n");           // turn disable the echo
      delay_ms(500);
      delay_ms(500);
      UART1_Write_Text("AT+CMGF = 1\r");        // set text mode
      Delay_ms(1000);
      UART1_Write_Text("AT+CNMI=2,2,0,0,0\r");
      Delay_ms(1000);
 
     cmd_lcd(0x80);
     string_lcd("Init Complete");
   while(1)
   {
   if(flag)                                //if flag is set execute the below command
           {
            // check();
             //cmd_lcd(0x80);
             //string_lcd(rcbuf);
 
 
             for(i=8;i<20;i++)
             {rcvd[i-8]=rcbuf[i];}      //get the number
 
                 if(rcvd[0]=='9')       //compare with predefined number
                 {
                 if(rcvd[1]=='1')
                 {
                  if(rcvd[2]=='8')
                  {
                   if(rcvd[3]=='2')
                   {
                    if(rcvd[4]=='0')
                    {
                     if(rcvd[5]=='8')
                     {
                      if(rcvd[6]=='9')
                      {
                       if(rcvd[7]=='9')
                       {
                        if(rcvd[8]=='6')
                        {
                         if(rcvd[9]=='4')
                         {
                           cmd_lcd(0x80);
                            string_lcd(rcbuf);
                           PORTB.F6=1;
                           delay_ms(5000); 
                           Init_Msg();           //if yes relay opearateed
                           // INTCON.PEIE=0;                          //enable interrupt
                           // INTCON.GIE=0;
                            /*delay_ms(1000);
                            Init_Msg();
                            delay_ms(2000);*/
                            /*INTCON.PEIE=1;                          //enable interrupt
                            INTCON.GIE=1;*/
                            //flag1=1;
                          }}}}}}}}}}
              flag=0;                          //set the falg to zero
        }
        if(PORTB.F7==0)
        {PORTB.F6=0;}
 
   }
}
 
void interrupt(void)
{
 if(PIR1.RCIF)           //check the receive interrupt flag has fired
 {
 t=RCREG;
 if((t!='\n')&&(rcindex<STRLEN))    //check the new line ,if not found  save the string to rcbuf
 {
    rcbuf[rcindex]=t;
     if(rcbuf[0]=='+')              //check the '+' char ,if yes increment rcindex
     {
      rcindex++;
     }
     else                          //if not ,reset the rcindex ,flag to zero
     {
      rcindex=0;                    //reset string index
      flag=0;
     }
 }
 else                       //if new line found reset the rcindex and set he flag
 {
 flag=1;
 rcindex=0;}
}
//PIR1.RCIF=0;              //it is read only
}

 

Wich MCU ?

You can not affect a byte to a bit !
TRISB.F6=0x00;
TRISB.F7=0xFF;
 

Wich MCU ?

You can not affect a byte to a bit !
TRISB.F6=0x00;
TRISB.F7=0xFF;

PIC16f877A and compiler is Mkroc pro for PIC .
TRISB.F6=0;
TRISB.F7=1;
i tried as above but still prblm not solved.
 

hello,


What is your remaining RAM SIZE ?
in View Statistic window ?
you are using a lot of direct Texte inside your code .. this amount of bytes goes to RAM area ..
and sometimes , no error in compile .
but edge effect or behavior in the running program..

check if you have a warning IRPbit into the Messages window !
 
exactly sir ..
when i changed string length (STRLEN) from 55 to 25, then code work properly.
as you said the problem is with RAM.
what changes should i do to read the whole string.
this response is valuable to beginners like us.
thanks sir.
 

hello,


look at this mikroE forum thread

replace all your direct text in code like this
UART1_Write_Text("AT+CMGS="+918446323311"\r");

by

Code:
// add a commun table for all your messages 

 unsigned char TEXTE [80];
char * txt;



void UART1_Write_CText(const char *txt)
 { char cx;
   cx=*(txt);
   while (cx>0)
   {  cx=*(txt++);
      UART1_Write(cx);
      }
}


// in your main program

txt=&TEXTE[0];   // init the pointer 

UART1_Write_CText("AT+CMGS="+918446323311"\r");

and you will see a big decreasing on used RAM ..
 
hello,


look at this mikroE forum thread

replace all your direct text in code like this
UART1_Write_Text("AT+CMGS="+918446323311"\r");

by

Code:
// add a commun table for all your messages 

 unsigned char TEXTE [80];
char * txt;



void UART1_Write_CText(const char *txt)
 { char cx;
   cx=*(txt);
   while (cx>0)
   {  cx=*(txt++);
      UART1_Write(cx);
      }
}


// in your main program

txt=&TEXTE[0];   // init the pointer 

UART1_Write_CText("AT+CMGS="+918446323311"\r");

and you will see a big decreasing on used RAM ..

last night i tried to implement this command using pointer, it gives fantastic result.
my RAM still have 75% remaining , if i used number of command it doesn't effect on ram.
but whenever i used command to send Message
void Init_Msg()
{
UART1_Write_CText("AT+CMGF = 1\r"); // set text mode
Delay_ms(1000);
UART1_Write_CText("AT+CMGS="+917350534654"\r");
delay_ms(500);
UART1_Write_Ctext("Door opened \r");
UART1_Write(26);
UART1_Write(0x1A);
}
i received message but the text is null.
instead i used below command
void Init_Msg()
{
UART1_Write_CText("AT+CMGF = 1\r"); // set text mode
Delay_ms(1000);
UART1_Write_Text("AT+CMGS="+917350534654"\r"); // only this i changed
delay_ms(500);
UART1_Write_Ctext("Door opened \r");
UART1_Write(26);
UART1_Write(0x1A);
}
i got the message with text "Door opened"

what should be the problem , i am not getting .
please reply
 

ohh sorry it was my mistake..
but i learned a lot..
 

This is wrong.


Code C - [expand]
1
UART1_Write_Text("AT+CMGS="+918446323311"\r");



The string formation is wrong.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top