sim900 interfacing with atmega32
#1

can any 1 plse give me d programming codes to interface sim900awith atmega 32 to send and recieve a message
Reply
#2
sim900 interfacing with atmega32

The GSM net used by cell phones provides a low cost, long range, wireless communication channel for applications that need connectivity rather than high data rates. Machinery such as industrial refrigerators and freezers, HVAC, vending machines, vehicle service etc. could benefit from being connected to a GSM system. Take a given example. A garage offers a very special package to their customers. Based on the mechanics knowledge and the given vehicle, tailored service intervals can be specified. A part of the service agreement is installation of a GSM modem in the vehicle. An onboard service application can then notify the garage when the vehicle approaches its service interval. The garage will schedule an appointment and inform the customer. The customer will benefit from a reliable and well-serviced vehicle at a minimum cost. The garage on the other hand can provide excellent customer support, vehicle statistics, efficient work scheduling, and minimum stocks. This application note describes how to use an AVR to control a GSM modem in a cellular phone. The interface between modem and host is a textual protocol called Hayes AT-Commands. These commands enable phone setup, dialing, text messaging etc. This particular application connects an AVR Butterfly and Siemens® M65 cellular phone using a RS232 based data cable.

Today’s tutorial is one of the most interesting tutorial in a practical sense. We will learn to interface a GSM modem with the AVR series which can be used to send and receive SMS and also to receive and send calls a well as to use GPRS. The module that will be using is the SIM300 module which as on board-support for RS-232 for computers as well as TTL ports for direct-interface to microcontrollers without any need for logic conversion.

A GSM/GPRS Module like SIM300 can be used for any embedded application that requires a long range communication, like a water pump in a rice field turned on in the morning by a farmer sitting in his house few kilometres away! You have few communication options depending on the application, such as a simple sms based communications or a call based communication.

The SIM300 KIT is a fully integrated module with SIM card holder, power supply etc. The basic communication is over asynchronous serial line. This is the most basic type of serial communication that’s why it is very popular and hardware support is available in most MCUs. The data is transmitted bit by bit in a frame consisting a complete byte. Thus at high level it is viewed as a simple text stream. There are only two streams one is from MCU to SIM300 and other is from SIM300 to MCU. Commands are sent as simple text.

For the purpose of the tutorial I will be using SIM300. However you can also use sim900. Both are easily available on online stores and they share a common commands. If you are planning to use it for GPRS based applications, I suggest you to buy SIM900 as it has a better functionality for GPRS based applications. Before beginning, I suggest you to acquire some basic information about UART of the AVR

Following are the functions in AVR USART library

char UReadData()

Reads a single character from the queue. Returns 0 if no data is available in the queue.

void USARTInit(uint16_t ubrrvalue)

Initializes the AVR USART Hardware. The parameter ubrrvalue is required to set desired baud rate for communication. By default SIM300 communicates at 9600 bps. For an AVR MCU running at 16MHz the ubrrvalue comes to be 103.

void UWriteString(char *str)

Writes a complete C style null terminated string to the Tx line.

uint8_t UDataAwailable()

Tells you the amount of data available in the FIFO queue.

void UWriteData(char data)

Writes a single byte of data to the Tx Line, used by UWriteString() function.

void UFlushBuffer()

Removes all waiting data in the fifo buffer. Generally before sending new command to GSM Module we first clear up the data waiting in the fifo.

All SIM300 commands are prefixed with AT+ and are terminated by a Carriage Return (or <CR> in short). The ASCII code of CR is 0x0D (decimal 13). Anything you write to SIM300 will be echoed back from sim300’s tx line. That means if you write a command which is 7 bytes long (including the trailing CR) then immediately you will have same 7 bytes in the MCU’s UART incoming buffer. If you don’t get the echo back then it means something is wrong!

So the first function we develop is SIM300Cmd (const char *cmd) which does the following job:-

1. Writes the command given by parameter cmd.

2. Appends CR after the command.

3. Waits for the echo, if echo arrives before timeout it returnsSIM300_OK (constant defined in sim300.h). If we have waited too long and echo didn’t arrive then it returns SIM300_TIMEOUT.

Commands are usually followed by a response. The form of the response is like this

<CR><LF><response><CR><LF>

LF is Line Feed whose ASCII Code is 0x0A (10 in decimal)

So after sending a command we need to wait for a response, three things can happen while waiting for a response:

No response is received after waiting for a long time, reason can be that the SIM300 is not connected properly with the MCU.

Response is received but not as expected, reason can be faulty serial line or incorrect baud rate setting or MCU is running at some other frequency than expected.

Correct response is received.

For example, command Get Network Registration is executed like this:-

Command String: “AT+CREG?”

Response:

<CR><LF>+CREG: <n>,<stat><CR><LF>

<CR><LF>OK<CR><LF>

So you can see the correct response is 20 bytes. So after sending command “AT+CREG?” we wait until we have received 20 bytes of data or certain amount of time has elapsed. The second condition is implemented to avoid the risk of hanging up if the sim300 module malfunctions. That means we do not keep waiting forever for response we simply throw error if SIM300 is taking too long to respond (this condition is called timeout)

If correct response is received we analyses variable <stat> to get the current network registration.

Depending on current network registration status the value of stat can be

0 – not registered, SIM300 is not currently searching a new operator to register to

1 registered, home network

2 not registered, but SIM300 is currently searching a new operator to register to

3 registration denied

4 unknown

5 registered, roaming

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
int8_t SIM300GetNetStat()
{
//Send Command
SIM300Cmd("AT+CREG?");

//Now wait for response
uint16_t i=0;

//correct response is 20 byte long
//So wait until we have got 20 bytes
//in buffer.
while(i<10)
{
if(UDataAvailable()<20)
{
i++;

_delay_ms(10);

continue;
}
else
{
//We got a response that is 20 bytes long
//Now check it
UReadBuffer(sim300_buffer,20); //Read serial Data

if(sim300_buffer[11]=='1')
return SIM300_NW_REGISTERED_HOME;
else if(sim300_buffer[11]=='2')
return SIM300_NW_SEARCHING;
else if(sim300_buffer[11]=='5')
return SIM300_NW_REGISTED_ROAMING;
else
return SIM300_NW_ERROR;
}
}

//We waited so long but got no response
//So tell caller that we timed out

return SIM300_TIMEOUT;

}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Tagged Pages: sim900 interface with atmega32, gprs programming for sim900 atmega 16,
Popular Searches: atmega32 stopwatch, osiloskop atmega32 12864, rtc code for atmega32, oscilloscope atmega32, wb stat lottry ra, how to get data from atmega32 to laptop using uart vb project, sim900 interface c code,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  code for interfacing 8051 with pir sensor 1 894 05-04-2017, 03:53 PM
Last Post: jaseela123d
  vhdl code for interfacing decoder ht12d with fpga 1 776 25-03-2017, 04:47 PM
Last Post: jaseela123d
Rainbow 8051 touchpad interfacing 1 623 15-03-2017, 04:03 PM
Last Post: jaseela123d
  c code for 89s52 gsm interfacing 1 700 15-03-2017, 03:02 PM
Last Post: jaseela123d
  gps interfacing 8051 microcontroller coding 1 790 15-03-2017, 01:21 PM
Last Post: jaseela123d
  alcohol sensor interfacing 8051 1 790 15-03-2017, 11:21 AM
Last Post: jaseela123d
  interfacing lpc2138 with zigbee module 1 704 14-03-2017, 10:11 AM
Last Post: jaseela123d
  r305 fingerprint module interfacing with microcontroller pic 1 1,020 13-03-2017, 04:36 PM
Last Post: jaseela123d
  interfacing adc to 8051 1 617 10-03-2017, 04:05 PM
Last Post: jaseela123d
  interfacing of mq 3 alcohol sensor with 8051 3 1,104 20-02-2017, 04:32 PM
Last Post: jaseela123d

Forum Jump: