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 Sim300 with ATmega32

Status
Not open for further replies.

tan229

Newbie level 1
Joined
Apr 17, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
31
Hi,
I am doing 4th year project interfacing sim300 with atmega32
My sim300 is working correctly when i test it on hyperterminal even the mcu USART pins are working fine
I am posting my code could you please help me with it.

No error.


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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>
 
#include"lcd.h" 
#include"lcd.c" 
 
#define F_CPU 12000000UL
 
int i=0;
 
void wait(float x) //Wait function
{
    for(i=0;i<(int)(46*x);i++)
    _delay_loop_2(0);
}
 
 
void USARTInit(uint16_t ubrr_value)  //USART initialization 
{
   UBRRL = ubrr_value;
   UBRRH = (ubrr_value>>8);
   
   
   UCSRC|=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
 
 
   UCSRB=(1<<RXEN)|(1<<TXEN);
}
 
void usart_putstr( const unsigned char *str ) //String Function
{
    for( ;*str != 0x00; )
    {
     USARTWriteChar( *str++ );
        
    }
}
 
 
unsigned char USARTReadChar()  //USART Recieving function
{
   while(!(UCSRA & (1<<RXC)));
 
   return UDR;
}
 
void USARTWriteChar(char data)   //USART transmitting function
{
 
   while(!(UCSRA & (1<<UDRE)))
   ;
 
 
   UDR=data;
}
 
void main()   //main function
{
    LCDClear();
    
USARTInit(77);     //setting baud rate 9600
 
LCDInit(LS_NONE);    
LCDWriteString("System is ready");  //Print  the text on LCD
 
wait(1);
 
    USARTWriteChar('A');   
 
    wait(1);
        USARTWriteChar('T');
     wait(1);
      USARTWriteChar('\n\r');
      
       wait(2);
        USARTWriteChar('A'); 
        USARTWriteChar('T');
        USARTWriteChar('+');
        USARTWriteChar('C');
        USARTWriteChar('M');
        USARTWriteChar('G');
        USARTWriteChar('F');
        USARTWriteChar('=');
        USARTWriteChar('1');
        USARTWriteChar('\n\r');
wait(2);
 
        USARTWriteChar('A');
        USARTWriteChar('T');
        USARTWriteChar('+');  
        USARTWriteChar('C');
        USARTWriteChar('M');   
        USARTWriteChar('G');
        USARTWriteChar('D');
        USARTWriteChar('=');
        USARTWriteChar('1');
        USARTWriteChar('\n\r');
 
 
wait(.5);
LCDClear();  //clear screen
 
LCDWriteString("Msg Memory Clear");
 
wait(2);
LCDClear();
wait(1);
 
while(1)
{
    USARTWriteChar('A');   
 
    wait(1);
        USARTWriteChar('T');
     wait(1);
      USARTWriteChar('\n\r');
      
wait(2);
 
    USARTWriteChar('A');  
        USARTWriteChar('T');  
        USARTWriteChar('+');  
        USARTWriteChar('C');  
        USARTWriteChar('M');  
        USARTWriteChar('G');
        USARTWriteChar('F');
        USARTWriteChar('=');
        USARTWriteChar('1');
 
wait(3);
 
        USARTWriteChar('A');  
        USARTWriteChar('T');  
        USARTWriteChar('+');  
        USARTWriteChar('C');  
        USARTWriteChar('M');  
        USARTWriteChar('G');
        USARTWriteChar('S');
        USARTWriteChar('=');
        USARTWriteChar('"');
        USARTWriteChar('+');
        USARTWriteChar('9');
        USARTWriteChar('1');
        USARTWriteChar('9');
        USARTWriteChar('9');
        USARTWriteChar('9');
        USARTWriteChar('9');
        USARTWriteChar('9');
        USARTWriteChar('9');
        USARTWriteChar('9');
        USARTWriteChar('9');
        USARTWriteChar('9');
        USARTWriteChar('9');
        USARTWriteChar('"');
        USARTWriteChar('\n\r');
        
 
        wait(3);
 
        USARTWriteChar('Y');
        USARTWriteChar('o');
        USARTWriteChar('u');   
        USARTWriteChar('r');
        USARTWriteChar(' ');   
        USARTWriteChar('A');  
        USARTWriteChar('C');
        USARTWriteChar(' ');
        USARTWriteChar('i');
        USARTWriteChar('s');
        USARTWriteChar(' ');
        USARTWriteChar('O');
        USARTWriteChar('n');
          
        USARTWriteChar(26);   
        USARTWriteChar('\n\r');
 
        wait(2);
        
LCDWriteString("check msg");
wait(1);
LCDClear();
wait(2);
}
}

 
Last edited by a moderator:

I'm pretty sure you problem is just timing... your wait() loop seems too quick (not even 1ms with those 12Mhz). why don't you use the _delay_ms() from util/delay.h ???

anyway... I think your timing even there is very off... as I remember most commands took at least 100ms to execute, and the quickest way to determine that is, instead of waiting time, catch the "OK" response with the usart...

also after the +CMGS command it takes a variable amount of time (about 1 or 2 seconds) before sending the caret ">" and only after receiving the caret you can send the message text (with the corresponding ctrl+z as you did)...

I suggest you to get one (or two if you can) TTL uart to USB converter (like some FT232boards) (probably the same kind you used to communicate the sim900 with the PC) and check both the uC tx data and the sim tx data (i you can check both at the same time see if you receive a corresponding 'OK' for each AT command) don't forget to check that the uC is correctly sending the data at 9600bps and you didn't mess the crystal freq or the clkdiv fuses in the AVR...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top