Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Gegradueerde in elektriciteit
Optie elektronica
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
INTRODUCTION
My project took place in Technobotnia in Finland. I was there from the 18th of August
until the 14th of November.
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.
TABLE OF CONTENTS
1 INTRODUCTION TO FINLAND ............................................................... 5
1.1 Finland ................................................................................................. 5
3 GSM ................................................................................................... 12
3.1 GSM network...................................................................................... 12
3.2 SMS.................................................................................................... 13
3.2.1 Use of the Q2501 GSM with SMS.............................................................. 13
6 CODEVISION AVR............................................................................... 27
6.1 Advantages and disadvantages .......................................................... 27
6.2 Programming ..................................................................................... 27
6.3 Uploading the code ............................................................................ 29
7 WINAVR ............................................................................................. 31
7.1 Advantages and disadvantages .......................................................... 31
7.2 Programming with WinAVR ................................................................ 31
CONCLUSION.................................................................................................... 43
9 APPENDIX .......................................................................................... 44
9.1 Appendix A: NMEA-0183 standard ..................................................... 44
9.1.1 $GPRMB................................................................................................44
9.1.2 $GPRMC................................................................................................44
9.1.3 $GPGGA................................................................................................45
9.1.4 $GPVTG ................................................................................................45
9.1.5 $GPRMA................................................................................................46
9.1.6 $GPGSA ................................................................................................46
9.1.7 $GPGSV ................................................................................................47
SOURCES .......................................................................................................... 62
1 INTRODUCTION TO FINLAND
For my practical training, I worked in Technobotnia. This is a Research centre of
Vaasan Ammattikorkeakoulu,Vaasan Yliopisto and Svenska Yrkeshögskolan. Vaasa is situated in
the middle of Finland.
1.1 Finland
Map of Finland
Finland is a Scandinavian country. It has borders with Norway, Sweden and Russia. A third of the
country is situated north of the Arctic Circle. It extends over a length of 1200 km from the north to the
south and about 550 from the west to the east. Different kind of geography can be found over the
entire country. In the North of Finland is a part of Lapland. A famous city in Lapland is Rovaniemi.
This is the city of Santa Claus. In Finland there are about 55000 lakes. Most of them are in the East
of Finland. All the lakes together cover about 10% of the country. A Big city in the east is Juväskylä.
This is also a big city for students. The north of Finland is known for its archipelagos. It exists of
more than thousands of islands. Most of the population in situated in these areas. Big cities are
Tampere, Turku, Oulu en Helsinki. Helsinki is the capital of Finland and has a population of about
500000 inhabitants. This is much compared to all the rest of Finland. The entire population is
5000000 people. The mother tongue in Finland is Finnish and Swedish. About 6% of the people
speak Swedish. Small minorities in the north speak Sami. This is the language of the Sami
civilisation which is still present in Lapland.
Vaasa is a city in the north of Finland. It is about 600km from Helsinki. It was the capital of Finland in
1917. Now it is a city for students. Over 10 000 people come to study in one of the schools every
year. In Vaasa about 25% of the people speak Swedish on a population of 57 000 people.
Technobotnia Vaasa
3 = SIM-card socket
4 = Status-LED’s
available
Every position on earth can be pointed in the geographic coordinate system. This
system exists of a longitude and latitude.
The longitude describes the place of a location based on the Prime Meridian. The
meridian is in Greenwich (UK).It is represented by the vertical lines on the map. 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. It is
represented by the horizontal lines on the map. The North Pole and the South Pole are
90 degree from the equator. The equator is the 0 degree line.
Map of Earth with longitude and latitude lines. The lines are actually circles around the
globe.
2.2 GPS
GPS stands for Global Positioning System. It is a worldwide navigation system that is
used to calculate the position of a receiver inside the geographic system. It is
developed by the US Department of Defence. The original name of the project was
NAVSTAR (Navigation System with Timing And Ranging). The GPS-system is a network
of 24 satellites. These satellites have 6 orbits around earth and are on an altitude of
20000 km. They move with a speed of 14000km/hour. Each position on earth can
receive a signal of at least four different satellites. Three satellites are needed to find
an exact position on earth. To calculate an altitude the fourth satellite is needed too.
The receiver calculates how far it is removed from the satellites and calculates his
position with this information. Here is shown why three satellites are necessary to
calculate one point.
Only one satellite is available. The distance from the satellite to the receiver is the
same over the entire circle.
In this case two satellites are available. The second satellite will narrow the position
down to two points. These two points are the intersections between the two circles.
A third satellite is available. The intersection between the three satellites is always on
one point only. This is the location of the receiver. Also other systems work the same
way as GPS. Other similar systems are GLONASS and EGNOS which are developed by
Russia and Europe. By 2008 the EGNOS program should be replaced by GALILEO.
2.3 NMEA-0183
NMEA is National Marine Electronics Association. The NMEA standard defines the
protocol used for data communication between the GPS-receiver and an external
interface. All the data is organised in sentences with a different sentenceID. A list of the
different sentenceID that are used by the Q2501 is listed the appendix. In this program
only the $GPRMC is used to filter the data. 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.
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 position is valid if more than three
satellites are detected.
Latitude, N/S :
Latitude of the current position
Longitude, E/W :
Longitude of the current position
UTC date :
Date of fix (UTC-date)
Magnetic variation :
It is the magnetic variation. If the magnetic
variation is incorrect, this will cause a directional
bias in the GPS.
Checksum
In the receiver is a list of all the satellites. This list is updated regularly so the
information stays correct at any moment. 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. Because the radio waves have a known speed,
the receiver can than calculate the position based on this time. This position is
translated in the longitude and the latitude of the receiver. By saving this position and
comparing it with the next calculation it is possible to determine the speed. The full
NMEA-0183 standard is included in appendix A.
To communicate between a PC and the GPS-receiver, the serial port of the GSM module
is used and connected to the serial port of the computer. On the computer, the
HyperTerminal can be used to program the module. The default settings of the GPS are
9600bps, 8 data bits, no parity and hardware flow control. A list of the commands for
the GPS receiver is in the appendix.
3 GSM
GSM is the Global System for Mobile communications. It is developed in Europe in the early 1980s.
Each country developed its own standard. Because these systems were incompatible, the
Conference of European Posts and Telegraphs formed the study group Groupe Spécial Mobile to
develop and study a mobile system for Europe. The criteria for the system were:
- good subjective speech quality
- low terminal and service cost
- support for international roaming
- ability to support handheld terminals
- spectral efficiency
- ISDN compatible
The GSM network is build with a cellular structure. Each cell of the network has its own Base Station
Transceiver. The Base Station Controller provides the connection between several Transceivers. In
smaller areas, Multiple Transceivers can be connected to one Controller.
The Network and Switching subsystem is used to manage the communications between cell phones
and the other telephone networks.
The Operation and Support subsystem oversees the proper operation and setup of the network.
3.2 SMS
SMS is the abbreviation of Short Message Service. It can send short alphanumeric
messages between mobile phones, PDA, etc
The GSM chip works on a default value of 115200bps. For my project, I had to use
4800bps because this is the speed of the GPS and the microcontroller. To set the speed
in the GSM use the following commands
If the speed of the GSM is the same as the speed of the microcontroller, it is possible to
use the GSM. The SMS service can be used with following commands.
4 ATMEL ATTINY2313
To connect the GPS and the GSM I use a microcontroller. For this project this
microcontroller is an ATMEL ATTINY2313. The ATTINY2313 works on a Tietomyrsky Oy
EXB2313 programming and testing board.
1 = Microcontroller ATTINY2313
3 = The LED’s are used to see that data is send. These are connected to
PORTB
The ROM memory stores the system program. The difference with RAM memory is that
it can only be read and not be written. The I/O is the bus to transfer all the data
between the different parts.
The ATMEL AVR is part of the ATMEL RISC family. RISC is an instruction set for the
computers, microcontrollers, etc. It is the abbreviation of RISC is Reduced Instruction
Set Computer. It is the successor of the CISC instruction set. CISC is Complex
Instruction Set Computer. The advantages of RISC are easy to program, pipelining, all
the instruction use the same numbers of bits, only few instructions and modes and
more than 1 register for each functions.
Pipelining is a technique where every process is divided in multiple smaller sub
processes. Each sub process can be send to a unit that is designed for the instruction.
The advantage of this technique is that multiple units can work at the same time.
Because it is an AVR microcontroller, it uses Harvard architecture to connect the
several components to each other. This means that one 8-bit data bus is uses for the
communication between the different parts of the microcontroller. This architecture is
faster that the Von Neumann architecture. In the Von Neumann architecture, 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.
Crystal Oscillator
The microcontroller can be connected to other devices with its ports. In this
microcontroller there are three ports available. The ports are named PORTA, PORTB
and PORTD. Each port exists of a number of pins which can be used simultaneously.
The pin map of this microcontroller is given below. It is a 20 pin s PDIP package.
Pins:
1 PA2 20 VCC
2 PD0 19 PB7
3 PD1 18 PB6
4 PA1 17 PB5
5 PA0 16 PB4
6 PD2 15 PB3
7 PD3 14 PB2
8 PD4 13 PB1
9 PD5 12 PB0
10 GND 11 PD6
All the ports in the microcontroller are bidirectional input/output ports. This means that
they can be set as input or output. The settings can be adjusted in the register DDxn,
PORTxn and PINxn. PINxn is the current value of the pin. The DDxn register sets the
pin as an output or input. If the corresponding pin is input, the value of DDxn is 0. The
PORTxn register can set a pull-up resistor to choose a default value. The pull-up
resistor creates a default value for each pin. When the default value of an input or
output supposed to be high, then the pull-up resistor has to be set. The pull-up resistor
is a transistor. When it is enabled, it will pass the 5V from the source to the min. This
setting for the pull-up resistor happens in the PORT register. The value of PORTx should
be 0x00 to enable the pull-up resistor of every port in that array. This is because the
resistor is enabled if no value is given. To disable it, PORTx should have the value 0xFF.
4.2.2.1 PORT A
PORTA.2
RESET:
dW: debug Wire On-chip Debug System
PORTA.1
PORTA.0
4.2.2.2 PORTB
PORTB.7
PORTB.6
PORTB.5
PORTB.4
PORTB.3
PORTB.2
PORTB.1
PORTB.0
4.2.2.3 PORTD
PORTD.6
PORTD.5
PORTD.4
PORTD.3
PORTD.2
PORTD.1
PORTD.0
There is a connection for programming on the EXB2313 testing board. The picture
above shows the connection between the cable and the microcontroller. The cable is
connected with a parallel plug onto the computer and with a RJ45 jack on the testing
board. Pin 2 is used as the RESET for the microcontroller. When a program is loaded in
the microcontroller, the registers have to be set to their initial values. This happens
when a reset occurs. Pin 4, 5 and 6 are the programming pins.
4.4 Interrupts
The use of an interrupt is to stop the normal procedure of a program and start another
procedure. There are 2 kinds of interrupts. Namely external and internal interrupt. The
internal interrupt are timers/counter and to store data. The external interrupt are
changes on one of the port. In this case, I use an interrupt to stop the program from
running and then read the signal on the serial receive port. The advantage of interrupt
is that the program does not have to listen to the port all the time. In the mean time, it
can run a normal procedure to by example edit the data. A problem that can occur is
that an interrupt gets interrupted. Therefore a General Interrupt Enable bit (GIE) can
block all further interrupt while the interrupt is running. This kind of interrupt is called a
signal.
4.5 USART
The USART is build up by three main parts. The first part is the clock generator. It
consists of a Synchronization Logic and a Baud Rate Generator. This pin is only used for
synchronous data transfer. With an asynchronous transfer, an internal clock is used.
This clock has a preset Baud Rate and Frame Size.
The second part is the Transmitter (TxD). It consists of a Write Buffer, a Shift Register,
Parity Generator and a Control Logic. The data byte that has to be sent is loaded in the
Write Buffer. When the Complete byte is in the buffer, it will be shifted to the
connection line. The shifting is done by the Shifting Register. When all the data is send,
the Parity Generator sends the parity bit. The receiver can test the data with the parity
bit.
The third part is the Receiver (RxD). It consists of a recovery unit for the clock and for
the data, a Parity Checker, Control Logic, a Shift Register and a Receiver Buffer (UDR).
When a start bit is received, the USART will send an interrupt. It read the data bit by
bit and sends them to the Receive Buffer. To receive a byte, the data has to be shifted
in the Shifting Register. The data is then checked in the Parity Checker who will
generate its own parity bit and compare it with the received one.
The settings for the USART are saved in the UCSRA and UCSRB register. This registers
consists of flag bits to communicate properly. They indicate if the Transmit and Receive
buffer are full, errors, interrupts, size of the frame, etc
//*****************************************************************//
// TRANSMIT //
//*****************************************************************//
For transmitting a frame, the UDRE is important. This flag bit indicates if the transmit
buffer is ready to receive new data.
//*****************************************************************//
// RECEIVE //
//*****************************************************************//
SIGNAL ( SIG_USART0_RX )
{
IncomingData = UDR; // Store received byte
PORTB = IncomingData; // This shows the data with LEDS on PORTB
}
//******************************************************************//
USI is also a way for serial communication. The USI is the Universal Serial Interface.
There are two possibilities for communication. It is also called SPI. In two-wire
communication only a transmitter and receiver are available. A clock frequency can be
send along in three-wire communication. The incoming and outgoing data is saved in
the 8-bit Shift Register (USIDR). This is for both the receiver and transmitter the same
register. To set the register for input or output, the D-Latch makes the connection with
the right pin. The data has to be written to a memory place immediately after
receiving. There is no buffer available to store the data.
1. Carrier detect
2. Rx ( Receive)
3. Tx (Transmit)
4. Data Terminal Ready
5. Ground
6. Data Set Ready
7. Request To Send
8. Clear To Send
9. Ring Indicator
For the transmission, the GPS sends its data to the microcontroller. This transmission
needs 2 connections. The first connection is from the Tx of the GPS to the Rx of the
microcontroller. The second connects the 2 ground with each other. The
microcontroller handles the data so that the GSM can send an SMS. To do this, there
are also 2 connections needed. The first from the Tx of the microcontroller to the Rx of
the GSM. The second also connects the ground with each other.
6 CODEVISION AVR
The disadvantages are that the program is not free. For my project, I could only use an
evaluation version. In this version are not all the features enabled. By example the
USART is locked.
6.2 Programming
Codevision AVR is specially designed for the Atmel AVR microcontrollers. The program
has a programmer and compiler on board. An Evaluation version can be downloaded at
http://www.hpinfotech.ro/html/download.htm
Codevision AVR
Some hardware functions are code generator by a wizard. To make a program, select
create new project. The Wizard is very useful if you are not used to program a lot. The
first thing to do is selecting the chip, which is a ATtiny2313. Then the ports can be set
to input or output. To work with USART, pin PD0 has to be input with a pull-up
transistor and pin PD1 has to be output with 0. These are the pins used for the USART
signal.
Project - Configure
When the code is written, it can be programmed into the microcontroller. To do this,
first the code has to be compiled. The compiler is the make option in the Project menu.
If the code is compiled correctly, the Program button is shown on the bottom of the
window.
Project - Make
7 WINAVR
The disadvantages are that it is very hard to learn this program. A makefile needs to be
made to compile code. The program doesn’t compile the code. Another program needs
to be use to compile and upload the code to the microcontroller.
Layout of WinAVR
WinAVR is a set of tools for microcontrollers. The tool for programming the
microcontroller is Programmers Notepad 2. This is an open source text editor with extra
features for coding. It supports several languages. For this project I chose for c-
language because all of the experience I had with microcontrollers was in c. A project
exists of a c-file and a makefile. Both are saved in the same directory. The c-file
contains the code for the program. A makefile tells the compiler what commands he
has to run and what files to compile. There is a makefile included in WinAVR. By default
installation it can be found in c:\winavr\sample. For this project, some data has to be
MCU = attiny2313
TARGET = project_GPS
SRC = $(TARGET).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
When a file is compiled, a .hex-file and a .cof-file are created. The .hex-file is the file
that will be uploaded in the FLASH memory of the microcontroller of the
microcontroller.
8.1 Flowchart
The flowchart shows how the program must run to complete his task. The
microcontroller reads the data from the GPS, filters the data and transmits the good
data to the GSM. The actions of the microcontroller are explained in the next
flowcharts. When the microcontroller receives the data, it is filtered immediately for the
right ID sentence. For this data, we use the GPRMC data. Because the first two signals
are always the same, it is possible to filter the data on the three signals that follow the
GP. If the data is correct, the reading can begin. Because the data is separated by
commas, it is only possible to count the commas to determine the data we need. This
data is stored in the memory of the microcontroller. To send the data with the cell
phone, the AT+CMGS= command is put in from together with the phone number of the
receiver. A counter is put on the transmitter, so it won’t send every time it receives the
GPS data. The different stages are explained in the following flowcharts.
PORTD has to be set to use the USART in the program. This USART will generate an
interrupt when data is inserted. When there is an interrupt, the data needs to be
checked for the GPRMC sentenceID. If the RMC is matched, the microcontroller can
start reading data.
If the data is checked, the microcontroller will read the data from the GPS. The right
data starts on the third place in the sentenceID and is separated by “,”. When the
counter that counts the commas reaches seven, it can send the data.
Counter to send = 10
No
Yes
Send AT+CMGS=”(phone
number)”
Send message
Counter = 0
Increment Counter
Sending data with a microcontroller is also done with the USART. In my project, I use a
counter. Because of this counter the data is not send every time a location is known. To
send a message with a GSM, it first need the data “AT+CMGS=”(phone number)”. Then
the message can be send with at the end char(26) which is CTRL – Z.
All the libraries that are needed to create a program are included on the top of the
code. The variables that not change during the program can be created here too. In the
middle of the program, the different functions are created. The program always starts
at the line int main( ). From this class other classes can be called. These are by
example Transmit and Receive functions.
#include <avr/io.h>
#include <stdio.h>
#include <inttypes.h>
#include <avr/signal.h> //include file for signal interrupts
#include <avr/interrupt.h> //include files for interrupts
#define DEF_UART 0 //value for UBRR
#define BAUD 51 //the baud is the speed at which the microcontroller
should check the USART port. 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. (4000000/(16*4800))-1 = 51,0833
#define COMMA3 3
#define COMMA4 4
#define COMMA5 5
#define COMMA6 6
#define CR 0x0D //CR and LF are use to send ENTER
#define LF 0x0A
#define CTRLZ 0x1A //The hexadecimal value of CTRL-Z is 0x1A
#define SMSCOMMAND 20
//*************************************************//
// TRANSMIT //
//*************************************************//
//*************************************************//
// MAIN PROGRAM //
//*************************************************//
int main ( )
{
//SET USART
UBRRH = DEF_UART; // 4800 bps at 4 MHz
UBRRL = BAUD;
UCSRB = _BV(RXEN) | _BV(TXEN) | _BV(RXCIE); // Rx Complete Interrupt &
Enable Rx/Tx
UCSRC = _BV(UCSZ1) | _BV(UCSZ0); // 8N1
//SET PORTS: PORTB is not needed, but is used to send to the LEDs
//PORTD uses 2 bits. PD0 for RXD and PD1 for TXD
//*****************************//
//reserve and set variables//
//*****************************//
/*
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, Latitude, 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
*/
/*
maximum 9 characters are possible for writing the data to latitude and longitude
because the last character of an array is a Carriage Return
*/
/*set variables of the array command. This array consists of the command to send an
SMS. This is AT+CMGS=“<phone number>”
*/
command[0] = 'A';
command[1] = 'T';
command[2] = '+';
command[3] = 'C';
command[4] = 'M';
command[5] = 'G';
command[6] = 'S';
command[7] = '=';
command[8] = '"';
command[9] = '0';
command[10] = '4';
command[11] = '4';
command[12] = '1';
command[13] = '2';
command[14] = '3';
command[15] = '4';
command[16] = '5';
command[17] = '6';
command[18] = '7';
command[19] = '"';
/*
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 == 1 )
{
if( check == 1 )
{
if( Read == 2 )
{
if( IncomingData == 'C' ) // check if char is C
{
Read = 3;
LenLon = 0;
LenLat = 0;
n = 0;
}
if( IncomingData != 'C' )
{
Read = 0;
}
check = 0;
}
}
//*************************************//
// 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, lattide, N-S, E-W,...
the fist sign is a comma
*/
n = n + 1;
}
if( n == COMMA4 )
{
DirNS = IncomingData;
}
if( n == COMMA5 )
{
Longitude[LenLon] = IncomingData;
LenLon = LenLon + 1;
}
if( n == COMMA6 )
{
DirEW = IncomingData;
Read = 0;
Write = 1;
counter = counter + 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 )
{
/*
To initiate the SMS service. Using a array gives an error on the last char of that array.
The service command is AT+CMGS= " (phone number) " <ENTER> message
<CTRL><Z>. AT+CMGS is written in the array command[]. On the GSM, the message
will be like this: <Latitude N or S , Longitude E or W> and the message will be send
after CTRL-Z
*/
USART_Transmit( CR ); //CR
USART_Transmit( LF ); //LF
for( int v = 0 ; v <= LenLat-1 ; v++ )
{
USART_Transmit( Latitude[v] );
}
USART_Transmit( DirNS );
USART_Transmit( ',' );
USART_Transmit( DirEW );
USART_Transmit( CTRLZ );
counter = 0;
}
return 1;
} //END MAIN
//*************************************************//
// RECEIVE //
//*************************************************//
SIGNAL ( SIG_USART0_RX )
{
IncomingData = UDR; //Store received byte
check = 1;
PORTB = IncomingData; //Show byte on PORTB. This is only to check if
//data is received and transmitted
}
CONCLUSION
During my practical training, I learned to work with GPS, Atmel microcontrollers and
GSM. Not only the hardware is important but also software is important to make
application. Codevision AVR is easy to learn and can be a step to the more powerful
WinAVR.
For the GPS it was important to connect it and have insight in the data that is
transmitted over the serial line. This data is build by the NMEA-0183 standard. This
standard is the same for every receiver and therefore easy to use.
In the beginning, my biggest concern was to use the GSM-module. After reading the
datasheet and testing some examples, the use was not so hard. It is also connected
with a serial cable and uses simple commands. Special combinations of letters can be
found in ASCII tables. By example <CTRL> + Z is char 26.
The choice of the program is very important for an application. WinAVR is a powerful
program that can be used as a notepad. Is contains an identifier for several
programming languages like Java, C, etc.
These years, GPS is used in many applications. In the future, the use of GPS will rise
rapidly. But GPS is still a military project. The European Galileo project is being made to
break the American monopoly in this field. This commercial product has much support
from other countries and will probably compete with GPS in the following years.
Advantages as higher accuracy and service integrity are used to convince companies
and people.
9 APPENDIX
9.1.1 $GPRMB
7 = N or S
9 = E or W
14 = Checksum
9.1.2 $GPRMC
3 = Latitude of fix
4 = N or S
5 = Longitude of fix
6 = E or W
9 = UT date
11 = E or W
12 = Checksum
9.1.3 $GPGGA
1 = UTC of Position
2 = Latitude
3 = N or S
4 = Longitude
5 = E or W
15 = Checksum
9.1.4 $GPVTG
2 = Fixed text 'T' indicates that track made good is relative to true north
3 = not used
4 = not used
9 = Checksum
9.1.5 $GPRMA
1 = Data status
2 = Latitude
3 = N/S
4 = longitude
5 = W/E
6 = not used
7 = not used
10 = Variation
12 = Checksum
9.1.6 $GPGSA
GSA = GPS receiver operating mode, SVs used for navigation, and DOP values.
1 = Mode:
A=Automatic, 3D/2D
2 = Mode:
2=2D
3=3D
3-14 = IDs of SVs used in position fix (null for unused fields)
15 = PDOP
16 = HDOP
17 = VDOP
9.1.7 $GPGSV
GSV = Number of SVs in view, PRN numbers, elevation, azimuth & SNR values.
2 = Message number
4 = SV PRN number
#----------------------------------------------------------------------------
# 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!
#
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
ASRC =
# 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
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB =
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
# If this is left blank, then it will use the Standard scanf version.
SCANF_LIB =
#SCANF_LIB = $(SCANF_LIB_MIN)
#SCANF_LIB = $(SCANF_LIB_FLOAT)
MATH_LIB = -lm
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
# just set to localhost unless doing some sort of crazy debugging when
DEBUG_HOST = localhost
#=====================================================
# Define programs and commands.
SHELL = sh
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
# Default target.
all: begin gccversion sizebefore build sizeafter end
build: elf hex eep lss sym
elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
end:
@echo $(MSG_END)
@echo
sizebefore:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE);
$(ELFSIZE); \
$(AVRMEM) 2>/dev/null; echo; fi
sizeafter:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER);
$(ELFSIZE); \
$(AVRMEM) 2>/dev/null; echo; fi
ifeq ($(DEBUG_BACKEND),simulavr)
@echo load >> $(GDBINIT_FILE)
endif
@echo break main >> $(GDBINIT_FILE)
Else
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
$(DEBUG_MFREQ) --port $(DEBUG_PORT)
endif
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVE) .dep/*
#include <avr/io.h>
#include <stdio.h>
#include <inttypes.h>
#include <avr/signal.h> //include file for signal interrupts
#include <avr/interrupt.h> //include files for interrupts
#define DEF_UART 0 //value for UBRR
#define BAUD 51 //the baud is the speed at which the microcontroller
should check the USART port. 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. (4000000/(16*4800))-1 = 51,0833
#define COMMA3 3
#define COMMA4 4
#define COMMA5 5
#define COMMA6 6
#define CR 0x0D //CR and LF are use to send ENTER
#define LF 0x0A
#define CTRLZ 0x1A //The hexadecimal value of CTRL-Z is 0x1A
#define SMSCOMMAND 20
//*************************************************//
// TRANSMIT //
//*************************************************//
//*************************************************//
// MAIN PROGRAM //
//*************************************************//
int main ( )
{
//SET USART
UBRRH = DEF_UART; // 4800 bps at 4 MHz
UBRRL = BAUD;
UCSRB = _BV(RXEN) | _BV(TXEN) | _BV(RXCIE); // Rx Complete Interrupt &
Enable Rx/Tx
UCSRC = _BV(UCSZ1) | _BV(UCSZ0); // 8N1
//SET PORTS: PORTB is not needed, but is used to send to the LEDs
//PORTD uses 2 bits. PD0 for RXD and PD1 for TXD
//*****************************//
//reserve and set variables//
//*****************************//
/*
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, Latitude, 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
*/
/*
maximum 9 characters are possible for writing the data to latitude and longitude
because the last character of an array is a Carriage Return
*/
counter = 0;
/*set variables of the array command. This array consists of the command to send an
SMS. This is AT+CMGS=“<phone number>”
*/
command[0] = 'A';
command[1] = 'T';
command[2] = '+';
command[3] = 'C';
command[4] = 'M';
command[5] = 'G';
command[6] = 'S';
command[7] = '=';
command[8] = '"';
command[9] = '0';
command[10] = '4';
command[11] = '4';
command[12] = '1';
command[13] = '2';
command[14] = '3';
command[15] = '4';
command[16] = '5';
command[17] = '6';
command[18] = '7';
command[19] = '"';
/*
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 == 1 )
{
if( check == 1 )
{
if( Read == 2 )
{
if( IncomingData == 'C' ) // check if char is C
{
Read = 3;
LenLon = 0;
LenLat = 0;
n = 0;
}
if( IncomingData != 'C' )
{
Read = 0;
}
check = 0;
}
}
//*************************************//
// 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, lattide, N-S, E-W,...
the fist sign is a comma
*/
n = n + 1;
}
if( n == COMMA4 )
{
DirNS = IncomingData;
}
if( n == COMMA5 )
{
Longitude[LenLon] = IncomingData;
LenLon = LenLon + 1;
}
if( n == COMMA6 )
{
DirEW = IncomingData;
Read = 0;
Write = 1;
counter = counter + 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 )
{
/*
To initiate the SMS service. Using a array gives an error on the last char of that array.
The service command is AT+CMGS= " (phone number) " <ENTER> message
<CTRL><Z>. AT+CMGS is written in the array command[]. On the GSM, the message
will be like this: <Latitude N or S , Longitude E or W> and the message will be send
after CTRL-Z
*/
USART_Transmit( CR ); //CR
USART_Transmit( LF ); //LF
for( int v = 0 ; v <= LenLat-1 ; v++ )
{
USART_Transmit( Latitude[v] );
}
USART_Transmit( DirNS );
USART_Transmit( ',' );
USART_Transmit( DirEW );
USART_Transmit( CTRLZ );
counter = 0;
}
return 1;
} //END MAIN
//*************************************************//
// RECEIVE //
//*************************************************//
SIGNAL ( SIG_USART0_RX )
{
IncomingData = UDR; //Store received byte
check = 1;
PORTB = IncomingData; //Show byte on PORTB. This is only to check if
//data is received and transmitted
}
SOURCES
Books
Richard H. Barnett, Sarah Cox, Larry O’Cull (2002). Embedded C Programming and the
Atmel AVR. Florence: Thomson Delmar Learning
Internet