Departement Technische Wetenschappen Gegradueerde in elektriciteit Optie elektronica

Sending a GPS location with a cell phone

CAMPUS Geel

Maarten Frederix

Academiejaar 2005-2006

De houder van dit diploma is gerechtigd tot het voeren van de titel van Bachelor

Vaasa Polytechnic

KHK Geel

1

FOREWORD
First I would like to thank everyone who helped me to complete my practical training and my paper. As a senior year student the paper is very important to obtain a certificate of Bachelor in ICT. Although my project mainly involves electronics, it has very instructive. I would like to thank Vaasa Polytechnic and KHK Geel for giving me the opportunity to do my practical training in Finland. I would like to thank Mrs. Lena Dilliën and the international office in Vaasa. This practical training has been a special experience. I would like to thank my supervisor Mr. Jukka Matila for the work placement and all the help I got from him. I also had lots of help from the laboratory engineer Jani Ahvonen. I would like to thank him for that. Also I would like to thank the other student that found time to help me in my assignment. For my paper, I would like to thank my supervisor Mr. Luc Friant for the advice and the help I had from him. Finally I would like to thank my parents for the support and the opportunity to study at KHK Geel and allowing me to go abroad for my training. Maarten Frederix June 2006

Frederix Maarten

June 2006

Vaasa Polytechnic

KHK Geel

2

INTRODUCTION
My project took place in Technobotnia in Finland. I was there from the 18th of August until the 14th of November. During this period, I worked with microcontrollers. My assignment is using an Atmel ATTINY2313 microcontroller. The microcontroller needs a serial connection with the GPS-receiver of the Wavecom QUICK Q2501 chipset. The task of the microcontroller is to filter the data. Only the position of the GPS-receiver must remain. This data is than send to the GSM of the Wavecom QUICK Q2501 chipset. Applications like these are already in use. But the Wavecom QUICK Q2501 is the first chip with a GPS-receiver and a GSM-module combined on one chip. In this project, I used a SMS to show that the program works. But practical it is possible to use any service provided by the GSM. This application is useful in navigation of ships, planes, etc. It can send its current position to a radar or something similar. It is already in use to guide ships to the requested position. In this paper, the first chapters are the theoretical background of the application. To understand the program it is important to understand how a microcontroller works. The middle chapters are an explanation of the programs that I used. These programs are Codevision AVR and WinAVR. The final chapter of my paper is the explanation of the project I made. This is explained by flowcharts and the code is explained with comments.

Frederix Maarten

June 2006

....1 3...................................................................... 21 Interrupts ..............2...............................................1 4 4............1............ 31 Programming with WinAVR ...................................................................3 2....................................................................................... 43 9 9.............................................................................. 11 GSM .............................................................................................................................. 8 NMEA-0183 ..........................................45 $GPVTG .............................................. 7 Geographical location ....................................................................................................................................................................................................... 29 WINAVR ............................. 27 Advantages and disadvantages ......................................3 7 7....................................... 13 Use of the Q2501 GSM with SMS.........1 2 2....................................................................................................................................................................6 9........................................3 9........ 5 Finland .....................................................................................................................................................................1 4...................................................................5 9.....................................................1 9............................................................................................ 27 Uploading the code .................45 $GPRMA........................................ 33 Flowchart ......Vaasa Polytechnic KHK Geel 3 TABLE OF CONTENTS 1 1...........7 APPENDIX ..........................................................................................................1........1 7........................... 12 GSM network...................................................46 $GPGSA ..................................................... 27 Programming ...................................... 17 External connections ...........................2 8 8......... 26 CODEVISION AVR. 31 Advantages and disadvantages ............................2 4.1.....3 4............................47 Frederix Maarten June 2006 ....1.................................. 44 $GPRMB................... 14 Features of the ATTINY2313 .........................2 6.....................................4 4............................................2........... 5 WAVECOM WISMO QUICK Q2501 ................................................... 15 Block diagram of the ATTINY2313 ..............................................5 5 6 6..................................................................44 $GPRMC.................................... 16 System Clock ...........................................2..1 2................................................................................................2 INTRODUCTION TO FINLAND ...........................2 9.........................................................................44 $GPGGA.............................. 22 CONNECTING THE MODULE WITH THE MICROCONTROLLER ............ 17 Programming the ATTINY2313 ...1 4........................... 8 GPS .....2 4...........46 $GPGSV .1 6............................................................... 44 Appendix A: NMEA-0183 standard .......................2 3.............................1....1 9....................... 13 ATMEL ATTINY2313 ..........4 9...... 33 The code ............... 31 EXPLAINING THE CODE ....................................................... 22 USART .................................................................................. 12 SMS..............4 3 3...........................................1.......................................1.....1 8............ 37 CONCLUSION.............. 10 Use of the Q2501 GPS-receiver ............................................................2 2...........................................................

...............3 Appendix B: The makefile....................................................... 47 Appendix C: The program........................................................................2 9.................................................. 56 SOURCES ............................Vaasa Polytechnic KHK Geel 4 9..................... 62 Frederix Maarten June 2006 ..

This is a Research centre of Vaasan Ammattikorkeakoulu. 1. Vaasa is situated in the middle of Finland.1 Finland Map of Finland Frederix Maarten June 2006 .Vaasan Yliopisto and Svenska Yrkeshögskolan.Vaasa Polytechnic KHK Geel 5 1 INTRODUCTION TO FINLAND For my practical training. I worked in Technobotnia.

It was awarded the price of Building of the Year in 1996 by the State Real Estate Department. The north of Finland is known for its archipelagos. Frederix Maarten June 2006 . Different kind of geography can be found over the entire country. A Big city in the east is Juväskylä. Over 10 000 people come to study in one of the schools every year. Sweden and Russia. Vaasa is a city in the north of Finland. This is the city of Santa Claus. In Finland there are about 55000 lakes. It was the capital of Finland in 1917. I worked for the Finnish department. This is also a big city for students. In Technobotnia there are three departments working. Most of the population in situated in these areas. This is the language of the Sami civilisation which is still present in Lapland.Vaasa Polytechnic KHK Geel 6 Finland is a Scandinavian country. It is a former Cotton factory which is renovated in 1996. The entire population is 5000000 people. a Swedish and a Finnish department. My supervisor was Jukka Matila. A third of the country is situated north of the Arctic Circle. Helsinki is the capital of Finland and has a population of about 500000 inhabitants. The school I worked for is Vaasan Ammattikorkeakoulo. Most of them are in the East of Finland. This is much compared to all the rest of Finland. In Vaasa about 25% of the people speak Swedish on a population of 57 000 people. Small minorities in the north speak Sami. It extends over a length of 1200 km from the north to the south and about 550 from the west to the east. The laboratory Engineer is Jani Ahvonen. It exists of more than thousands of islands. Business Economics and Tourism as well as Health Care and Social Services. About 6% of the people speak Swedish. A famous city in Lapland is Rovaniemi. Turku. All the lakes together cover about 10% of the country. Oulu en Helsinki. Technobotnia Vaasa The laboratory of the Faculty of Technology and Communication is in Technobotnia. The mother tongue in Finland is Finnish and Swedish. It has borders with Norway. Big cities are Tampere. Now it is a city for students. It is about 600km from Helsinki. multilingual and international institution providing higher education and research services within Technology and Communication. Vaasa Polytechnic is a multi-disciplinary. These departments are an English. Vaasa Polytechnic has approximately 3500 students enrolled and a staff of over 240 members. In the North of Finland is a part of Lapland.

1A) Frederix Maarten June 2006 . no position is available 5 = Connector for the antenna for the GSM 6 = Connector for the antenna for the GPS 7 = Connectors for every pin on the Q2501-chip 8 = Power-connector (the board requires 9-12V DC. Glyn EVBQUIK-GPS testing board 1 = Serial connector for the GSM (RS232) 2 = Serial connector for the GPS (RS232) 3 = SIM-card socket 4 = Status-LED’s GPS: LED blinks if a valid GPS signal is received GSM: LED blinks if a SIM-card is connected to a network Power: LED is on if power is on. This board is shown in the picture below.Vaasa Polytechnic KHK Geel 7 2 WAVECOM WISMO QUICK Q2501 The Wavecom WISMO Q2501 is a GPS-receiver and a GSM-controller. The chip was delivered with the glyn EVBQUICK testing board. I used this chipset because it is combined on one print. Both parts have there own serial connection to send and receive data. If the LED is off.

The equator is the 0 degree line. The lines are actually circles around the globe. It is a worldwide navigation system that is used to calculate the position of a receiver inside the geographic system. The North Pole and the South Pole are 90 degree from the equator. This system exists of a longitude and latitude. They move with a speed of 14000km/hour. The longitude describes the place of a location based on the Prime Meridian.2 GPS GPS stands for Global Positioning System. To calculate an altitude the fourth satellite is needed too.It is represented by the vertical lines on the map. Each position on earth can receive a signal of at least four different satellites.1 Geographical location Every position on earth can be pointed in the geographic coordinate system. The receiver calculates how far it is removed from the satellites and calculates his position with this information. It is developed by the US Department of Defence. The west side of the Prime Meridian is represented by a – sign in front of the position. The latitude is the place of a location based on the distance from the equator. These satellites have 6 orbits around earth and are on an altitude of 20000 km. 2.Vaasa Polytechnic KHK Geel 8 2. Map of Earth with longitude and latitude lines. Three satellites are needed to find an exact position on earth. The meridian is in Greenwich (UK). Here is shown why three satellites are necessary to calculate one point. The GPS-system is a network of 24 satellites. It is represented by the horizontal lines on the map. Frederix Maarten June 2006 . The original name of the project was NAVSTAR (Navigation System with Timing And Ranging).

The distance from the satellite to the receiver is the same over the entire circle. Frederix Maarten June 2006 .Vaasa Polytechnic KHK Geel 9 Only one satellite is available. In this case two satellites are available. These two points are the intersections between the two circles. The second satellite will narrow the position down to two points.

Other similar systems are GLONASS and EGNOS which are developed by Russia and Europe. Fix : Time of fix (UTC-time) Status : The navigation receiver warning which displays an ‘A’ for a valid position and a ‘V’ for an invalid position. A list of the different sentenceID that are used by the Q2501 is listed the appendix. By 2008 the EGNOS program should be replaced by GALILEO. The NMEA standard defines the protocol used for data communication between the GPS-receiver and an external interface. 2. Latitude. The standard is explained below. E/W : Longitude of the current position Frederix Maarten June 2006 .3 NMEA-0183 NMEA is National Marine Electronics Association. In this program only the $GPRMC is used to filter the data. The intersection between the three satellites is always on one point only. Also other systems work the same way as GPS. N/S : Latitude of the current position Longitude. A position is valid if more than three satellites are detected. All the data is organised in sentences with a different sentenceID. The signal that is send by GPS-satellites is compiled according to the NMEA-0183 standard.Vaasa Polytechnic KHK Geel 10 A third satellite is available. The $GPRMC is the Recommended minimum of data that a receiver should send through its serial output. The following data is sent in this sentenceID. This is the location of the receiver.

Vaasa Polytechnic KHK Geel 11 Speed over ground : Horizontal speed of the receiver (in knots) Course over ground : Direction of the movement (in degrees) UTC date : Date of fix (UTC-date) Magnetic variation : It is the magnetic variation. On the computer. Because the radio waves have a known speed. the HyperTerminal can be used to program the module. A list of the commands for the GPS receiver is in the appendix. this will cause a directional bias in the GPS. The full NMEA-0183 standard is included in appendix A. This position is translated in the longitude and the latitude of the receiver. Because the receiver knows the position it can determine the time between the sending of the data by the satellite and the receiving of the data by the receiver. the serial port of the GSM module is used and connected to the serial port of the computer.4 Use of the Q2501 GPS-receiver To communicate between a PC and the GPS-receiver. 2. the receiver can than calculate the position based on this time. By saving this position and comparing it with the next calculation it is possible to determine the speed. Frederix Maarten June 2006 . The default settings of the GPS are 9600bps. This list is updated regularly so the information stays correct at any moment. Magnetic variation E/W Checksum In the receiver is a list of all the satellites. 8 data bits. no parity and hardware flow control. If the magnetic variation is incorrect.

good subjective speech quality . The Base Station Controller provides the connection between several Transceivers. Because these systems were incompatible.support for international roaming . Each cell of the network has its own Base Station Transceiver.Base Station Subsystem . Each country developed its own standard. It is developed in Europe in the early 1980s.Operation and Support subsystem The GSM network is build with a cellular structure. The criteria for the system were: . The Operation and Support subsystem oversees the proper operation and setup of the network.low terminal and service cost . In smaller areas.1 GSM network The GSM network consists of: .ISDN compatible 3. Cellular structure of the GSM network The Network and Switching subsystem is used to manage the communications between cell phones and the other telephone networks. the Conference of European Posts and Telegraphs formed the study group Groupe Spécial Mobile to develop and study a mobile system for Europe.Vaasa Polytechnic KHK Geel 12 3 GSM GSM is the Global System for Mobile communications.ability to support handheld terminals .Network and Switching subsystem . Multiple Transceivers can be connected to one Controller. Frederix Maarten June 2006 .spectral efficiency .

1 Use of the Q2501 GSM with SMS The GSM chip works on a default value of 115200bps. etc 3.2. AT+CMGS="(phone number)" <ENTER> (with the quotes) (message) <CTRL><Z> (<CTRL><Z> can be send by a ASCII character 26dec) Frederix Maarten June 2006 . For my project. It can send short alphanumeric messages between mobile phones. To set the speed in the GSM use the following commands AT+IPR = 4800 (changes the current baud rate to 4800 bps) AT&W (saves the data to the EEPROM) AT+CFUN = 1 (restart the chip software) If the speed of the GSM is the same as the speed of the microcontroller. it is possible to use the GSM. PDA.2 SMS SMS is the abbreviation of Short Message Service. I had to use 4800bps because this is the speed of the GPS and the microcontroller. The SMS service can be used with following commands.Vaasa Polytechnic KHK Geel 13 3.

Vaasa Polytechnic KHK Geel 14 4 ATMEL ATTINY2313 To connect the GPS and the GSM I use a microcontroller. The ATTINY2313 works on a Tietomyrsky Oy EXB2313 programming and testing board.0 and PORTD.1 3 = The LED’s are used to see that data is send. For this project this microcontroller is an ATMEL ATTINY2313. The connection with the microcontroller is made on PORTD. Frederix Maarten June 2006 . Tietomyrsky EXB2313 testing board 1 = Microcontroller ATTINY2313 2 = serial connector. 5 = Power connector (12V DC) 6 = Connectors for every pin on the microcontroller. These are connected to PORTB 4 = Connector for a parallel programming cable.

7V . Compare and Capture Mode Full Duplex USART 2.5V for Operating Voltage Up to 20MHz clock frequency Frederix Maarten June 2006 . 32 x 8 General Purpose Working Registers 2KBytes of In-System Self Programmable Flash 128 Bytes of In-System Programmable EEPROM 128 Bytes of Internal SRAM One 8-bit Timer/Counter with Prescaler and Compare Mode One 16-bit Time/Counter with Prescaler.Vaasa Polytechnic KHK Geel 15 4.5.1 Features of the ATTINY2313 The microcontroller uses AVR architecture.

the CPU uses AVR architecture. The CPU consists of the Arithmetic Logical Unit. registers and a control unit. ROM memory and I/O. It is very useful for on-board programming and to save space on a print. Frederix Maarten June 2006 . it is directly connected to the ALU with 2 data buses. For fast access.Vaasa Polytechnic KHK Geel 16 4. In the RAM memory it is possible to store data.2 Block diagram of the ATTINY2313 Block Diagram of the ATTINY2313 A microcontroller is a small computer build in a chip. The ALU is directly connected with the 32 General Purpose Registers. These Registers are uses for data and control information. RAM memory. It exists of a CPU. In this microcontroller.

It is the successor of the CISC instruction set. A Crystal Oscillator can be connected to the XTAL1 and XTAL2 pins of the microcontroller. The ports are named PORTA. In the Von Neumann architecture. This clock can be set for 4MHz or 8MHz. It is a 20 pin s PDIP package. etc. This is pin 4 and pin 5 of the microcontroller. microcontrollers.2 External connections The microcontroller can be connected to other devices with its ports. This means that one 8-bit data bus is uses for the communication between the different parts of the microcontroller. Pipelining is a technique where every process is divided in multiple smaller sub processes. 4. a certain frequency is given to all of the components. Crystal Oscillator 4. It uses an RC Oscillator. RISC is an instruction set for the computers. all the instruction use the same numbers of bits. it uses Harvard architecture to connect the several components to each other.2. only few instructions and modes and more than 1 register for each functions. CISC is Complex Instruction Set Computer. It is the abbreviation of RISC is Reduced Instruction Set Computer. The pin map of this microcontroller is given below. Frederix Maarten June 2006 . all the data and the program are put in the same memory. A disadvantage of this architecture is that all the instruction and data can only be read in multiple cycles. PORTB and PORTD. In the microcontroller is a clock present. This architecture is faster that the Von Neumann architecture. The advantage of this technique is that multiple units can work at the same time.Vaasa Polytechnic KHK Geel 17 The ROM memory stores the system program. Each port exists of a number of pins which can be used simultaneously. Each sub process can be send to a unit that is designed for the instruction. The ATMEL AVR is part of the ATMEL RISC family.2. Because it is an AVR microcontroller.1 System Clock To make the microcontroller work. The difference with RAM memory is that it can only be read and not be written. In this microcontroller there are three ports available. The advantages of RISC are easy to program. An external oscillator is also possible. The maximum frequency of this microcontroller is 20MHz. The I/O is the bus to transfer all the data between the different parts. pipelining.

This is because the resistor is enabled if no value is given. PINxn is the current value of the pin. The pull-up resistor creates a default value for each pin.Vaasa Polytechnic KHK Geel 18 Pin map of the ATTINY2313 Pins: 1 2 3 4 5 6 7 8 9 10 PA2 PD0 PD1 PA1 PA0 PD2 PD3 PD4 PD5 GND 20 19 18 17 16 15 14 13 12 11 VCC PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0 PD6 All the ports in the microcontroller are bidirectional input/output ports. The pull-up resistor is a transistor. The PORTxn register can set a pull-up resistor to choose a default value. PORTxn and PINxn. Frederix Maarten June 2006 . This setting for the pull-up resistor happens in the PORT register. the value of DDxn is 0. PORTx should have the value 0xFF. To disable it. The DDxn register sets the pin as an output or input. This means that they can be set as input or output. The settings can be adjusted in the register DDxn. The value of PORTx should be 0x00 to enable the pull-up resistor of every port in that array. then the pull-up resistor has to be set. If the corresponding pin is input. it will pass the 5V from the source to the min. When the default value of an input or output supposed to be high. When it is enabled.

1 PORT A PORTA is a 3-bit input/output port PORTA.2.2 RESET: dW: debug Wire On-chip Debug System PORTA. Frederix Maarten June 2006 .0 XTAL1: PIN1 of an external clock 4.2. PORTB.2 PORTB Port B is an 8-bit input/output port.7 USCK: Three-wire mode Serial Interface Clock SCL: Two-wire Serial Clock for USI communication PCINT7: Pin Change Interrupt source 7.2.1 XTAL2: PIN2 of an external clock PORTA.2.Vaasa Polytechnic KHK Geel 19 4.

5 OC0B: Output Compare Match B output T1: Timer/Counter1 External Counter Clock input PORTD.2.0 AIN0: Analogue Comparator Positive Input PCINT0: Pin change Interrupt source 0 4.6 ICP: Time/Counter1 Input Capture Pin PORTD.4 T0: Timer/Counter0 External Counter Clock input PORTD.3 PORTD Port D is a 7-bit input/output port.3 OC1A: Output Compare Match A output PCINT3: Pin change Interrupt source 3 PORTB.5 DI: Three-wire mode Serial Interface Data Input SDA: Two-wire mode Serial Interface Data PCINT5: Pin change Interrupt source 5 PORTB. PORTD.2.2 OC0A: Output Compare Match A output PCINT2: Pin change Interrupt source 2 PORTB.3 INT1: External Interrupt source 1 Frederix Maarten June 2006 .4 OC1B: Output Compare Match B output PCINT4: Pin change Interrupt source 4 PORTB.1 AIN1: Analogue Comparator Negative Input PCINT1: Pin change Interrupt source 1 PORTB.6 DO: Three-wire mode Serial Interface Data Output PCINT6: Pin Change Interrupt source 6 PORTB.Vaasa Polytechnic KHK Geel 20 PORTB.

Frederix Maarten June 2006 . The cable is connected with a parallel plug onto the computer and with a RJ45 jack on the testing board. The picture above shows the connection between the cable and the microcontroller.0 RXD: USART Data Receiver 4.Vaasa Polytechnic KHK Geel 21 PORTD. When a program is loaded in the microcontroller.2 INT0: External Interrupt source 0 XCK: USART Transfer Clock used for synchronous Transfer mode CKOUT: System Clock Out PORTD. the registers have to be set to their initial values.1 TXD: USART Data Transmitter PORTD. This happens when a reset occurs. Pin 4.3 Programming the ATTINY2313 Connection for programming the ATTINY2313 There is a connection for programming on the EXB2313 testing board. 5 and 6 are the programming pins. Pin 2 is used as the RESET for the microcontroller.

The advantage of interrupt is that the program does not have to listen to the port all the time.1 for sending data. Namely external and internal interrupt. In this case. 4. The internal interrupt are timers/counter and to store data.4 Interrupts The use of an interrupt is to stop the normal procedure of a program and start another procedure. The external interrupt are changes on one of the port. Therefore a General Interrupt Enable bit (GIE) can block all further interrupt while the interrupt is running. I use an interrupt to stop the program from running and then read the signal on the serial receive port. In the mean time. Both receiver and transmitter require a USART for serial communication. A problem that can occur is that an interrupt gets interrupted.0 for receiving data and PORTD.5 USART A USART is a Universal Synchronous / Asynchronous Receiver / Transmitter.Vaasa Polytechnic KHK Geel 22 4. This kind of interrupt is called a signal. The USART of the ATTINY2313 is on PORTD. Frederix Maarten June 2006 . There are 2 kinds of interrupts. it can run a normal procedure to by example edit the data.

the Parity Generator sends the parity bit. With an asynchronous transfer. The first part is the clock generator. The receiver can test the data with the parity bit. a Shift Register and a Receiver Buffer (UDR). Control Logic. The second part is the Transmitter (TxD). The shifting is done by the Shifting Register. the data has to be shifted in the Shifting Register. it will be shifted to the connection line. It consists of a Write Buffer. The data is then checked in the Parity Checker who will generate its own parity bit and compare it with the received one. When the Complete byte is in the buffer. It read the data bit by bit and sends them to the Receive Buffer. an internal clock is used. It consists of a Synchronization Logic and a Baud Rate Generator. the USART will send an interrupt.Vaasa Polytechnic KHK Geel 23 Schematic of the USART in the ATTINY2313 The USART is build up by three main parts. This clock has a preset Baud Rate and Frame Size. To receive a byte. a Parity Checker. This pin is only used for synchronous data transfer. When a start bit is received. a Shift Register. Parity Generator and a Control Logic. The data byte that has to be sent is loaded in the Write Buffer. The third part is the Receiver (RxD). It consists of a recovery unit for the clock and for the data. When all the data is send. Frederix Maarten June 2006 .

They indicate if the Transmit and Receive buffer are full. size of the frame. //Put data into buffer. This registers consists of flag bits to communicate properly. errors. //*****************************************************************// // RECEIVE // //*****************************************************************// SIGNAL ( SIG_USART0_RX ) { // Store received byte IncomingData = UDR. It is also called SPI. the UDRE is important. The USI is the Universal Serial Interface. This flag bit indicates if the transmit buffer is ready to receive new data. In two-wire communication only a transmitter and receiver are available. To set the register for input or output. // This shows the data with LEDS on PORTB } //******************************************************************// USI is also a way for serial communication. There is no buffer available to store the data. This is for both the receiver and transmitter the same register. A clock frequency can be send along in three-wire communication. etc //*****************************************************************// // TRANSMIT // //*****************************************************************// void USART_Transmit(unsigned char data) { while( ! ( UCSRA & ( 1<<UDRE ) ) ). The incoming and outgoing data is saved in the 8-bit Shift Register (USIDR). Frederix Maarten June 2006 . // Wait for empty transmit buffer UDR = data. There are two possibilities for communication. PORTB = IncomingData. sends the data } //*****************************************************************// For transmitting a frame. The data has to be written to a memory place immediately after receiving. interrupts.Vaasa Polytechnic KHK Geel 24 The settings for the USART are saved in the UCSRA and UCSRB register. the D-Latch makes the connection with the right pin.

Vaasa Polytechnic KHK Geel 25 Schematic of the USI in the ATTINY2313 Frederix Maarten June 2006 .

6. Full Duplex Espionage Monitor Cable The connections of a serial port are: 1. I used a HyperTerminal connection instead of the GSM-module. 8. The second connects the 2 ground with each other. The connections of the cable are shown in following picture. It shows that the receive and the transmit cable of a normal serial cable is connected to another connector which is connected to the GSM. This serial connection is a Full Duplex Espionage monitor cable. The second also connects the ground with each other. Frederix Maarten June 2006 . 2. The baud rate for all the connections has to be the same. 9. 5. the data can be seen as plain text. The first from the Tx of the microcontroller to the Rx of the GSM. To do this. a special type of cable is used to connect all three devices to each other. the GPS sends its data to the microcontroller.Vaasa Polytechnic KHK Geel 26 5 CONNECTING THE MODULE WITH THE MICROCONTROLLER The GPS is connected to the microcontroller by a serial cable and the GSM too. This transmission needs 2 connections. 4. there are also 2 connections needed. Because the USART of the microcontroller has both pins on the serial connection. In this case I used a baud rate of 4800bps. The first connection is from the Tx of the GPS to the Rx of the microcontroller. The microcontroller handles the data so that the GSM can send an SMS. In the HyperTerminal. Carrier detect Rx ( Receive) Tx (Transmit) Data Terminal Ready Ground Data Set Ready Request To Send Clear To Send Ring Indicator For the transmission. 7. To test the code in the microcontroller. 3.

In this version are not all the features enabled. A lot of the code is generated by a wizard. For my project.htm Codevision AVR Frederix Maarten June 2006 .ro/html/download.hpinfotech. 6. By example the USART is locked.Vaasa Polytechnic KHK Geel 27 6 6.2 Programming Codevision AVR is specially designed for the Atmel AVR microcontrollers. The program has a programmer and compiler on board. When the code is finished.1 CODEVISION AVR Advantages and disadvantages It is an easy to use programming environment. I could only use an evaluation version. An Evaluation version can be downloaded at http://www. it can be automatically compiled by this program The disadvantages are that the program is not free.

To work with USART. These are the pins used for the USART signal. Then the ports can be set to input or output. To make a program.Vaasa Polytechnic KHK Geel 28 Some hardware functions are code generator by a wizard. which is a ATtiny2313. select create new project. The first thing to do is selecting the chip. The Wizard is very useful if you are not used to program a lot. Codevision AVR wizard Frederix Maarten June 2006 . pin PD0 has to be input with a pull-up transistor and pin PD1 has to be output with 0.

first the code has to be compiled. Frederix Maarten June 2006 . The compiler is the make option in the Project menu. To do this.Vaasa Polytechnic KHK Geel 29 6.Configure When the code is written. it can be programmed into the microcontroller. the Program button is shown on the bottom of the window. If the code is compiled correctly.3 Uploading the code Codevision – save and generate Project .

Make Frederix Maarten June 2006 .Vaasa Polytechnic KHK Geel 30 Project .

A makefile needs to be made to compile code. Both are saved in the same directory. The c-file contains the code for the program. For this project I chose for clanguage because all of the experience I had with microcontrollers was in c.Vaasa Polytechnic KHK Geel 31 7 7. The disadvantages are that it is very hard to learn this program. A makefile tells the compiler what commands he has to run and what files to compile. The tool for programming the microcontroller is Programmers Notepad 2. For this project. It supports several languages. A project exists of a c-file and a makefile. This is an open source text editor with extra features for coding. some data has to be Frederix Maarten June 2006 . It allows companies to change code of the program and help develop this program. Another program needs to be use to compile and upload the code to the microcontroller.2 Programming with WinAVR Layout of WinAVR WinAVR is a set of tools for microcontrollers.1 WINAVR Advantages and disadvantages WinAVR is a freeware and open-source program. By default installation it can be found in c:\winavr\sample. 7. There is a makefile included in WinAVR. The program doesn’t compile the code.

This data is put in the first lines of the makefile: MCU = attiny2313 TARGET = project_GPS SRC = $(TARGET).cof-file are created. An example of the used makefile is in appendix B.sourceforge. the file c:\winavr\bin\install_giveio.Vaasa Polytechnic KHK Geel 32 change to make a working makefile. This can be done in the command browser. The official WinAVR website is http://winavr. The first thing to do is choose a microcontroller and a name for the project.net/projects/winavr/. a .net/ and the program can be downloaded at http://sourceforge.bat has to be installed manually first.hex-file is the file that will be uploaded in the FLASH memory of the microcontroller of the microcontroller. This tool is also included in WinAVR.c F_CPU = 4000000 FORMAT = ihex To determine the programming protocol in the makefile the following data has to be adjusted to: AVRDUDE_PROGRAMMER = dt006 #AVRDUDE_PORT = com1 # programmer connected to serial device AVRDUDE_PORT = lpt1 # programmer connected to parallel device To work with the LPT-port. Frederix Maarten June 2006 . The . It is also possible it make the makefile by the tool Mfile. When a file is compiled.hex-file and a .

Because the data is separated by commas. we use the GPRMC data. it is possible to filter the data on the three signals that follow the GP. it is only possible to count the commas to determine the data we need. so it won’t send every time it receives the GPS data. The actions of the microcontroller are explained in the next flowcharts. Because the first two signals are always the same. the reading can begin. To send the data with the cell phone. it is filtered immediately for the right ID sentence. The different stages are explained in the following flowcharts.1 EXPLAINING THE CODE Flowchart Flowchart of the entire program The flowchart shows how the program must run to complete his task. the AT+CMGS= command is put in from together with the phone number of the receiver. Frederix Maarten June 2006 . This data is stored in the memory of the microcontroller. If the data is correct. For this data. A counter is put on the transmitter.Vaasa Polytechnic KHK Geel 33 8 8. filters the data and transmits the good data to the GSM. When the microcontroller receives the data. The microcontroller reads the data from the GPS.

Vaasa Polytechnic KHK Geel 34 Flowchart of Receive the data Frederix Maarten June 2006 .

When there is an interrupt. This USART will generate an interrupt when data is inserted. the data needs to be checked for the GPRMC sentenceID. it can send the data. the microcontroller can start reading data. The right data starts on the third place in the sentenceID and is separated by “. Flowchart of saving the data If the data is checked. When the counter that counts the commas reaches seven. the microcontroller will read the data from the GPS. Frederix Maarten June 2006 .Vaasa Polytechnic KHK Geel 35 PORTD has to be set to use the USART in the program. If the RMC is matched.”.

I use a counter. Then the message can be send with at the end char(26) which is CTRL – Z. it first need the data “AT+CMGS=”(phone number)”. In my project. To send a message with a GSM.Vaasa Polytechnic KHK Geel 36 Counter to send = 10 No Yes Send AT+CMGS=”(phone number)” Send message Counter = 0 Increment Counter Flowchart of sending the data Sending data with a microcontroller is also done with the USART. Because of this counter the data is not send every time a location is known. Frederix Maarten June 2006 .

2 The code All the libraries that are needed to create a program are included on the top of the code. sends the data Frederix Maarten June 2006 . the checking of the data should begin. unsigned int check. the different functions are created. UDR = data.h> #include <avr/interrupt. This is calculated by fosc −1 16( BAUDRATE ) The clock frequency of the oscillator is 4 MHz and the Baud Rate (speed of the USART is 4800.Vaasa Polytechnic KHK Geel 37 8. #include <avr/io. If there is an interrupt.h> #include <stdio. These are by example Transmit and Receive functions. } // Wait for empty transmit buffer //Put data into buffer. (4000000/(16*4800))-1 = 51. The program always starts at the line int main( ).0833 #define #define #define #define #define #define #define #define COMMA3 3 COMMA4 4 COMMA5 5 COMMA6 6 CR 0x0D LF 0x0A CTRLZ 0x1A SMSCOMMAND 20 //CR and LF are use to send ENTER //The hexadecimal value of CTRL-Z is 0x1A unsigned char IncomingData. //*************************************************// // TRANSMIT // //*************************************************// void USART_Transmit(unsigned char data) { while( ! ( UCSRA & ( 1<<UDRE ) ) ).h> #include <avr/signal. //global variable //this variable is used for a timing function.h> #include <inttypes. In the middle of the program. The variables that not change during the program can be created here too.h> #define DEF_UART 0 #define BAUD 51 //include file for signal interrupts //include files for interrupts //value for UBRR //the baud is the speed at which the microcontroller should check the USART port. From this class other classes can be called.

Read = 0. check = 0. Write = 0. DirEW. PORTB=0x00. UBRRL = BAUD. Frederix Maarten June 2006 . DDRD=0x02. int command[20]. n. UCSRB = _BV(RXEN) | _BV(TXEN) | _BV(RXCIE). but is used to send to the LEDs //PORTD uses 2 bits. counter = 0. DirNS .Vaasa Polytechnic KHK Geel 38 //*************************************************// // MAIN PROGRAM // //*************************************************// int main ( ) { //SET USART UBRRH = DEF_UART. UCSRC = _BV(UCSZ1) | _BV(UCSZ0). Latitude[10] . LenLat. Latitude. //B port output //B port high //port0 on pull up and port1 on 0 asm("sei"). Write . int LenLon. /* maximum 9 characters are possible for writing the data to latitude and longitude because the last character of an array is a Carriage Return */ char Longitude[10] . n = 0. //*****************************// //reserve and set variables// //*****************************// //enables the interrupts /* Read is variable to check the data n is variable to count the commas that have past the check with reading m is used to count the number of bytes needed to store he data Longitude. IncomingData = 0. DirNs and DirEW are used to save the data from the GPS LenLon and LenLat are used to see how long the array for Longitude and Latitude is the counter is used to send the data at certain times */ int Read . // 4800 bps at 4 MHz // Rx Complete Interrupt & Enable Rx/Tx // 8N1 //SET PORTS: PORTB is not needed. PD0 for RXD and PD1 for TXD DDRB=0xFF. int counter. LenLat = 0. LenLon = 0.

command[8] = '"'. while(1) //this makes an infinite loop { //*************************************// // CHECKING OF DATA // //*************************************// /* In this program 3 characters are used to test: RMC This is the signal to start the reading of the right data */ if ( check == 1 ) { if ( Read == 0 ) { if( IncomingData == 'R' ) { Read = 1. } } //check is 1 after every interrupt //and 0 when action is done // check if received char is R //If character is R then check //the next character if ( check == 1 ) { if ( Read == 1 ) { Frederix Maarten June 2006 . command[11] = '4'. command[16] = '5'. command[1] = 'T'. command[6] = 'S'. command[18] = '7'. command[2] = '+'. command[19] = '"'. command[17] = '6'. This is AT+CMGS=“<phone number>” */ command[0] = 'A'. command[3] = 'C'.Vaasa Polytechnic KHK Geel 39 /*set variables of the array command. } check = 0. This array consists of the command to send an SMS. command[15] = '4'. command[4] = 'M'. command[7] = '='. command[14] = '3'. command[13] = '2'. command[12] = '1'. command[9] = '0'. command[10] = '4'. command[5] = 'G'.

.' ) //if the char is a comma //then don't read the char. N-S. } if( IncomingData != 'C' ) { Read = 0. LenLon = 0. but increment n { Frederix Maarten June 2006 .Vaasa Polytechnic KHK Geel 40 if( IncomingData == 'M' ) { Read = 2. n = 0. } check = 0. } } if( check == 1 ) { if( Read == 2 ) { if( IncomingData == 'C' ) { Read = 3.. } if( IncomingData != 'M' ) { Read = 0. the fist sign is a comma */ if( IncomingData == '. } } // check if char is M // check if char is C //*************************************// // READ THE RIGHT DATA // //*************************************// /* All 3 characters are checked and OK The reading of the right data begins Again if check = 1 it should do an action The data is divided in 4 parts which are read separately */ if( check == 1 ) { if( Read == 3 ) { /* data is shown in form of .longitude.. LenLat = 0. lattide. } check = 0. E-W.

Read = 0. counter = counter + 1. } if( n == COMMA5 ) { Longitude[LenLon] = IncomingData. LenLon = LenLon + 1. } if( n == COMMA6 ) { DirEW = IncomingData. LenLat = LenLat + 1.' ) { if( n == COMMA3 ) { Latitude[LenLat] = IncomingData. } if( IncomingData != '.Vaasa Polytechnic KHK Geel 41 n = n + 1. } check = 0. } } } //*************************************// // SENDING THE DATA // //*************************************// /* The data is send in this part Every certain time it has to send a message to another phone The message exists of AT+CMGS="TELEPHONE NUMBER" <CR> The message is send after this with CTRL-Z at the end. */ if( Write == 1 ) { if( counter == 10 ) { Frederix Maarten June 2006 . Write = 1. } if( n == COMMA4 ) { DirNS = IncomingData.

} } } return 1. t == SMSCOMMAND-1 . u++ ) { USART_Transmit( Longitude[u] ). Using a array gives an error on the last char of that array. check = 1. } USART_Transmit( CR ). for( int u = 0 . } //END MAIN //END WHILE LOOP //*************************************************// // RECEIVE // //*************************************************// SIGNAL ( SIG_USART0_RX ) { IncomingData = UDR. //LF for( int v = 0 . //CR USART_Transmit( LF ). v <= LenLat-1 . t++ ) { USART_Transmit( command[t] ). The service command is AT+CMGS= " (phone number) " <ENTER> message <CTRL><Z>. USART_Transmit( '. Longitude E or W> and the message will be send after CTRL-Z */ for( int t = 0 . the message will be like this: <Latitude N or S . u <= LenLon-1 .Vaasa Polytechnic KHK Geel 42 /* To initiate the SMS service. This is only to check if //data is received and transmitted Frederix Maarten June 2006 . } //Store received byte //Show byte on PORTB. v++ ) { USART_Transmit( Latitude[v] ). } USART_Transmit( DirNS ). counter = 0. On the GSM. AT+CMGS is written in the array command[]. USART_Transmit( CTRLZ ). PORTB = IncomingData. } USART_Transmit( DirEW ).' ).

In the future. Compare to assemble it allows the user to write better programs that are also better comprehendible for people who don’t work with microcontrollers in everyday life. etc. The choice of the program is very important for an application. By example <CTRL> + Z is char 26. Frederix Maarten June 2006 . The microcontroller is an Atmel ATTINY2313. For the GPS it was important to connect it and have insight in the data that is transmitted over the serial line. the use of GPS will rise rapidly. I learned to work with GPS. But GPS is still a military project. Advantages as higher accuracy and service integrity are used to convince companies and people. In the beginning. Is contains an identifier for several programming languages like Java. The European Galileo project is being made to break the American monopoly in this field. After reading the datasheet and testing some examples. An introduction in the world of microcontrollers is still an advantage. Atmel microcontrollers and GSM.Vaasa Polytechnic KHK Geel 43 CONCLUSION During my practical training. Codevision AVR is easy to learn and can be a step to the more powerful WinAVR. I had an introduction from my school KHK Geel. C. The AVR technology that Atmel uses causes the microcontroller to work with c-language instructions. Not only the hardware is important but also software is important to make application. This standard is the same for every receiver and therefore easy to use. It is also connected with a serial cable and uses simple commands. Special combinations of letters can be found in ASCII tables. my biggest concern was to use the GSM-module. WinAVR is a powerful program that can be used as a notepad. GPS is used in many applications. It is one of the smallest and cheapest microcontrollers of the Atmel series. These years. This data is build by the NMEA-0183 standard. This commercial product has much support from other countries and will probably compete with GPS in the following years. the use was not so hard.

(A=entered or perpendicular passed) = Checksum 9.2 $GPRMC RMC = Recommended Minimum Specific GPS/TRANSIT Data 1 2 3 4 5 6 7 = UTC of position fix = Data status (V=navigation receiver warning) = Latitude of fix = N or S = Longitude of fix = E or W = Speed over ground in knots Frederix Maarten June 2006 .Vaasa Polytechnic KHK Geel 44 9 9.1.1 APPENDIX Appendix A: NMEA-0183 standard $GPRMB RMB = Recommended Minimum Navigation Information 1 2 3 4 5 6 7 8 9 10 11 12 13 14 = Data Status (V=navigation receiver warning) = Crosstrack error in nautical miles = Direction to steer (L or R) to correct error = Origin waypoint ID# = Destination waypoint ID# = Destination waypoint latitude = N or S = Destination waypoint longitude = E or W = Range to destination in nautical miles = Bearing to destination.1 9. degrees True = Destination closing velocity in knots = Arrival status.1.

GPS fix) = Number of satellites in use [not those in view] = Horizontal dilution of position = Antenna altitude above/below mean sea level (geoids) = Meters (Antenna height unit) = Geoidal separation (Diff. 1=GPS fix. between WGS-84 earth ellipsoid and mean sea level. 2=Diff. subtracts from true course) = E or W = Checksum 9.1. -=geoid is below WGS-84 ellipsoid) 12 13 14 15 = Meters (Units of geoidal separation) = Age in seconds since last update from diff.4 $GPVTG VTG = Actual track made good and speed over ground 1 2 3 = Track made good = Fixed text 'T' indicates that track made good is relative to true north = not used Frederix Maarten June 2006 .1.Vaasa Polytechnic KHK Geel 45 8 9 10 11 12 = Track made good in degrees True = UT date = Magnetic variation degrees (Easterly var.3 $GPGGA GGA = Global Positioning System Fix Data 1 2 3 4 5 6 7 8 9 10 11 = UTC of Position = Latitude = N or S = Longitude = E or W = GPS quality indicator (0=invalid. reference station = Diff. reference station ID# = Checksum 9.

5 $GPRMA RMA = Navigation data from present position 1 2 3 4 5 6 7 8 9 10 11 12 = Data status = Latitude = N/S = longitude = W/E = not used = not used = Speed over ground in knots = Course over ground = Variation = Direction of variation E/W = Checksum 9. forced to operate in 2D or 3D A=Automatic. 3D/2D 2 = Mode: 1=Fix not available 2=2D Frederix Maarten June 2006 . 1 = Mode: M=Manual.6 $GPGSA GSA = GPS receiver operating mode. and DOP values.1. SVs used for navigation.Vaasa Polytechnic KHK Geel 46 4 5 6 7 8 9 = not used = Speed over ground in knots = Fixed text 'N' indicates that speed over ground in knots = Speed over ground in kilometres/hour = Fixed text 'K' indicates that speed over ground is in kilometres/hour = Checksum 9.1.

Vaasa Polytechnic

KHK Geel

47

3=3D 3-14 = IDs of SVs used in position fix (null for unused fields) 15 16 17 = PDOP = HDOP = VDOP

9.1.7

$GPGSV

GSV = Number of SVs in view, PRN numbers, elevation, azimuth & SNR values. 1 2 3 4 5 6 7 = Total number of messages of this type in this cycle = Message number = Total number of SVs in view = SV PRN number = Elevation in degrees, 90 maximum = Azimuth, degrees from true north, 000 to 359 = SNR, 00-99 dB (null when not tracking)

8-11 = Information about second SV, same as field 4-7 12-15= Information about third SV, same as field 4-7 16-19= Information about fourth SV, same as field 4-7

9.2

Appendix B: The makefile

#---------------------------------------------------------------------------# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. # # Released to the Public Domain # #---------------------------------------------------------------------------# On command line: # # make all = Make software. # # make clean = Clean out built project files. # # make coff = Convert ELF to AVR COFF. # # make extcoff = Convert ELF to AVR Extended COFF. # # make program = Download the hex file to the device, using avrdude. # Please customize the avrdude settings below first! #
Frederix Maarten June 2006

Vaasa Polytechnic

KHK Geel

48

# make debug = Start either simulavr or avarice as specified for debugging, # with avr-gdb or avr-insight as the front end for debugging. # # make filename.s = Just compile filename.c into the assembler code only. # # make filename.i = Create a preprocessed source file for use in submitting # bug reports to the GCC project. # # To rebuild project do "make clean" then "make all". #---------------------------------------------------------------------------MCU = attiny2313 TARGET = gps_data SRC = $(TARGET).c # Processor frequency. # This will define a symbol, F_CPU, in all source code files equal to the # processor frequency. You can then use this symbol in your source code to # calculate timings. Do NOT tack on a 'UL' at the end, this will be done # automatically to create a 32-bit value in your source code. F_CPU = 4000000 # Output format. (can be srec, ihex, binary) FORMAT = ihex # Target file name (without extension). # List C source files here. (C dependencies are automatically generated.) # List Assembler source files here. # # # # # # Make them always end in a capital .S. Files ending in a lowercase .s will not be considered source files but generated files (assembler output from the compiler), and will be deleted upon "make clean"! Even though the DOS/Win* filesystem matches both .s and .S the same, it will preserve the spelling of the filenames, and gcc itself does care about how the name is spelled on its command-line.

ASRC =

# Optimization level, can be [0, 1, 2, 3, s]. # 0 = turn off optimization. s = optimize for size. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) OPT = s # Debugging format. # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. # AVR Studio 4.10 requires dwarf-2. # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. DEBUG = dwarf-2 # List any extra directories to look for include files here. # Each directory must be seperated by a space. # Use forward slashes for directory separators. # For a directory that has spaces, enclose it in quotes. EXTRAINCDIRS =

Frederix Maarten

June 2006

Vaasa Polytechnic

KHK Geel

49

# Compiler flag to set the C Standard level. # c89 = "ANSI" C # gnu89 = c89 plus GCC extensions # c99 = ISO C99 standard (not yet fully implemented) # gnu99 = c99 plus GCC extensions CSTANDARD = -std=gnu99 # Place -D or -U options here CDEFS = -DF_CPU=$(F_CPU)UL # Place -I options here CINCS = #---------------- Compiler Options ---------------# -g*: generate debugging information # -O*: optimization level # -f...: tuning, see GCC manual and avr-libc documentation # -Wall...: warning level # -Wa,...: tell GCC to pass this to the assembler. # -adhlns...: create assembler listing CFLAGS = -g$(DEBUG) CFLAGS += $(CDEFS) $(CINCS) CFLAGS += -O$(OPT) CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums CFLAGS += -Wall -Wstrict-prototypes CFLAGS += -Wa,-adhlns=$(<:.c=.lst) CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) CFLAGS += $(CSTANDARD)

#---------------- Assembler Options ---------------# -Wa,...: tell GCC to pass this to the assembler. # -ahlms: create listing # -gstabs: have the assembler create line number information; note that # for use in COFF files, additional information about filenames # and function names needs to be present in the assembler source # files -- see avr-libc docs [FIXME: not yet described there] ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs #---------------- Library Options ---------------# Minimalistic printf version PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min # Floating point printf version (requires MATH_LIB = -lm below) PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt # If this is left blank, then it will use the Standard printf version. PRINTF_LIB =

Frederix Maarten

June 2006

#AVRDUDE_PORT = com1 # programmer connected to serial device AVRDUDE_PORT = lpt1 # programmer connected to serial device #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).--defsym=__heap_end=0x80ffff # 64 KB of external RAM. # #AVRDUDE_PROGRAMMER = stk500 AVRDUDE_PROGRAMMER = dt006 # com1 = serial port.bss) and heap (malloc()). # -Map: create map file # --cref: add cross reference to map file LDFLAGS = -Wl. SCANF_LIB = #SCANF_LIB = $(SCANF_LIB_MIN) #SCANF_LIB = $(SCANF_LIB_FLOAT) MATH_LIB = -lm #---------------.Vaasa Polytechnic KHK Geel 50 #PRINTF_LIB = $(PRINTF_LIB_MIN) #PRINTF_LIB = $(PRINTF_LIB_FLOAT) # Minimalistic scanf version SCANF_LIB_MIN = -Wl.-u.-Map=$(TARGET). #EXTMEMOPTS = -Wl.data/.-#defsym=__heap_end=0x80ffff EXTMEMOPTS = #---------------. starting after internal RAM (ATmega128!).-Tdata=0x801100...map.vfscanf -lscanf_flt # If this is left blank.Linker Options ---------------# -Wl.-u. then it will use the Standard scanf version. # only used for heap (malloc()). Use lpt1 to connect to parallel port. starting after internal RAM (ATmega128!)..: tell GCC to pass this to linker. # used for variables (.Programming Options (avrdude) ---------------# Programming hardware: alf avr910 avrisp bascom bsd # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 # # Type: avrdude -c ? # to get a full listing.--cref LDFLAGS += $(EXTMEMOPTS) LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) #---------------.hex Frederix Maarten June 2006 .vfscanf -lscanf_min # Floating point + %[ scanf version (requires MATH_LIB = -lm below) SCANF_LIB_FLOAT = -Wl.--defsym=__heap_start=0x801100. #EXTMEMOPTS = -Wl.External Memory Options ---------------# 64 KB of external RAM.

Debugging Options ---------------# For simulavr only . simulavr. #AVRDUDE_ERASE_COUNTER = -y # Uncomment the following if you do /not/ wish a verification to be # performed after programming the device. SHELL = sh Frederix Maarten June 2006 .target MCU frequency. # DEBUG_UI = gdb DEBUG_UI = insight # Set the debugging back-end to either avarice. # see avrdude manual. #AVRDUDE_VERBOSE = -v –v AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) –c $(AVRDUDE_PROGRAMMER) AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) #---------------. #AVRDUDE_NO_VERIFY = -V # Increase verbosity level.Vaasa Polytechnic KHK Geel 51 # Uncomment the following if you want avrdude's erase cycle counter.nongnu.org/projects/avrdude> # to submit bug reports. DEBUG_MFREQ = $(F_CPU) # Set the DEBUG_UI to either gdb or insight. See <http://savannah. DEBUG_PORT = 4242 # Debugging host used to communicate between GDB / avarice / simulavr. Please use this when submitting bug # reports about avrdude. DEBUG_BACKEND = avarice #DEBUG_BACKEND = simulavr # GDB Init Filename. GDBINIT_FILE = __avr_gdbinit # When using avarice settings for the JTAG JTAG_DEV = /dev/com1 # Debugging port used to communicate between GDB / avarice / simulavr. DEBUG_HOST = localhost #===================================================== # Define programs and commands. normally # # just set to localhost unless doing some sort of crazy debugging when avarice is running on a different computer. # Note that this counter needs to be initialized first using -Yn.

eep Frederix Maarten June 2006 . $(CFLAGS) $(GENDEPFLAGS) ALL_ASFLAGS = -mmcu=$(MCU) -I.d # Combine all necessary flags and optional flags.S=.elf hex: $(TARGET).Vaasa Polytechnic KHK Geel 52 CC = avr-gcc OBJCOPY = avr-objcopy OBJDUMP = avr-objdump SIZE = avr-size NM = avr-nm AVRDUDE = avrdude REMOVE = rm –f COPY = cp WINSHELL = cmd # Define Messages # English MSG_ERRORS_NONE = Errors: none MSG_BEGIN = -------.c=.c=. -x assembler-with-cpp $(ASFLAGS) # Default target.end -------MSG_SIZE_BEFORE = Size before: MSG_SIZE_AFTER = Size after: MSG_COFF = Converting to AVR COFF: MSG_EXTENDED_COFF = Converting to AVR Extended COFF: MSG_FLASH = Creating load file for Flash: MSG_EEPROM = Creating load file for EEPROM: MSG_EXTENDED_LISTING = Creating Extended Listing: MSG_SYMBOL_TABLE = Creating Symbol Table: MSG_LINKING = Linking: MSG_COMPILING = Compiling: MSG_ASSEMBLING = Assembling: MSG_CLEANING = Cleaning project: # Define all object files.lst) $(ASRC:.hex eep: $(TARGET).o) $(ASRC:. LST = $(SRC:. OBJ = $(SRC:.o) # Define all listing files. all: begin gccversion sizebefore build sizeafter end build: elf hex eep lss sym elf: $(TARGET). GENDEPFLAGS = -MD -MP -MF .dep/$(@F). ALL_CFLAGS = -mmcu=$(MCU) -I.S=.begin -------MSG_END = -------.lst) # Compiler flags to generate dependency files. # Add target processor to flags.

$(ELFSIZE). gdb-config: @$(REMOVE) $(GDBINIT_FILE) @echo define reset >> $(GDBINIT_FILE) @echo SIGNAL SIGHUP >> $(GDBINIT_FILE) @echo end >> $(GDBINIT_FILE) @echo file $(TARGET). fi # Display compiler version information. # AVR Studio 3.eep $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) # Generate avr-gdb config/init file which does the following: # define the reset signal.sym # Eye candy.elf.lss sym: $(TARGET).Vaasa Polytechnic KHK Geel 53 lss: $(TARGET). \ $(AVRMEM) 2>/dev/null.hex $(TARGET). begin: @echo @echo $(MSG_BEGIN) end: @echo $(MSG_END) @echo # Display size of file. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET). echo $(MSG_SIZE_BEFORE). program: $(TARGET). echo.x does not check make's exit code but relies on # the following magic strings to be generated by the compile job.sh $(TARGET). echo. \ $(AVRMEM) 2>/dev/null. gccversion : @$(CC) –version # Program the device. connect to target. load the target file.elf AVRMEM = avr-mem. then echo. then echo.elf >> $(GDBINIT_FILE) @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) ifeq ($(DEBUG_BACKEND). and set # a breakpoint at main().simulavr) @echo load >> $(GDBINIT_FILE) Frederix Maarten June 2006 .elf $(MCU) sizebefore: @if test -f $(TARGET). echo $(MSG_SIZE_AFTER).elf. $(ELFSIZE). fi sizeafter: @if test -f $(TARGET).hex ELFSIZE = $(SIZE) -A $(TARGET).

elf @echo @echo $(MSG_EXTENDED_COFF) $(TARGET).elf @echo @echo $(MSG_FLASH) $@ $(OBJCOPY) -O $(FORMAT) -R . .cof $(COFFCONVERT) -O coff-avr $< $(TARGET).eeprom $< $@ %.Press enter when "waiting to connect" message displays.Vaasa Polytechnic KHK Geel 54 endif @echo break main >> $(GDBINIT_FILE) debug: gdb-config $(TARGET).data-0x800000 \ --change-section-address .elf @echo @echo $(MSG_COFF) $(TARGET).noinit-0x800000 \ --change-section-address . COFFCONVERT=$(OBJCOPY) --debugging \ --change-section-address .cof # Create final output files (.eeprom-0x810000 coff: $(TARGET).cof $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).bss-0x800000 \ --change-section-address .eep: %. @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ $(TARGET).hex.cof extcoff: $(TARGET).elf ifeq ($(DEBUG_BACKEND).hex: %. %.eep) from ELF output file.eeprom --set-section-flags=.elf $(DEBUG_HOST):$(DEBUG_PORT) @$(WINSHELL) /c pause Else @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ $(DEBUG_MFREQ) --port $(DEBUG_PORT) endif @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.eeprom="alloc. avarice) @echo Starting AVaRICE .elf @echo @echo $(MSG_EEPROM) $@ -$(OBJCOPY) -j .eeprom=0 -O $(FORMAT) $< $@ Frederix Maarten June 2006 .load" \ --change-section-lma .

elf . %. %. %.i : %.Vaasa Polytechnic KHK Geel 55 # Create extended listing file from ELF output file.s : %. clean: begin clean_list end clean_list : @echo @echo $(MSG_CLEANING) $(REMOVE) $(TARGET).elf @echo @echo $(MSG_EXTENDED_LISTING) $@ $(OBJDUMP) -h -S $< > $@ # Create a symbol table from ELF output file.sym: %.elf @echo @echo $(MSG_SYMBOL_TABLE) $@ $(NM) -n $< > $@ # Link: create ELF output file from object files.c $(CC) -S $(ALL_CFLAGS) $< -o $@ # Assemble: create object files from assembler source files.elf $(REMOVE) $(TARGET).elf: $(OBJ) @echo @echo $(MSG_LINKING) $@ $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) # Compile: create object files from C source files. $(CFLAGS) $< -o $@ # Target: clean project.sym $(REMOVE) $(TARGET).lss Frederix Maarten June 2006 .hex $(REMOVE) $(TARGET).c @echo @echo $(MSG_COMPILING) $< $(CC) -c $(ALL_CFLAGS) $< -o $@ # Compile: create assembler files from C source files.S @echo @echo $(MSG_ASSEMBLING) $< $(CC) -c $(ALL_ASFLAGS) $< -o $@ # Create preprocessed source for use in sending a bug report.map $(REMOVE) $(TARGET).cof $(REMOVE) $(TARGET).o : %.PRECIOUS : $(OBJ) %. .lss: %.c $(CC) -E -mmcu=$(MCU) -I. %. %.SECONDARY : $(TARGET).o : %. %.eep $(REMOVE) $(TARGET).

c=.d) . the checking of the data should begin.h> #include <avr/interrupt.h> #include <stdio. //*************************************************// // TRANSMIT // //*************************************************// void USART_Transmit(unsigned char data) { while( ! ( UCSRA & ( 1<<UDRE ) ) ).h> #include <avr/signal.h> #include <inttypes. If there is an interrupt. This is calculated by fosc −1 16( BAUDRATE ) The clock frequency of the oscillator is 4 MHz and the Baud Rate (speed of the USART is 4800. unsigned int check. -include $(shell mkdir .dep/*) # Listing of phony targets.dep 2>/dev/null) $(wildcard . (4000000/(16*4800))-1 = 51.h> #define DEF_UART 0 #define BAUD 51 //include file for signal interrupts //include files for interrupts //value for UBRR //the baud is the speed at which the microcontroller should check the USART port.PHONY : all begin finish end sizebefore sizeafter gccversion \ build elf hex eep lss sym coff extcoff \ clean clean_list program debug gdb-config 9.s) $(SRC:.0833 #define #define #define #define #define #define #define #define COMMA3 3 COMMA4 4 COMMA5 5 COMMA6 6 CR 0x0D LF 0x0A CTRLZ 0x1A SMSCOMMAND 20 //CR and LF are use to send ENTER //The hexadecimal value of CTRL-Z is 0x1A unsigned char IncomingData. .3 Appendix C: The program #include <avr/io.Vaasa Polytechnic KHK Geel 56 $(REMOVE) $(REMOVE) $(REMOVE) $(REMOVE) $(REMOVE) $(OBJ) $(LST) $(SRC:.c=. } // Wait for empty transmit buffer //Put data into buffer. //global variable //this variable is used for a timing function.dep/* # Include the dependency files. sends the data Frederix Maarten June 2006 . UDR = data.

Read = 0. Latitude[10] . //B port output //B port high //port0 on pull up and port1 on 0 asm("sei"). Write . DDRD=0x02. Latitude. // 4800 bps at 4 MHz // Rx Complete Interrupt & Enable Rx/Tx // 8N1 //SET PORTS: PORTB is not needed. but is used to send to the LEDs //PORTD uses 2 bits. //*****************************// //reserve and set variables// //*****************************// //enables the interrupts /* Read is variable to check the data n is variable to count the commas that have past the check with reading m is used to count the number of bytes needed to store he data Longitude. DirNS . PD0 for RXD and PD1 for TXD DDRB=0xFF. IncomingData = 0. UCSRB = _BV(RXEN) | _BV(TXEN) | _BV(RXCIE). DirEW. UBRRL = BAUD. n. LenLat. /* maximum 9 characters are possible for writing the data to latitude and longitude because the last character of an array is a Carriage Return */ char Longitude[10] . LenLat = 0. PORTB=0x00. Frederix Maarten June 2006 . DirNs and DirEW are used to save the data from the GPS LenLon and LenLat are used to see how long the array for Longitude and Latitude is the counter is used to send the data at certain times */ int Read . LenLon = 0.Vaasa Polytechnic KHK Geel 57 //*************************************************// // MAIN PROGRAM // //*************************************************// int main ( ) { //SET USART UBRRH = DEF_UART. UCSRC = _BV(UCSZ1) | _BV(UCSZ0). Write = 0. n = 0. int LenLon. check = 0. int command[20]. int counter.

command[18] = '7'. command[15] = '4'. command[13] = '2'. command[12] = '1'. command[19] = '"'. command[2] = '+'. command[16] = '5'. command[9] = '0'. This is AT+CMGS=“<phone number>” */ command[0] = 'A'. command[10] = '4'. This array consists of the command to send an SMS. command[4] = 'M'. command[5] = 'G'. /*set variables of the array command. command[17] = '6'.Vaasa Polytechnic KHK Geel 58 counter = 0. command[6] = 'S'. command[11] = '4'. command[1] = 'T'. } } if ( check == 1 ) { if ( Read == 1 ) { //check is 1 after every interrupt //and 0 when action is done // check if received char is R //If character is R then check //the next character Frederix Maarten June 2006 . command[7] = '='. while(1) //this makes an infinite loop { //*************************************// // CHECKING OF DATA // //*************************************// /* In this program 3 characters are used to test: RMC This is the signal to start the reading of the right data */ if ( check == 1 ) { if ( Read == 0 ) { if( IncomingData == 'R' ) { Read = 1. command[14] = '3'. } check = 0. command[3] = 'C'. command[8] = '"'.

lattide.. n = 0. LenLon = 0.Vaasa Polytechnic KHK Geel 59 if( IncomingData == 'M' ) { Read = 2. } check = 0.. N-S.longitude. the fist sign is a comma */ if( IncomingData == '. LenLat = 0. } } if( check == 1 ) { if( Read == 2 ) { if( IncomingData == 'C' ) { Read = 3. but increment n { Frederix Maarten June 2006 . } check = 0. E-W.' ) //if the char is a comma //then don't read the char. } } // check if char is M // check if char is C //*************************************// // READ THE RIGHT DATA // //*************************************// /* All 3 characters are checked and OK The reading of the right data begins Again if check = 1 it should do an action The data is divided in 4 parts which are read separately */ if( check == 1 ) { if( Read == 3 ) { /* data is shown in form of . } if( IncomingData != 'C' ) { Read = 0.. } if( IncomingData != 'M' ) { Read = 0.

LenLat = LenLat + 1.' ) { if( n == COMMA3 ) { Latitude[LenLat] = IncomingData. } } } //*************************************// // SENDING THE DATA // //*************************************// /* The data is send in this part Every certain time it has to send a message to another phone The message exists of AT+CMGS="TELEPHONE NUMBER" <CR> The message is send after this with CTRL-Z at the end. LenLon = LenLon + 1. */ if( Write == 1 ) { if( counter == 10 ) { Frederix Maarten June 2006 .Vaasa Polytechnic KHK Geel 60 n = n + 1. Write = 1. } if( IncomingData != '. } check = 0. Read = 0. counter = counter + 1. } if( n == COMMA6 ) { DirEW = IncomingData. } if( n == COMMA5 ) { Longitude[LenLon] = IncomingData. } if( n == COMMA4 ) { DirNS = IncomingData.

PORTB = IncomingData. } //Store received byte //Show byte on PORTB. counter = 0. //CR USART_Transmit( LF ). v <= LenLat-1 . } } } return 1.Vaasa Polytechnic KHK Geel 61 /* To initiate the SMS service. This is only to check if //data is received and transmitted Frederix Maarten June 2006 . u <= LenLon-1 . On the GSM. } USART_Transmit( CR ). t++ ) { USART_Transmit( command[t] ). for( int u = 0 . USART_Transmit( CTRLZ ). check = 1.' ). The service command is AT+CMGS= " (phone number) " <ENTER> message <CTRL><Z>. t == SMSCOMMAND-1 . the message will be like this: <Latitude N or S . } USART_Transmit( DirNS ). } USART_Transmit( DirEW ). u++ ) { USART_Transmit( Longitude[u] ). AT+CMGS is written in the array command[]. } //END MAIN //END WHILE LOOP //*************************************************// // RECEIVE // //*************************************************// SIGNAL ( SIG_USART0_RX ) { IncomingData = UDR. USART_Transmit( '. //LF for( int v = 0 . Longitude E or W> and the message will be send after CTRL-Z */ for( int t = 0 . v++ ) { USART_Transmit( Latitude[v] ). Using a array gives an error on the last char of that array.

pdf Atmel (2005) Datasheet Atmel ATTINY2313 Found 23th of August 2005 on the internet: http://www. Florence: Thomson Delmar Learning Internet Ma Chao.wavecom.atmel.htm#nmea John Scourias (1994) Information of the GSM-network infrastructure.fi/dyn/products/product_card.de/~jutta/gsm/js-intro.gpsinformation. Programming and Customizing the AVR microcontroller. Embedded C Programming and the Atmel AVR. Larry O’Cull (2002).cs.Vaasa Polytechnic KHK Geel 62 SOURCES Books Dhananjay V.asp?part_id=3229 Wavecom (2004) Datasheets of Wavecom QUICK Q2501 Found 23th of August 2005 on the internet: http://www. Barnett.pdf Wavecom (2004) Datasheets of Wavecom QUICK Q2501 GPS commands Found 23th of August 2005 on the internet: http://www. Gadre (2000).org/dale/nmea.fi/journal/documents/issue1/gps.wavecom.pdf Dale DePriest Information about the NMEA-0186 standard.tuberlin.com/media/files/support/Hard_platforms/Modules/Q2501B/Firmw are_release_v650A/AT_commands_manual/AT_Commands_Interface_Guide_for_revisi on_X50a.html Frederix Maarten June 2006 .atmel. Hightstown: McGraw-Hill’s professional Book Grouup composition unit Richard H. Lin Ming (2003) GPS-GSM Mobile Navigator Found 24th of August 2005 on the internet: http://www. Sarah Cox.com/media/files/support/Hard_platforms/Modules/Q2501B/Firmw are_release_v650A/AT_commands_manual/Q2501_Specific_GPS_AT_commands_Interf ace_Guide. Found 14th of September 2005 on the internet: http://www. Found 14th of September 2005 on the internet: http://kbs.

Sign up to vote on this title
UsefulNot useful