Sei sulla pagina 1di 98

SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

ABSTRACT

Wireless sensor networks are one of the highly emerging areas and found really useful in
environmental studies and military applications. In sensor networks a set of nodes randomly
deployed communicate through wireless links and provide the information as on when required.
Since these nodes run with little power mostly running with batteries the hardware and software
must be designed appropriately.

This gives importance for less weight and secure encryption and decryption algorithms
especially for defense applications. The Tiny Encryption Algorithm (TEA) is becoming very useful
in this context. TEA is a preferred choice due to its low memory and less hardware requirements in
these applications. It was designed by David Wheeler and Roger Needham of the Cambridge
Computer Laboratory, and first presented at the Fast Software Encryption workshop in 1994.

TEA is a 64-bit block network with a 128-bit key and a suggested 64 rounds. In this project
TEA is implemented for 434 MHz Amplitude shift keying based wireless link. The wireless link
will be designed and will be implemented with TLP434A transmitter and RLP434A receiver
circuit. Two Philips 89C51 microcontrollers (8051 architecture) will be used for interfacing with
the transmitter and receiver chips at the two ends of communication. The TEA encryption
algorithm will be developed on transmitter and decryption algorithm will be developed on receiver
side.

The proposed work involves study of TEA, C program implementation of algorithm,


hardware design for microcontroller and RF units. The end to end single ended wireless
communication link will be demonstrated with some sensors data and LCD interface in range of 5
meters. The Embedded development studio (EDS) software will be used for the building the
application.

B.V.R.I.T. Page 1
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

INDEX

Introduction 9

1. Introduction
10
1.1 Context of the project 10
1.2 Block diagram 11
1.3 Project Study 11
1.4 Basic principle 12
2. Tools and hardware 12
3. Motivation 12
4. State of the Art 13
Chapter 1: Encryption 14

1.1 Introduction to Encryption 15


1.2 Importance of Encryption 15
1.3 Existing systems for the project 16
1.4 Proposed architecture 17
1.5 PSoC microcontroller Introduction 17
1.5.1 PSoC architecture 18
1.5.2 Characteristics of PSoC microcontrollers 19
1.5.3 Selection of PSoC for this project 20
Chapter 2: PSoC Microcontroller 22

2.1 About Microcontroller 23


2.2 Introduction to PSoC Microcontroller 25
2.2.1 Introduction 25
2.2.2 PSoC 26
2.2.3 System overview 26
2.2.4 Frequency generator 29
2.2.5 Microcontroller power consumption 30

B.V.R.I.T. Page 2
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

2.3 Digital Inputs and Outputs 31


2.4 Analog inputs and outputs 33
2.5 Accessing programmable digital blocks 33
2.6 Digital programmable blocks 34
2.7 Analog programmable blocks 35
2.8 PSoC Designer 38
2.8.1 Introduction 38
2.8.2 Programmable Component Selection 38
2.8.3 Interconnection View 39
2.8.4 Global Parameters 40
2.8.5 Digital Components Interconnection 41
2.8.6 Analog Components Interconnection 41
2.8.7 Application Editor 42
2.8.8 Analog Component Interconnect 42
2.8.9 Application Editor 43

Chapter 3: PSoC User Modules 44

3.1 User Modules Introduction 45


3.2 LCD User Module 46
3.3 TX8 User Module 49
3.4 RX8 User Module 52
3.5 One Wire Software User Module 54

Chapter 4: Sensors 57

4.1 Sensors 58
4.1.1 Types 58
4.1.2 Classification of measurement errors 59
4.1.3 Resolution 59
4.2 Temperature Sensor 60
4.2.1 Features 60

B.V.R.I.T. Page 3
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

4.2.2 Description 60
4.2.3 Overview 61
4.2.4 Operation-Measuring Temperature 63
4.2.5 Operation Alarm Signaling 64
4.2.6 Memory 65
4.2.7 CRC Generation 66
4.2.8 1-Wire Bus System 67
4.2.9 Transaction Sequence 67
4.2.10 1-Wire Signaling 68
Chapter 5: Transceiver 69
5.1 General Description 70
5.1.1 Features 70
5.1.2 Applications 70
5.1.3 Mechanical Appearance 71
5.1.4 Pin Definition 71
5.2 Module Application 72

Chapter 6: Tiny Encryption Algorithm (TEA) 74


6.1 Introduction 75
6.1.1 Basics of the Routine 75
6.1.2 Usage 76
6.1.3 Selection of Algorithm 76
6.1.4 Analysis 76
6.1.5 Preliminaries 77
6.2 The Key Schedule 78
6.2.1 Technique Developed by Inventors 78
6.3 Encryption Routine 79
6.4 Decryption Routine 80

B.V.R.I.T. Page 4
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Chapter 7: Implementation 82
7.1 Data Transmission 83
7.1.1 Program for Data Transmission 83
7.2 Data Reception 89
7.2.1 Program for Data Reception 89
Chapter 8: Results and Conclusion 94
8.1 Results 95
8.2 Applications 98
8.3 Advantages 98
8.4 Disadvantages 99
8.5 Conclusion 99
8.6 Contributions of the Project 99
8.7 Future Work 99

References: 101

Appendix: 102
A. Interfacing TX8 with PSoC Micro Controller 103
B.Interfacing RX8 with PSoC Micro Controller 104
C. Interfacing Temperature Sensor with PSoC Micro Controller 105

B.V.R.I.T. Page 5
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

List of Figures

Figure 1: Block Diagram of Secured Wireless Communication Link 11

Figure 1.1: Block Diagram of Existing Model using 89C51 Micro Controller 16

Figure 1.2: PSoC Model 20

Figure 1.3: PSoC Architecture 21

Figure 2.1: The Microcontroller 25

Figure 2.2: The PSoC Microcontroller 27

Figure 2.3: CPU Overview 28

Figure 2.4: The Microcontroller-Freq Generator 29

Figure 2.5: Port Operation 31

Figure 2.6: Analog IO 33

Figure 2.7: Digital block 34

Figure 2.8: Digital Programming 35

Figure 2.9: Analog programming 36

Figure 2.10: Interrupt sequence 37

Figure 2.11: Device editor 39

Figure 2.12: Interconnect view 40

Figure 3.1: LCD to PSoC Block Diagram 46

Figure 3.2: TX8 Block Diagram 50

Figure 3.3: RX8 Block Diagram 52

B.V.R.I.T. Page 6
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

List of Figures

Figure 3.4: PSoC to Wire schematic 55

Figure 4.1: Pin configuration 61

Figure 4.2: DS18S20 Block Diagram 62

Figure 4.3: DS18S20 Memory Map 66

Figure 4.4: CRC Generator 67

Figure 5.1: Mechanical Appearance 71

Figure 5.2: Communication Diagram 72

Figure 5.3: Configure mode connections 73

Figure 8.1: Welcome note on LCD at Transmitter 95

Figure 8.2: Welcome note on LCD at Receiver 95

Figure 8.3: Encryption Process 96

Figure 8.4: Decryption Process 97

Figure 8.5: Decrypted Data at the Receiver side 97

B.V.R.I.T. Page 7
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

List of Tables

Table 2.1: Pin work Models 32

Table 2.2: Blocks 35

Table 4.1: Pin Description for Temperature Sensor 61

Table 4.2: Temperature Register Format 63

Table 4.3: Temperature/Data Relationship 64

Table 4.4: TH and TL Register Format 64

Table 5.1: Pin Description for Transceiver 71

B.V.R.I.T. Page 8
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Introduction

1. Introduction
1.1 Context of the project
1.2 Block diagram
1.3 Project Study
1.4 Basic principle
2. Tools and hardware
3. Motivation
4. State of the Art

B.V.R.I.T. Page 9
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

1. Introduction:

Many symmetric block ciphers have been presented in recent years. The Tiny Encryption
Algorithm (TEA) (Wheeler et al., 1994) is a compromise for safety, ease of implementation, lack
of specialized tables, and reasonable performance. TEA can replace 1 DES in software, and is short
enough to integrate into almost any program on any computer. Some attempts have been made to
find weakness of the Tiny Encryption Algorithm. The motivation of this project is to study and
implement the proposed algorithm.

1.1. Context of the project:

Monitoring of the Critical sensor monitoring is very important in several industries


(Nuclear plants, power plants, petroleum and gas) . This job should be done with at most accuracy
and reliably. The sensor information should be available at various locations simultaneously to take
accurate decisions. This kind of requirement can be met by using the central servers and
connecting the sensor networks through the controllers to the central servers.

When the physical quantities like temperature, humidity, pressure etc.. are sensed by the
sensors, this data should be transmitted to the other side wirelessly. Here, we encounter with the
problems like security issues.

So, to over these issues the data should be encrypted to provide security for secret data.

Here, in this project we implement Tiny Encryption Algorithm (TEA) at the either nodes.

B.V.R.I.T. Page 10
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

1.2. Block Diagram:

PSoC PC

Microcontroller

B.V.R.I.T. Page 11
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

UART

Figure1. Block Diagram of Secured Wireless Communication Link

1.3. Project Study:

The Tiny Encryption Algorithm (TEA) is a cryptographic algorithm designed by Wheeler


and Needham (1994). It is designed to minimize memory footprint and maximize speed. This
project presents the cryptanalysis of the Tiny Encryption Algorithm

1.4. Basic Principle:

Micro controller is interfaced with sensors. PSoC controller is programmed with the Tiny
Encryption Algorithm. The sensor information processed by the controller can be rooted to the
other nodes by power on controller sends the data to the other nodes.The encrypted data as well as
the actual data can be displayed on LCD simultaneously.

B.V.R.I.T. Page 12
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

2. Tools and Hardware:

The following are the software tools used in the project. PSoC Designer suite, from
Cypress Semiconductors, for building and configuring the required blocks and to develop the code.
PSoC programmer, to dump the code on the Microcontroller.

The following are the hardware modules used in the project development.

PSoC microcontroller,
Temperature sensors,

Transceivers,

LCDs.

3. Motivation:

As computer systems become more pervasive and complex, security is increasingly


important. Cryptographic algorithms and protocols constitute the central component of
systems that protect network transmissions and store data. The security of such systems
greatly depends on the methods used to manage, establish, and distribute the keys
employed by the cryptographic techniques. Even if a cryptographic algorithm is ideal in
both theory and implementation, the strength of the algorithm will be rendered useless if
the relevant keys are poorly managed.

4. State of the art:

Cryptography is the art and science behind the principles, means, and methods for keeping
messages secure. Cryptanalysis is a study of how to compromise (defeat) cryptographic
mechanism. There are two classes of key-based encryption algorithms: symmetric (or

B.V.R.I.T. Page 13
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

secret-key) and asymmetric (or public-key) algorithms. Symmetric algorithms use the same
key for encryption and decryption, whereas asymmetric algorithms use different keys for
encryption and decryption. Ideally it is infeasible to compute the decryption key from the
encryption key.
Symmetric algorithms can be divided into stream ciphers and block ciphers. Stream ciphers
encrypt a single bit of plain text at a time, whereas block ciphers take a number of bits (say
64 bits), and encrypt them as a single unit. Symmetric encryption is the backbone of many
secure communication systems. Dozens of symmetric algorithms have been invented and
implemented, both in hardware and software.

B.V.R.I.T. Page 14
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

CHAPTER 1

Encryption

1.1 Introduction to Encryption


1.2 Importance of Encryption
1.3 Existing systems for the project
1.4 Proposed architecture
1.5 PSoC microcontroller Introduction
1.5.1 PSoC architecture
1.5.2 Characteristics of PSoC microcontrollers
1.5.3 Selection of PSoC for this project

1.1. Introduction to Encryption:

B.V.R.I.T. Page 15
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Encryption is the conversion of data into a form, called a cipher text that cannot be easily
understood by unauthorized people. Decryption is the process of converting encrypted data back
into its original form, so it can be understood.

The use of encryption/decryption is as old as the art of communication. In wartime,


a cipher, often incorrectly called a code, can be employed to keep the enemy from obtaining the
contents of transmissions. (Technically, a code is a means of representing a signal without the
intent of keeping it secret; examples are Morse code and ASCII.) Simple ciphers include the
substitution of letters for numbers, the rotation of letters in the alphabet, and the "scrambling" of
voice signals by inverting the sideband frequencies. More complex ciphers work according to
sophisticated computer algorithms that rearrange the data bits in digital signals.

In order to easily recover the contents of an encrypted signal, the correct decryption key is
required. The key is an algorithm that undoes the work of the encryption algorithm. Alternatively, a
computer can be used in an attempt to break the cipher. The more complex the encryption
algorithm, the more difficult it becomes to eavesdrop on the communications without access to the
key.

1.2. Importance of Encryption:

Encryption/decryption is especially important in wireless communications. This is because


wireless circuits are easier to tap than their hard-wired counterparts. Nevertheless,
encryption/decryption is a good idea when carrying out any kind of sensitive transaction, such as a
credit-card purchase online, or the discussion of a company secret between different departments
in the organization. The stronger the cipher -- that is, the harder it is for unauthorized people to
break it -- the better, in general. However, as the strength of encryption/decryption increases, so
does the cost.

In recent years, a controversy has arisen over so-called strong encryption. This refers to
ciphers that are essentially unbreakable without the decryption keys. While most companies and
their customers view it as a means of keeping secrets and minimizing fraud, some governments
view strong encryption as a potential vehicle by which terrorists might evade authorities. These

B.V.R.I.T. Page 16
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

governments, including that of the United States, want to set up a key-escrow arrangement. This
means everyone who uses a cipher would be required to provide the government with a copy of the
key. Decryption keys would be stored in a supposedly secure place, used only by authorities, and
used only if backed up by a court order. Opponents of this scheme argue that criminals could hack
into the key-escrow database and illegally obtain, steal, or alter the keys. Supporters claim that
while this is a possibility, implementing the key escrow scheme would be better than doing nothing
to prevent criminals from freely using encryption/decryption.

1.3. Existing Systems for the Project:

In the earlier days, the wireless communication link was developed using 89C51 Micro
Controller. But, this micro controller needed extra peripherals like ADCs, filters, amplifiers etc..
More over, it is not programmable and it occupies very large space. The other reason for not going
for microcontroller is that the code for implementation is very large. So, it is very complex and
cant be understood easily.

1.4. Proposed Architecture:

Here, we are introducing PSoC Micro Controller which has programmable analog and
digital blocks and it needs minimal code for implementation. In sensor networks a set of nodes
randomly deployed communicate through wireless links and provide the information as on when
required. Since these nodes run with little power (mostly running with batteries), the hardware and
software must be designed appropriately.

This gives importance for less weight and secure encryption and decryption algorithms
especially for defense applications. The Tiny Encryption Algorithm (TEA) is becoming very useful
in this context. TEA is a preferred choice due to its low memory and less hardware requirements in
these applications. It was designed by David Wheeler and Roger Needham of the Cambridge
Computer Laboratory, and first presented at the Fast Software Encryption workshop in 1994.

B.V.R.I.T. Page 17
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

The proposed work involves study of TEA, C program implementation of algorithm,


hardware design for microcontroller and RF units. The end to end single ended wireless
communication link will be demonstrated with some sensors data and LCD interface in range of 5
meters. The Embedded development studio (EDS) software will be used for the building the
application.

1.5. PSoC Micro Controller Introduction:

When developing more complex projects, there is often a need for additional peripheral
units, such as operational and instrument amplifiers, filters, timers, digital logic circuits, AD and
DA converters, etc. As a general rule, implementation of the extra peripherals brings in additional
difficulties: new components take space, require additional attention during production of a printed
circuit board, and increase power consumption. All of these factors can significantly affect the
price and development cycle of the project.

The introduction of PSoC microcontrollers has made many engineers dream come true of
having all their project needs covered in one chip.

1.5.1 PSoC architecture:

Programmable System on Chip PSoC (Programmable System on Chip) represents a whole


new concept in microcontroller development. In addition to all the standard elements of 8-bit
microcontrollers, PSoC chips feature digital and analog programmable blocks, which themselves
allow implementation of large number of peripherals. Digital blocks consist of smaller
programmable blocks that can be configured to allow different development options. Analog
blocks are used for development of analog elements, such as analog filters, comparators,
instrumentation noninverting amplifiers, as well as AD and DA converters. There is a number of
different PSoC families you can base your project upon, depending on the project requirements.
Basic difference between PSoC families is the number of available programmable blocks and the
number of input/output pins. Number of components that can be devised is primarily a function of
the available programmable blocks. Depending on the microcontroller family, PSoC chips have 4
16 digital blocks, and 312 analog programmable blocks.

B.V.R.I.T. Page 18
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

1.5.2 Characteristics of PSoC microcontrollers:

Some of the most prominent features of PSoC microcontrollers are:

MAC unit, hardware 8x8 multiplication, with result stored in 32-bit accumulator,
Changeable working voltage, 3.3V or 5V,

Possibility of small voltage supply, to 1V,

Programmable frequency choice.

Programmable blocks allow you to devise:

16K bytes of programmable memory,


256 bytes of RAM,

AD converters with maximum resolution of 14 bits,

DA converters with maximum resolution of 9 bits,

Programmable voltage amplifier,

Programmable filters and comparators,

Timers and counters of 8, 16, and 32 bits,

Pseudorandom sequences and CRC code generators,

Two Full-Duplex UARTs,

Multiple SPI devices,

Option for connection on all output pins,

B.V.R.I.T. Page 19
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Option for block combining,

Option for programming only the specified memory regions and write protection,

For every pin there is an option of Pull up, Pull down, High Z, Strong, or Open pin state,

Possibility of interrupt generation during change of state on any input/output pin,

I2C Slave or Master and Multi-Master up to speed of 400KHz,

Integrated Supervisory Circuit,

Built-in precise voltage reference.

Figure 1.2: PSoC Model

B.V.R.I.T. Page 20
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Figure1.3. PSoC Architecture

1.5.3 Selection of PSoC for this Project:

Perhaps the best way to recognize the true value of PSoC microcontrollers is through
comparison with other options.

Major advantages of PSoC microcontroller include the following:

There is no other microcontroller that has programmable voltage, instrumentational,


inverting, and non-inverting amplifiers;
Hardware generators of pseudorandom and CRC code, as well as analog modulators, are
unique to PSoC families;

B.V.R.I.T. Page 21
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

MAC (Multiply-accumulate) is an essential part of digital signal processors, which allows


implementation of digital signal processing algorithms. Its worth noting that hardware
accumulator multiplication is not a common feature of 8-bit microcontrollers;

Having the advantage of changeable working voltage doesnt really need a comment. This
feature is particularly important for development of new devices as it eliminates the need
for redesigning the PCB and implementing the level translator;

Option for low voltage supply (~1V) is a tremendous advantage in battery operated
systems;

Timers, counters, and PWM units are more flexible than the usual implementation;

Automatic code writing for accessing all the peripherals in use;

In case you need a larger array of components, there is an option for dynamic
reconfiguration, allowing you to change peripherals during run-time. In this way, its
possible to minimize the processor workload at an time, leaving the largest part of the job
to the specialized hardware.

On the other hand, there are certain limitations of PSoC that could influence the choice of
microcontroller for the design.

In systems which require highly precise or fast measurement, problems may occur
with analog device characteristics. In this case, you should analyze if speed of AD
converters and offset/noise of analog amplifiers are able to satisfy the project
demands.
Analog components do not have the ability to work with usual negative supply
voltage. For example, zero voltage for inverting amplifiers is taken to be the analog
ground AGND (usually 2.5V). All voltages above AGND are taken as positive,
while voltages below AGND are taken as negative.

B.V.R.I.T. Page 22
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Most PSoC microcontrollers have 256 bytes of RAM, which could prove to be
insufficient for some projects.

CHAPTER 2

PSoC Microcontroller

2.1 About Microcontroller


2.2 Introduction to PSoC Microcontroller
2.2.1 Introduction
2.2.2 PSoC
2.2.3 System overview
2.2.4 Frequency generator
2.2.5 Microcontroller power consumption

B.V.R.I.T. Page 23
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

2.3 Digital Inputs and Outputs


2.4 Analog inputs and outputs
2.5 Accessing programmable digital blocks
2.6 Digital programmable blocks
2.7 Analog programmable blocks
2.8 PSoC Designer
2.8.1 Introduction
2.8.2 Programmable Component Selection
2.8.3 Interconnection View
2.8.4 Global Parameters
2.8.5 Digital Components Interconnection
2.8.6 Analog Components Interconnection
2.8.7 Application Editor
2.1 About Microcontroller:

This section provides an introduction to most common word in the embedded system
microcontroller. It is written to familiarize you with microcontroller terminology and basic
microcontroller architecture.

Its hard to imagine the present world of electronic tools and toys without the
microprocessor or Microcontroller. Yet this single chip wonder has barely reached thirtieth
birthday. In 1971 Intel corporation introduced the 8080, the first successful microprocessor.
Shortly thereafter, Motorola, RCA and then MOS technology and Zilog introduced similar devices:
the 6800, 1801, 6502 and Z80 respectively. Alone these integrated circuits (ICs) were rather
helpless (and they remain so); but as a part of a single board computer (SBC) they become the
central component in useful products for learning and designing with microprocessors. These
SBCs of which SDK-85 by Intel etc. Are the most memorable, quickly found their way into design
labs at colleges, universities and electronics companies.

A microcontroller is a single chip, self-contained computer which incorporates all the basic
components of a personal computer on a much smaller scale. Microcontrollers are often referred to
as single chip devices or single chip computers. The main consequence of the microcontrollers

B.V.R.I.T. Page 24
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

small size is that its resources are far more limited than those of a desktop personal computer. In
functional terms, a microcontroller is a programmable single chip which controls a process or
system.

Microcontrollers are typically used as embedded controllers where they control part of a
larger system such as an appliance, automobile, scientific instrument or a computer peripheral.
Microcontrollers are designed to be low cost solutions; therefore using them can drastically reduce
part and design costs for a project. Physically, a microcontroller is an integrated circuit with pins
along each side. The pins presented by a microcontroller are used for power, ground, oscillator, I/O
ports, interrupt request signals, reset and control. In contrast, the pins exposed by a microprocessor
are most often memory bus signals (rather than I/O ports).

Note: - A microcontroller is not the same as a microprocessor. A microprocessor is a single chip


CPU used within other computer systems. A microcontroller is itself a single chip computer
system.

Personal computers are used as development platforms for microcontroller projects.


Development computers, usually personal or workstation computers, use a microprocessor as their
principle computing engine. Microprocessors depend upon a variety of subsidiary chips and
devices to provide the resources not available on the microprocessor. Additional chips required
with microprocessor support memory storage, input/output control and specialized processing. A
development platform is required to run embedded system development software such as
assemblers, compilers, editors and simulators which require the processing power and memory
capabilities of a desktop personal computer or workstation.

The target platform is the platform on which the finished program will be run. For example,
consider a developer who is creating a program for a 8051 microcontroller. The developer writes,
edits, and tests the program on a Pentium personal computer the development platform. The
developer will use software which runs on a Pentium but whose target device is the 8051. When
the program is ready it is programmed in the target platform, the 8051.

A microcontroller has seven main components:

B.V.R.I.T. Page 25
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

i. Central processing unit (CPU)


ii. ROM
iii. RAM
iv. Input and Output
v. Timer
vi. Interrupt circuitry
vii. Buses

Figure 2.1: Internal Parts of a Microcontroller

Microcontrollers do not function in isolation. As their name suggests they are designed to
control other devices. The microcontroller can accept inputs from some devices and provide
outputs to other devices within any given system. For example, a microcontroller may accept input
from a switch and may send output to an LED. If the switch is pressed the microcontroller can be
instructed to illuminate the LED. The microcontroller is often part of a larger system. For example,
the switch and LED may be part of a compact disc player in a car stereo system. When a
microcontroller is part of a larger system it is often referred to as an embedded controller because
it is embedded within the larger system.

2.2 Introduction to PSoC Microcontroller:

B.V.R.I.T. Page 26
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

2.2.1 Introduction:

When developing more complex projects, there is often a need for additional
peripheral units, such as operational and instrument amplifiers, filters, timers, digital logic
circuits, AD and DA convertors, etc. As a general rule, implementation of the extra
peripherals brings in additional difficulties: new components take space, require additional
attention during production of a printed circuit board, and increase power consumption. All
of these factors can significantly affect the price and development cycle of the project.

The introduction of PSoC microcontrollers has made many engineers dream come
true of having all their project needs covered in one chip.

2.2.2 PSoC (Programmable System on Chip):

PSoC (Programmable System on Chip) represents a whole new concept in


microcontroller development. In addition to all the standard elements of 8-bit
microcontrollers, PSoC chips feature digital and analog programmable blocks, which
themselves allow implementation of large number of peripherals.

Digital blocks consist of smaller programmable blocks that can be configured to


allow different development options. Analog blocks are used for development of analog
elements, such as analog filters, comparators, instrumentational (non) inverting amplifiers,
as well as AD and DA convertors.

There are a number of different PSoC families you can base your project upon,
depending on the project requirements. Basic difference between PSoC families is the
number of available programmable blocks and the number of input/output pins.

Number of components that can be devised is primarily a function of the available


programmable blocks. Depending on the microcontroller family, PSoC chips have 416
digital blocks, and 312 analog programmable blocks.

B.V.R.I.T. Page 27
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

2.2.3 System overview:

PSoC microcontrollers are based on 8-bit CISC architecture. Their general structure
with basic blocks is presented in the following image:

Figure 2.2: Overview of the PSoC Microcontroller

CPU unit is the main part of a microcontroller whose purpose is to execute program
instructions and control workflow of other blocks.

Frequency generator facilitates signals necessary for CPU to work, as well as an


array of frequencies that are used by programmable blocks. These signals could be based
on internal or external referent oscillator.

Reset controller enables microcontroller start action and brings a microcontroller to


regular state in the case of irregular events.

Watch Dog timer is used to detect software dead-loops.

B.V.R.I.T. Page 28
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Sleep timer can periodically wake up microcontroller from power saving modes. It
could be also used as a regular timer.

Input-Output pins enable communication between the CPU unit, digital and analog
programmable blocks and outside world.

Digital programmable blocks are used to configure digital programmable


components which are selected by user.

Analog programmable blocks are used to configure analog components, like AD


and DA converters, filters, and DTMF receivers, programmable, instrumental, inverting,
non-inverting and operational amplifiers. Interrupt controller handles necessary operations
in the case of interrupts.

I2C controller Enables hardware realization of an I2C communication.

Voltage reference is vital for the work of analog components that reside inside of
analog programmable blocks.

MAC unit is used for operations of hardware signed multiplication of 8-bit


numbers.

SMP is a system which can be used as a part of a voltage regulator. For example, it
is possible to supply power to a PSoC microcontroller from a single 1.5V battery.

CPU During the programming, instructions are stored in program (FLASH)


memory in a way which is familiar to microcontroller. CPU fetches one instruction at a
time from program memory, decodes it and executes appropriate operations. CPU unit has
internal registers PC, SP, A, X and F, as well as ALU unit and instruction decoding unit,
that are associated to instruction execution process.

B.V.R.I.T. Page 29
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Figure 2.3: CPU Overview

2.2.4 Frequency generator:

Frequency generator is vital to CPU unit functioning, as well as programmable


blocks. Each of programmable components has certain demands regarding speed. PSoC
microcontrollers have a system for generation of different frequency signals, which is done
by graphically selecting appropriate parameters. Picture shows two independent systems
for generating signals SYSCLK and CLK 32k.

Figure 2.4: The Microcontroller-Freq Generator

B.V.R.I.T. Page 30
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

SYSCLK is the main internal clock signal with a speed of 24MHz. It is used as a
reference clock for most of other signals.

SYSCLKx2 is a clock signal with double frequency (48MHz) of SYSCLK signal.

24V1 is a signal derived by dividing frequency SYSCLK with parameter N1, which
varies in range from 1 to 16. 24V1 frequency equals SYSCLK/N1, with a frequency from
1.5MHz (N1=16) to 24MHz (N1=1).

24V2 is a signal derived by dividing 24MHz frequency with parameter N1, which
varies in range between 1 and 16. 24V2 signal frequency equals SYSCLK/N1N2., which
means that possible frequency ranges from 93.75kHz (N1, N2=16) to 24MHz (N1,N2=1).

24V3 signal is derived by dividing frequency of one of the signals 24V2, 24V1,
SYSCLK or SYSCLKx2, with number N, in the range from 1 to 256.

CPU_CLK is used as a CPU unit frequency which has a direct impact on instruction
execution speed. CPU_CLK can have any of eight frequencies that are in range from
93.75MHz to 24MHz. Frequency 24V1, 24V2, 24V3 and CPUCLK selection is done
easily, by setting appropriate parameters in Device Editor or during program runtime by
selecting three lower bits of OSCCR0 register.

CLK32K is a slow signal with a frequency of 32 kHz. It can be used as a


programmable component input. It can also be used for Sleep timer wake-up operation in
the case when other SYSCLK derived signals are inactive. Signal SYSCLK can be
acquired using internal main oscillator (IMO), while CLK32K signal is acquired through
internal local oscillator (ILO).

2.2.5 Microcontroller power consumption:

Processor signal frequency CPUCLK is directly connected with the instruction


execution speed of the microcontroller. Doubling the frequency, program executes
approximately twice faster. On the other hand, higher frequency doesnt necessary always

B.V.R.I.T. Page 31
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

mean better overall performances. Main disadvantage in raising the frequency is its
unwanted affect on microcontroller power consumption, which is one of the main problems
it the case of battery supply. Other disadvantage of higher frequency is more intensive
generation of electromagnetic interference, which may affect on surrounding devices.
Because of these problems general rule should be applied, which says that lowest possible
satisfactory frequency should be used. Default value of PSoC microcontroller signal
frequency is 3MHz, which is a compromise between speed and consumption.

2.3 Digital Inputs and Outputs:

Connection between PSoC microcontrollers with an outside world is achieved over input-
output pins. Eight pin groups which could be accessed simultaneously are parts of one port.
Although port number differs from the type of the microcontroller, write and read operations are
done in the same way in any case. Port access registers are stored inside of register address space
noted as PRT0DR, PRT1DR, PRT2DR, PRT3DR, PRT4DR or PRT5DR.

Figure 2.5: Port operation

B.V.R.I.T. Page 32
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Writing to port Writing value to PRTxDR initializes register which through init
circuit drives the state of pins. Init circuit can pass the signal from PRTxDR register
directly (strong), over pull-up or pull-down resistors or through open drain output. Beside
that, there is a possibility to isolate value of register from pin state (Hi-Z).

Reading port Reading value from address PRTxDR digital state of voltage on pins
is stored to register A. In case that voltage is dictated by some external device, read value
could differ from voltage on PRTxDR register.

Table 2.1: Pinwork Modes

DM2 bit DM1 bit DM0 bit Mode Data = 0 Data = 1

0 0 0 Resistive Pull Down Resistive Strong

0 0 1 Strong Drive Strong Strong

0 1 0 High Impedance Hi-Z Hi-Z

0 1 1 Resistive Pull Up Strong Resistive

1 0 0 Open Drain, Drives High Hi-Z Strong (Slow)

1 0 1 Slow Strong Drive Strong (Slow) Strong (Slow)

1 1 0 High Impedance Analog Hi-Z Hi-Z

1 1 1 Open Drain, Drives Low Strong (Slow) Hi-Z

Drive Mode Selection of the way in which init register PRTxDR is connected to
pins can be set inside of Device Editor or during runtime initializing registers PRTxDM2,
PRTxDM1 and PRTxDM0. There is eight methods to initialize pins in total, which enables
connection to different types of devices, with considerate smaller amount of external
components. Pin work modes are defined according to the following table depending on
contents of appropriate bit from registers DM2, DM1 and DM0.

B.V.R.I.T. Page 33
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Strong mode is used when it is needed to connect the state on PRTxDR register
directly to pins. This way of connection is applied when pin is used as an input.

Analog Hi-Z mode is used when connecting analog signals, like AD converter
input. In this case, all internal connections between PRTxDR register and pin are
disconnected, so not to interfere with value of brought voltage.

Pull-up or pull-down resistors are used when connecting with buttons or some
other devices which demand this type of components. These resistors are defining the state
on input when button is not pushed.

Open drain mode is used when it is needed to bring several devices to the same
line, when it is needed to add one external pull-up or pull-down resistor. This mode is
convenient for realization of a line which signals if there has been a mistake to one of the
microcontrollers.

2.4 Analog inputs and outputs:


Some of input-output pins, beside their standard use can perform analog input or output
operation. Any pin of port P0 as well as lower four pins of port P2 can be used as analog input.
Inputs of port P0 are connected to analog blocks over analog multiplexers, while in case of port P2
they are connected directly to programmable SC blocks. Pins P2[4] and P2[6] can serve as external
referent voltage inputs. Outputs from analog blocks can be connected to 4 output buffers, which
are connected to P0[2],P0[3],P0[4] and P0[5] pins.

B.V.R.I.T. Page 34
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Figure 2.6: Analog IO

2.5 Accessing programmable digital blocks:

Digital components, which are stored inside of programmable blocks, arent connected
directly to input or output pins. It is done in a way shown on following picture, which depicts
group of four digital programmable blocks. As it could be seen, pin connection is established using
global connection lines, multiplexer and lines of programmable blocks. PSoC microcontrollers can
have one, two or four digital programmable block groups like this one depending on their family.

Figure 2.7: Digital Block

2.6 Digital programmable blocks:

Inside of digital programmable blocks user can configure components like timers, counters,
PWM, PRS, CRC generators and devices for SPI, IrDA and UART communication, which enables
custom hardware adjustment of the system for specific uses. The process of setting and connecting
using PSoC Designer is very simple to understand, but at first is necessary to understand the way
those components function. Most components, like counters, PRS and CRC generators can be
stored inside of any free block. On the other side, communication components like Rx, TX, UART
and SPI can be set on the right side of the programmable blocks.

B.V.R.I.T. Page 35
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Figure 2.8: Digital Programming Structure

The number of necessary blocks which are used for component configuration shown in the table:

Table 2.2: Blocks

Number of blocks Components

1 Counter8, Timer8, PWM8, PRS8, RX8/TX8, SPIM/SPIS

Counter16, Timer16, PWM16, PRS16, PWMDB8, CRC16, UART,


2
IrDARx/IrDATx

3 Counter24, Timer24, PWMDB16

B.V.R.I.T. Page 36
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Number of blocks Components

4 Counter32, Timer32

2.7 Analog programmable blocks:

Analog programmable blocks are grouped in columns of three programmable blocks.


Depending on family of microcontroller, there could be 1, 2 or 4 analog columns. Each column has
input multiplexer, one frequency line, output analog and a comparator line.

Figure 2.9: Analog programming structure

MAC unit is a device that implements operation of hardware multiplication of 8-bit


signed numbers, as well as sum of product. For execution of these operations there is no
special instruction, but all of the work is done by writing to and reading from certain registers.

I2C Controller I2C controller implements hardware serial I2C communication, and in
that way minimizes usage of CPU units resources. Most important operations of I2C controller
are:
Master or Slave, sending or receiving data
Byte level data processing

B.V.R.I.T. Page 37
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Connected to CPU over interrupts or polling mode.

Transfer speed: 50K, 100K and 400K

Frequency synching in case of larger number of masters

7or 10-bit addressing of I2C unit

Interrupt Controller: Interrupts are mechanisms inside of a microcontroller that


allow responding to some event immediately after its detection. Events could be internal
(timer overrun, end of AD conversion) or external (character receiving over serial
connection, pin state change).

Figure 2.10: Interrupt sequence

Program memory is the part of ROM, which is used for storing program code,
which is written in this part of memory written by programming hardware. Program
memory is implemented in FLASH technology, which allows simple development time
change of the program inside of microcontroller. Program memory size depends on the
family of PSoC microcontrollers and is 2, 4, 8, 16 and 32 kB.

Supervisory ROM is part of ROM which is used during start of PSoC


microcontroller, as well as for calibration of components. With special instruction SSC, it is
possible access this part of memory.

RAM enables storing of variables and stack which are used during work of
microcontroller. Size of RAM, in most PSoC microcontrollers, is 256 bytes

B.V.R.I.T. Page 38
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Register address space contains registers used for peripheral's global parameters
and programmable blocks of a PSoC microcontroller. PSoC microcontrollers have 512
registers, which are grouped in two 256 bytes banks.

2.8PSoC Designer:

2.8.1. Introduction:

PSoC Designer is program package that leads user through all stages of developing
project. Version discussed here will be 4.2, but this book will still remain competent in case of
newer versions, because differences are shown only in addition of new programmable
components and some minor improvements. The most important for user is to get familiar with
two main parts of PSoC Designer:

Device Editor
Application Editor

2.8.2 Programmable Component Selection:

Most important part of the programmable component selection window is placed on


the left side. Components sorted in several groups, like AD converters, amplifiers, analog
communications, counters, etc.

B.V.R.I.T. Page 39
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Figure 2.11: Device editor

The rest of the window offers some other useful information. Resource Meter
shows how much space is left for new programmable blocks.

2.8.3 Interconnection View:

Previously selected components are still unusable, until they are placed in digital or
analog programmable blocks, and until appropriate parameters are set. This important part
of work can be done in Interconnection View window.

B.V.R.I.T. Page 40
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Figure 2.12: Interconnect view

2.8.4 Global Parameters:

On the upper left side can be found Global Resources window. It is used for general
parameters selection. This method of setting is similar to configuration words on other
microcontrollers, but with more versatility.

B.V.R.I.T. Page 41
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

2.8.5 Component Parameters:

Central window on the left side is designated as User Module Parameters.


Peripherals in PSoC microcontroller are very flexible, so it is required to set the way of
their operation. Typically this is done by selecting frequency of the signal, connecting it
with some other blocks and internal connection lines. Also, component specific parameters
can be set. Such parameters are component specific,

2.8.6 Pin Parameters:

Lower left side holds pin parameter options. In order to protect external devices
from unexpected signals, default pin state of PSoC microcontrollers is Analog Hi-Z, in
which microcontroller cannot change pin states. Pin drive mode selection can be done
graphically by selecting appropriate parameters in column Drive or software by setting
appropriate registers.

B.V.R.I.T. Page 42
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

2.8.7 Digital Components Interconnection:

For start, the most important thing is to get to know the basic elements of
programmable blocks. Digital blocks are grouped in two entireties of four blocks, as shown
on picture.

2.8.8 Analog Components Interconnection:

Analog blocks are placed on lower side of the graphic part of the window. Four
analog columns and several multiplexers can be noticed. In every of columns, upper block
ACB is used for analog amplifiers realization, while lower two are used for AD and DA
convertors. Routing is done graphically, by connecting frequency signal, and input signal to

B.V.R.I.T. Page 43
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

the same analog column.

2.8.9 Application Editor:

Application Editor is used for writing programs, which can be done using assembly
or C. Application Editor itself, bears much resemblance to IDE-s of other standard 8-bit
microcontrollers. Left side window holds list of files that are contained in current project.
Most important file for users is called main.

B.V.R.I.T. Page 44
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

B.V.R.I.T. Page 45
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

CHAPTER 3

PSoC User Modules

3.1 User Modules Introduction


3.2 LCD User Module
3.3 TX8 User Module
3.4 RX8 User Module
3.5 One Wire Software User Module

3.1 User Modules Introduction:

Over the years, microcontrollers have become highly integrated and have begun to
offer a large portfolio of peripherals. In many implementations, various features present on
the microcontroller are seldom or never used. For example in the case of a smoke detector, a
microcontroller might be using an ADC to monitor the ionization chamber but resources like
timers and communication interfaces are not being used. Also, in the event of a fire, after the
smoke causes a reduction in voltage output from the ionization chamber, the microcontroller

B.V.R.I.T. Page 46
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

does not need to use the ADC resource anymore but instead requires a PWM output to the
speaker system to issue an alarm. A microcontroller will need to have both, an ADC and a
PWM to allow the smoke detector to scream at the appropriate time, but is only using one or
the other and wasting many more.

PSoC is a family of mixed-signal arrays made by Cypress Semiconductor that


integrate a microcontroller and the components that typically surround it into a single
package. The PSoC architecture includes configurable blocks of analog circuits and digital
logic, as well as a programmable interconnect that allows the user to create customized
peripheral configuration to match the requirements of each individual application. Each of
the blocks is controlled by a set of latch-based registers. User modules are an abstraction of
register settings that enable a high level function.

In some other designs, a certain set of modules are used only when an exception
occurs. The controller in an emergency lighting system needs modules to run routines to
charge the battery, while constantly monitoring to see if a power failure occurred. Once the
power failure does occur, the modules responsible for charging the battery take the shape of
modules that deliver the right amount of current to the LEDs.

Some of the important user modules that are present in the PSoC are different types of
ADC, different versions of amplifiers, different versions of counters, digital to analog converters,
filters, multiplexers, pulse width modulators, internal temperature sensor, timers.

The user modules that we are going to use in our project are:

3.2 LCD User Modules:

a) Features and Overview:

Uses the industry standard Hitachi HD44780 LCD display driver chip protocol,

Requires only seven I/O pins,

Routines provided to print RAM or ROM strings,

B.V.R.I.T. Page 47
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Routines provided to print numbers,

Routines provided to display horizontal and vertical bar graphs,

Uses a single I/O port.

The LCD Tool Box User Module is a set of library routines that writes text strings
and formatted numbers to a common two- or four-line LCD module. This library uses the
4-bit interface mode to limit the number of I/O pins required.

Figure 3.1: Block Diagram of LCD to PSoC Interfacing

b) Functional Description:

The LCD User Module uses a single I/O port to interface to an industry standard
Hitachi HD44780A LCD controller. This type of display has a simple interface consisting of 8
data bits, read/write (R/W), register select "RS," and an enable "E" signal. To reduce the
number of pins required, the 4-bit interface mode is used. The LCD to PSoC block diagram and
the table below, describe the 4-bit interface connections.

B.V.R.I.T. Page 48
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

c) LCD Port:

Selects which PSoC I/O port is used to interface to the LCD display module. Bar graph
selects whether the bar graph functions are enabled. If disabled, the bar graph code is not
generated, saving ROM space.

d) Application Programming Interface:

The Application Programming Interface (API) routines are provided as part of the user
module to allow the designer to deal with the module at a higher level. This section specifies
the interface to each function together with related constants provided by the "include" files.

The following are the API programming routines provided for the LCD User Module:

e) Basic LCD Tool Box Functions:

1. LCD_Start:

Description: Initializes LCD to use the multi-line 4-bit interface. This function should be called
prior to all other LCD functions.

C Prototype: void LCD_Start (void);

Assembly: call LCD_Start

2. LCD_Position:

B.V.R.I.T. Page 49
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Description: Moves cursor to a location specified by the parameters. The upper left character is
row 0, column 0. For a two-line by 16 character display, the lower right character is row 1,
column 15.

C Prototype: void LCD_Position( BYTE bRow, BYTE bCol);

Assembly: mov A,01h ; Load Row

Mov X,02h ; Load Column

call LCD_Position

Parameters:

bRow: The row number at which to position the cursor. Zero specifies the first row.

bCol: The column number at which to position the cursor. Zero specifies the first (left most)
column.

3. LCD_PrString:

Description: Prints a null terminated RAM-based character string to the LCD at the present
cursor location.

C Prototype: void LCD_PrString(CHAR * sRamString);

Assembly: mov A,>sRamString ; Load MSB part of pointer to RAM-based null

mov X,<sRamString ; Load LSB part of pointer to RAM-based null

call LCD_PrString ; Call function to display string at current position

Parameters: sRamString: A pointer to a null-terminated string located in RAM.

4. LCD_PrCString:

Description: Prints a null terminated ROM-based character string to the LCD at the present
cursor location.

C Prototype: void LCD_PrCString(const char * sRomString);

Assembly: mov A,>sRomString ; Load MSB part of pointer to ROM-based null

mov X,<sRomString ; Load LSB part of pointer to ROM-based null

B.V.R.I.T. Page 50
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

call LCD_PrCString ; Call function to display string at current position

Example String Printing Code:

char str[ ] = "User Module"; // Define "RAM" based string

LCD_Start (); // Initialize LCD hardware

LCD_Position (0,4); // Position cursor @ row 0, col 4

LCD_PrCString ("PSoC LCD"); // Print a constant "ROM" string

LCD_Position (1,2); // Position cursor @ row 1, col 2

LCD_PrString (str); // Print "RAM" based string.

3.3 TX8 User Module:

a) Features and Overview:

8-bit serial transmitter with selectable clocking to 48 MHz, yielding maximum 6


Mbit data rate.

Data framing consists of start, optional parity, and stop bits.

RS-232 serial-data compliant format with even, odd, or no parity.

Optional interrupt on transmit buffer empty condition.

The TX8 User Module is an 8-bit RS-232 data-format compliant serial transmitter
with programmable clocking and selectable interrupt or polling style operation. The data
transmitted is framed with a leading start bit, an optional parity bit, and a stop bit.
Transmitter firmware is used to initialize, start, stop, read status, and write data to the TX8.

B.V.R.I.T. Page 51
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Figure 3.2: Block Diagram of TX8

b) Functional Description:

The TX8 User Module implements a serial transmitter. It uses the Buffer, Shift, and
Control registers of a digital communications type PSoC block. The Control register is
initialized and configured, using the TX8 User Module firmware Application Programming
Interface (API) routines. When the Enable bit in the Control register is set, an internal
divide-by-eight bit clock is generated. A data byte to transmit is written by an API routine
into the Buffer register, clearing the Buffer Empty status bit in the Control register. This
status bit can be used to detect and prevent transmit overrun errors.

The rising edge of the next bit clock transfers the data to the Shift register and sets
the Buffer Empty bit of the Control register. If the interrupt enable mask is enabled, an
interrupt will be triggered. This interrupt enables the queuing of the next byte to transmit,
so that upon completion of transmission of the current data byte, the new byte will be
transmitted on the next available transmit clock.

c) Parameters and Resources:

1. Clock TX8 is clocked by one of 16 possible sources. This parameter is set using the
Device Editor in PSoC Designer. The Global I/O busses may be used to connect the
clock input to an external pin or a clock function generated by a different PSoC
block.

B.V.R.I.T. Page 52
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

2. Output The output of the transmitter can be routed to the Global Output Bus. The
Global Output Bus can then be connected to an external pin or to another PSoC
block for further processing.

3. TX Interrupt Mode this option determines when an interrupt will be generated for
the TX block.

4. ClockSync In the PSoC devices, digital blocks may provide clock sources in
addition to the system clocks. Digital clock sources may even be chained in ripple
fashion.

5. Data Clock Out The Data Clock Out signal is a clock signal that corresponds to
the Clock input divided by 8. This clock is active only during the data bits of
the transmit and will be held high all other times. The rising edge of the clock
corresponds to the time when the data is stable and should be sampled. The
Data Clock Out signal can be used to facilitate data checking functions such as
Cyclical Redundancy Checks.

6. Interrupt Generation Control The following two parameters Interrupt API and
Int Dispatch Mode are only accessible by setting the Enable Interrupt
Generation Control check box in PSoC Designer. This is available under
Project > Settings.> Device Editor.

7. Interrupt API The Interrupt API parameter allows conditional generation of a


User Module's interrupt handler and interrupt vector table entry. Select

B.V.R.I.T. Page 53
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

"Enable" to generate the interrupt handler and interrupt vector table entry.
Select "Disable" to bypass the generation of the interrupt handler and
interrupt vector table entry.

8. Placement The TX8 User Module uses a single block, designated "TX", which
can map freely onto any of the Digital Communication PSoC blocks.

3.4 RX8 User Module:

a) Features and Overview:

Burst rates up to 6 Mbits/second

RS-232 data-format compliant with framing consisting of starts, optional parity,


and stop bits

Serial data format with even, odd, or no parity

Optional interrupt receive register full condition

Automatic framing, overrun, and parity error detection

The RX8 User Module is a RS-232 data-format compliant 8-bit serial receiver
with programmable clocking and selectable interrupt or polling control operation.
The format of the received data consists of a start bit, an optional parity bit, and a
trailing stop bit.

Figure 3.3: Block Diagram of RX8

B.V.R.I.T. Page 54
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

b) Functional Description:

The RX8 User Module implements a serial receiver. The RX8 maps onto a single PSoC
block designated "RX" in the PSoC Designer Device Editor. It uses the Buffer, Shift and
Control registers of a digital communications type PSoC block.

Rx Register Full bit in the Control register is set, and if the interrupt for the RX8 is
enabled, then the associated interrupt is triggered.

If the stop bit is not detected at the expected bit position in the data stream, then the
Framing Error bit in the Control register is set.

If the Buffer register has not been read, before the stop bit of the currently received
data, then the Overrun Error bit in the Control register is set.

If a parity error was detected, then the Parity Error bit is set in the Control register.

c) Parameters and Resources:

Clock RX8 is clocked by one of 16 possible sources. The Global I/O busses may be
used to connect the clock input to an external pin or a clock function generated by a
different PSoC block.

Input As a general rule, input through desired bus option to a source of


asynchronous data. Using a global bus, the input can be connected to one of the external
pins.

ClockSync In the PSoC devices, digital blocks may provide clock sources in
addition to the system clocks. Digital clock sources may even be chained in ripple fashion.
This introduces skew with respect to the system clocks.

RX Output This parameter allows the Input signal to be routed to one of the row
busses. This signal along with the Data Clock Out can be used to facilitate data verification
functions such as Cyclical Redundancy Checks.

B.V.R.I.T. Page 55
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Data Clock Out This parameter allows the bit clock in SPI Mode 3 to be routed to
one of the row busses. The bit clock is the Clock input divided by eight. The rising edge of
the Data Clock

RxCmdBuffer This parameter enables the receive command buffer and firmware
used for command processing. The UART RX interrupt must be enabled for the command
buffer to operate.

RxBufferSize This parameter determines how many RAM locations are reserved
for the receive buffer. The largest command that can be received is one less than the buffer
size selected, since the string must be null terminated. This parameter is only valid when
the RxCmdBuffer is enabled and the UART RX interrupt is enabled.

Invert Input This parameter allows the user to invert the RX input signal.

Command Terminator This parameter selects the character that signals the end of a
command. When received, a flag is set signaling a complete command has been received.

Param_Delimiter This parameter selects the character used to delimit the command
and parameters in the command receiver buffer. For example, if the Param_Delimiter is set
to a space character (32), each substring separated by a space would be a parameter.

IgnoreCharsBelow This parameter enables characters below a set value to be


ignored by the receive buffer. The characters will be received, but will not be added to the
receive buffer.

3.5 One Wire Software User Module:

The 1-Wire Master User Module is a set of library routines that write and read data as
master using the Dallas Semiconductor 1-Wire protocol. A 1-Wire master may communicate with
one or many slave devices using only one signal wire and a ground.

a) Features and Benefits:

Requires only one I/O pin to interface multiple slave devices

Uses no PSoC Blocks

B.V.R.I.T. Page 56
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Functions provided support reading and writing of both bits and bytes

Function provided for CRC-8 data integrity checking

Optional CRC-16 function for iButton data integrity checking

Optional functions provided for performing 1-Wire search for handling multiple
devices

b) Functional Description:

The 1-Wire User Module uses a single I/O pin to interface to 1-Wire components
over twisted-pair cable. A 1-Wire network consists of a master, the wiring, and one or
more slave devices. Both master and slave devices are open drain. The I/O pin is
configured to provide the resistive pull-up. The CPU is 100% utilized during data
transfers.

Figure 3.4: PSoC to 1-Wire schematic

c) Parameters and Resources:

DQIOPort Selects which PSoC I/O port is used for the 1-Wire DQ signal below.

DQPin Selects which pin of DQIOPort is used for the 1-Wire interface.

Search Selects whether the 1-Wire search functions are enabled. If disabled, the search
code is not generated to save ROM space.

B.V.R.I.T. Page 57
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Placement and Resources The 1-Wire User Module only uses one I/O pin of one port
and does not use any digital or analog blocks. There are no placement restrictions.

d) Application Programming Interface:

In all examples, the OW is used for the INSTANCE_NAME.

OW_Start:

Description: Initializes OW I/O pin to have a resistive pull-up. This function should be called
once before the other 1-Wire functions.

C Prototype: void OW_Start(void);

Assembler: call OW_Start ; Call function

OW_WriteByte

Description: Writes a byte to the 1-Wire devices.

C Prototype: void OW_WriteByte( BYTE bData);

Assembler: mov A,CCh ; Load byte

Call OW_WriteByte

Parameters:

bData: Byte to be written to the 1-Wire devices.

OW_ReadByte:

Description: Reads a byte from a 1-Wire device.

C Prototype: BYTE OW_ReadByte(void);

Assembler: call OW_ReadByte ; Byte returned in A.

Chapter 5

B.V.R.I.T. Page 58
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

6.4 DS18S20 TEMPERATURE SENSOR

Figure 6.5: Pin diagram of DS18S20

Description

The DS18S20 digital thermometer provides 9-bit Celsius temperature measurements and has an
alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18S20
communicates over a 1-Wire bus that by definition requires only one data line (and ground) for
communication with a central microprocessor. It has an operating temperature range of 55C to
+125C and is accurate to 0.5C over the range of 10C to +85C. In addition, the DS18S20 can
derive power directly from the data line (parasite power), eliminating the need for an external
power supply. Each DS18S20 has a unique 64-bit serial code, which allows multiple DS18S20s to
function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many

B.V.R.I.T. Page 59
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

DS18S20s distributed over a large area. Applications that can benefit from this feature include
HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or
machinery, and process monitoring and control systems.

Figure 6.6: DS18S20 Block diagram

Overview

A block diagram of the DS18S20, and pin descriptions are given in the Pin Description table. The
64-bit ROM stores the devices unique serial code. The scratchpad memory contains the 2-byte
temperature register that stores the digital output from the temperature sensor. In addition, the
scratchpad provides access to the 1-byte upper and lower alarm trigger registers (TH and TL). The
TH and TL registers are nonvolatile (EEPROM), so they will retain data when the device is
powered down.

B.V.R.I.T. Page 60
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

The DS18S20 uses Maxims exclusive 1-Wire bus protocol that implements bus communication
using one control signal. The control line requires a weak pullup resistor since all devices are
linked to the bus via a 3-state or open-drain port (the DQ pin in the case of the DS18S20). In this
bus system, the microprocessor (the master device) identifies and addresses devices on the bus
using each devices unique 64-bit code. Because each device has a unique code, the number of
devices that can be addressed on one bus is virtually unlimited. The 1-Wire bus protocol, including
detailed explanations of the commands and time slots, is covered in the 1-Wire Bus System
section.

Another feature of the DS18S20 is the ability to operate without an external power supply. Power
is instead supplied through the 1-Wire pullup resistor via the DQ pin when the bus is high. The
high bus signal also charges an internal capacitor (CPP), which then supplies power to the device
when the bus is low. This method of deriving power from the 1-Wire bus is referred to as parasite
power. As an alternative, the DS18S20 may also be powered by an external supply on VDD.

Operationmeasuring temperature

The core functionality of the DS18S20 is its direct-to-digital temperature sensor. The temperature
sensor output has 9-bit resolution, which corresponds to 0.5C steps. The DS18S20 powers-up in a
low-power idle state; to initiate a temperature measurement and A-to-D conversion, the master
must issue a Convert T [44h] command. Following the conversion, the resulting thermal data is
stored in the 2-byte temperature register in the scratchpad memory and the DS18S20 returns to its
idle state. If the DS18S20 is powered by an external supply, the master can issue read-time slots
(see the 1-Wire Bus System section) after the Convert T command and the DS18S20 will respond
by transmitting 0 while the temperature conversion is in progress and 1 when the conversion is
done. If the DS18S20 is powered with parasite power, this notification technique cannot be used
since the bus must be pulled high by a strong pullup during the entire temperature conversion. The
bus requirements for parasite power are explained in detail in the Powering the DS18S20 section.

B.V.R.I.T. Page 61
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

The DS18S20 output data is calibrated in degrees centigrade; for Fahrenheit applications, a lookup
table or conversion routine must be used. The temperature data is stored as a 16-bit sign-extended
twos complement number in the temperature register. The sign bits (S) indicate if the temperature
is positive or negative: for positive numbers S = 0 and for negative numbers S = 1. Resolutions
greater than 9 bits can be calculated using the data from the temperature, COUNT REMAIN and
COUNT PER C registers in the scratchpad. Note that the COUNT PER C register is hard-wired
to 16 (10h). After reading the scratchpad, the TEMP_READ value is obtained by truncating the
0.5C bit (bit 0) from the temperature data. The extended resolution temperature can then be
calculated using the following equation:

Connections:

Figure 6.7: Temperature sensor connection to PSOC pin P0.6

B.V.R.I.T. Page 62
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

CHAPTER 5

Tiny Encryption Algorithm (TEA)

6.1 Introduction
6.1.1 Basics of the Routine
6.1.2 Usage
6.1.3 Selection of Algorithm
6.1.4 Analysis
6.1.5 Preliminaries
6.2 The Key Schedule
6.2.1 Technique Developed by Inventors
6.3 Encryption Routine
6.4 Decryption Routine

B.V.R.I.T. Page 63
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

6.1 Introduction:

We give a short routine which is based on Feistel iteration and uses a large number of
rounds to get security with simplicity.

We design a short program which will run on most machines and encipher safely. It uses a
large number of iterations rather than a complicated program. It is hoped that it can easily be
translated into most languages in a compatible way. The first program is given below. It uses little
set up time and does a weak non linear iteration enough rounds to make it secure. There are no
preset tables or long set up times. It assumes 32 bit words.

6.1.1 Basics of the Routine:

It is a Festal type routine although addition and subtraction are used as the reversible
operators rather than XOR. The routine relies on the alternate use of XOR and ADD to provide
nonlinearity. A dual shift causes all bits of the key and data to be mixed repeatedly. The number of
rounds before a single bit change of the data or key has spread very close to 32 is at most six, so
that sixteen cycles may suffice and we suggest 32. The key is set at 128 bits as this is enough to
prevent simple search techniques being effective. The top 5 and bottom four bits are probably
slightly weaker than the middle bits. These bits are generated from only two versions of z (or y)
instead of three, plus the other y or z. Thus the convergence rate to even diffusion is slower.

However the shifting evens this out with perhaps a delay of one or two extra cycles. The
key scheduling uses addition, and is applied to the unshifted z rather than the other uses of the key.
In some tests k[0] etc. were changed by addition, but this version is simpler and seems as effective.
The number delta, derived from the golden number is used where

delta = (sqrt(5)-1)*2^31

A deferent multiple of delta is used in each round so that no bit of the multiple will not
change frequently. We suspect the algorithm is not very sensitive to the value of delta and we
merely need to avoid a bad value. It will be noted that delta turns out to be odd with truncation or

B.V.R.I.T. Page 64
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

nearest rounding, so no extra precautions are needed to ensure that all the digits of sum change.
The use of multiplication is an effective mixer, but needs shifts anyway. It was about twice as slow
per cycle on our implementation and more complicated. The use of a table look up in the cycle was
investigated. There is the possibility of a delay ere one entry of the table is used. For example if k
[z&3] is used instead of k [0], there is a chance one element may not be used of (3=4)32, and a
much higher chance that the use is delayed appreciably. The table also needed preparation from the
key. Large tables were thought to be undesirable due to the set up time and complication.

The algorithm will easily translate into assembly code as long as the exclusive or is an
operation. The hardware implementation is not difficult, and is of the same order of complexity as
DES [1], taking into account the double length key.

6.1.2 Usage:

This type of algorithm can replace DES in software, and is short enough to write into
almost any program on any computer. Although speed is not a strong objective with 32 cycles (64
rounds), on one implementation it is three times as fast as a good software implementation of DES
which has 16 rounds. The modes of use of DES are all applicable. The cycle count can readily be
varied, or even made part of the key. It is expected that security can be enhanced by increasing the
number of iterations.

6.1.3 Selection of Algorithm:

A considerable number of small algorithms were tried and the selected one is neither the
fastest, nor the shortest but is thought to be the best compromise for safety, ease of
implementation, lack of specialized tables, and reasonable performance. On languages which lack
shifts and XOR it will be difficult to code. Standard C does makes an arithmetic right shift and
overflows implementation dependent so that the right shift is logical and y and z are unsigned.

6.1.4 Analysis:

A few tests were run to detect when a single change had propagated to 32 changes within a
small margin. Also some loop tests were run including a deferential loop test to determine loop

B.V.R.I.T. Page 65
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

closures. These tests failed to show any unexpected behavior. The shifts and XOR cause changes
to be propagated left and right, and a single change will have propagated the full word in about 4
iterations. Measurements showed the diffusion was complete at about six iterations. There was also
a cycle test using up to 34 of the bits to find the lengths of the cycles. A more powerful version
found the cycle length of the deferential function.

d(x) =f(x XOR 2p) XOR f(x)

6.1.5 Preliminaries:

The following notation is necessary for our discussion.

Hexadecimal numbers will be subscripted with h, e.g., 10 = 16. h

Bitwise Shifts: The logical shift of x by y bits is denoted by x << y. The logical right shift of x by
y bits is denoted by x >> y.

Bitwise Rotations: A left rotation of x by y bits is denoted by x <<< y. A right rotation of x by y


bits is denoted by x >>> y.

Exclusive-OR: The operation of addition of n-tuples over the field F 2 (also known as exclusive-or)
is denoted by xy.

Integer Addition: The operation of integer addition modulo 2n is denoted by x 2n y. (where x, y


Z2n). The value of n should be clear from the context.

Feistel ciphers are a special class of iterated block ciphers where the cipher text is
calculated from the plain text by repeated application of the same transformation or round
function.

In a Feistel cipher, the text being encrypted is split into two halves. The round function, F,
is applied to one half using a sub key and the output of F is (exclusive-or-ed (XORed)) with the
other half. The two halves are then swapped. Each round follows the same pattern except for the
last round where there is often no swap. The focus of this project is the TEA Feistel Cipher.

B.V.R.I.T. Page 66
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

6.2 The Key Schedule:

The Tiny Encryption Algorithm is a Feistel type cipher (Feistel, 1973) that uses operations
from mixed (orthogonal) algebraic groups. A dual shift causes all bits of the data and key to be
mixed repeatedly. The key schedule algorithm is simple; the 128-bit key K is split into four 32-bit
blocks K = ( K[0], K[1], K[2], K[3]). TEA seems to be highly resistant to differential cryptanalysis
(Biham et al., 1992) and achieves complete diffusion (where a one bit difference in the plaintext
will cause approximately 32 bit differences in the cipher text). Time performance on a workstation
is very impressive.

6.2.1 Technique Developed by Inventors:

Wheeler et al. (1994) at the computer laboratory of Cambridge University developed the
TEA encode routine. Figure 2.1 presents the TEA encode routine in C language where the key
value is stored in k[0] k[2] and data are stored in v[0] v[1].

6.3 Encryption Routine:

The inputs to the encryption algorithm are a plaintext block and a key K .The plaintext is
P = (Left[0], Right[0]) and the cipher text is C = (Left[64], Right[64]). The plaintext block is split
into two halves, Left[0] and Right[0]. Each half is used to encrypt the other half over 64 rounds of
processing and then combine to produce the cipher text block.

Each round i has inputs Left[i-1] and Right[i-1], derived from the previous round, as well as a sub
key K[i] derived from the 128 bit overall K.

The sub keys K[i] are different from K and from each other. The constant delta =

, is derived from the golden number ratio to ensure that the sub keys are
distinct and its precise value has no cryptographic significance. The round function differs slightly
from a classical Fiestel cipher structure in that integer addition modulo 2 is used instead of
exclusive-or as the combining operator.

B.V.R.I.T. Page 67
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Flow chart for Encryption Routine

Encode routine

B.V.R.I.T. Page 68
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

6.4 Decryption Routine:

Decryption is essentially the same as the encryption process; in the decode routine
the cipher text is used as input to the algorithm, but the sub keys K[i] are used in the reverse order.

The intermediate value of the decryption process is equal to the corresponding value of the
encryption process with the two halves of the value swapped.

Flow chart for Decryption routine

B.V.R.I.T. Page 69
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Decode routine

B.V.R.I.T. Page 70
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

CHAPTER 6

Implementation

7.1 Data Transmission


7.1.1 Program for Data Transmission
7.2 Data Reception
7.2.1 Program for Data Reception

1.9 RF434 wireless communication


1.9.1 General
HM-TR series transparent wireless data link module is developed by
Hope microelectronics Co. Ltd, dedicated for applications that needs wireless data
transmission. It features high data rate, longer transmission distance. The
communication protocol is self controlled and completely transparent to user
interface. The module can be embedded to your current design so that wireless
communication can be set up easily.

HM-TRXXX-232 HM-TRXXX-TTL

B.V.R.I.T. Page 71
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

1.9.2. Features

FSK technology, half duplex mode, robust to interference


ISM band, no need to apply frequency usage license
Operation frequency can be configured and can be used in FDMA
pplications
Transmitting frequency deviation and receiver bandwidth can be selected.
Protocol translation is self controlled, easy to use.
Data rate can be select from a wide range.
Provide ENABLE pin to control duty-cycle to satisfy different application
requirements
High sensitivity, long transmission range.
Standard UART interface, TTL or RS232 logic level selectable
Very reliable, small size, easier mounting.
No tuning in producing.

1.9.3. Application

Remotecontrol,remote measurement system


Wireless metering
Access control
Identity discrimination
Data collection
IT home appliance
Smart house products
Baby monitoring

1.9.4. Pin definition

B.V.R.I.T. Page 72
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

1.9.5. Module application


Module has two modes: communication mode and configure mode, it is
determined by the status of CONFIG pin when power on:
CONFIG=LOWIt enter communication mode for data transmission
CONFIG=HIIt enter configure mode to setup work parameters

1.9.5.1 Communication mode


If CONFIG pin is low when powering on, the module will enter into communication
mode. The module provide RS232 connector to connect with PC or TLL level with
MCU directly.

B.V.R.I.T. Page 73
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Communication Diagram

It can work properly with the default configuration (default configure is


9600,8N,1. the module work parameters can be set up via HM-TR setup tool.
When the serial data rate is below 9600bps HM-TR module supports continuous
Transmission and the maximum data stream can reach 1000000bytes; however, the
data transmitted each time should not exceed 32bytes in high-speed
applications >9600bps . HM-TR module work in half-duplex mode. When
receiving 32 Bytes from the serial port, it will send data out at once. If the data
package received is below 32 Bytes, the module will wait for about 30 ms and then
send it. In order to send data immediately, 32 Bytes data per transmission is
necessary.

After each transmission, HM-TR module will be switched to receiver mode


automatically. The switch time is about 5ms. ENABLE pin is used to control the
power consumption. Once this pin is pulled down, the module will enter into sleep
mode immediately. Users can use this pin to control the receiving duty circle.

1.9.5.2 Configuration mode


If the CONFIG pin is in high level when powering on, the module will
enter into configuration mode automatically. In this mode the module communicates
with the host in fixed serial format96008N1.

B.V.R.I.T. Page 74
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Configure mode connection

7.1 Data Transmission:

B.V.R.I.T. Page 75
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Flow Chart for Data Transmission

7.1.1 Program for Data Transmission employed at the Transmitter:

//----------------------------------------------------------------------------

// C main line

//----------------------------------------------------------------------------

#include <m8c.h> // part specific constants and macros

#include "PSoCAPI.h" // PSoC API definitions for all User Modules

#include <stdlib.h>

void delay_sec(int);

char TextBuff[5];

unsigned char TLSB, TMSB, TempI, j;

B.V.R.I.T. Page 76
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

int TempP;

void encrypt (unsigned long int* v, unsigned long int* k);

void main()

unsigned long int key[4]={0x01234123,0xabcd1234,0x1234abcd,0x987654};

char ch[8];

int i=0,j=0;

TX8_1_Start(TX8_PARITY_NONE);

OneWireSW_1_Start(); // Initialize 1-Wire pin.

LCD_1_Start();

LCD_1_Position(0,0);

LCD_1_PrCString(" HI WELCOME TO ");

delay_sec(1);

LCD_1_Position(1,0);

LCD_1_PrCString("Tiny Encryption");

delay_sec(2);

LCD_1_Control(0x01);

while(1){

j=0;

i=0;

B.V.R.I.T. Page 77
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

ch[0]='A';

j=1;

while(i<2){

ch[j++]=TextBuff[i++];

LCD_1_Position(0,0);

LCD_1_PrCString("TEMP = ");

LCD_1_PrString(TextBuff);

TempP = (TempP & 0x000f)* 625; // Convert data to decimal point for display.

itoa(TextBuff,TempP,10); // Display decimal point.

if (TempP < 1000) {

ch[j++]='.';

ch[j++]='0';

LCD_1_PrCString(".0");

else {

ch[j++]='.';

LCD_1_PrCString(".");

i=0;

while(i<4){

B.V.R.I.T. Page 78
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

ch[j++]=TextBuff[i++];

//ch[j++]='C';

LCD_1_PrString(TextBuff);

LCD_1_PrCString(" C ");

j=0;

LCD_1_Control(0x01);

while(j<8){

LCD_1_Position(0,j);

LCD_1_WriteData(ch[j]);

delay_sec(1);

j++;

delay_sec(2);

encrypt(ch,key);

// TX8_1_CPutString("AA");

TX8_1_PutString(ch);

j=0;

while(j<8){

LCD_1_Position(1,j);

LCD_1_WriteData(ch[j]);

B.V.R.I.T. Page 79
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

delay_sec(1);

j++;

delay_sec(2);

i=0;

LCD_1_Control(0x01);

void delay_sec(int sec)

int i,j,secd;

for (secd=0;secd<=sec;secd++)

for(i=0;i<=2;i++)

for (j= 0;j<=15000;j++)

void encrypt (unsigned long int* v, unsigned long int* k) {

unsigned long int v0=v[0], v1=v[1], sum=0, i; /* set up */

unsigned long int delta=0x9e3779b9; /* a key schedule constant */

unsigned long int k0=k[0], k1=k[1], k2=k[2], k3=k[3]; /* cache key */

B.V.R.I.T. Page 80
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

for (i=0; i < 32; i++) { /* basic cycle start */

sum += delta;

v0 += ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + k1);

v1 += ((v0<<4) + k2) ^ (v0 + sum) ^ ((v0>>5) + k3);

} /* end cycle */

v[0]=v0; v[1]=v1; }

7.2 Data Reception:

Flow Chart for Data Reception

7.2.1 Program for Data Reception employed at the Receiver:

B.V.R.I.T. Page 81
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

//----------------------------------------------------------------------------

// C main line

//----------------------------------------------------------------------------

#include <m8c.h> // part specific constants and macros

#include "PSoCAPI.h" // PSoC API definitions for all User Modules

void delay_sec(int);

void cls(void);

void decrypt (unsigned long int *v, unsigned long int *k);

void main()

unsigned long int key[4]={0x01234123,0xabcd1234,0x1234abcd,0x987654};

char * strPtr;

char ch[10];

int i=0;

RX8_1_CmdReset();

TX8_1_Start(TX8_PARITY_NONE ) ;

RX8_1_EnableInt();

RX8_1_Start(RX8_PARITY_NONE);

M8C_EnableGInt ;

LCD_1_Start();

LCD_1_Position(0,0);

B.V.R.I.T. Page 82
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

LCD_1_PrCString("HI WELCOM TO UTS");

delay_sec(1);

LCD_1_Position(1,0);

LCD_1_PrCString("TEA SYSTEM");

delay_sec(2);

LCD_1_Control(0x01);

while(1){

LCD_1_Position(0,0);

delay_sec(1);

LCD_1_PrCString("DATA FROM TRANSM");

while(RX8_1_bCmdCheck==0);

if(strPtr = RX8_1_szGetParam())

for(i=0;i<8;i++)

ch[i]= *(strPtr+i);

i=0;

while(i<8){

LCD_1_Position(1,i);

LCD_1_WriteData(ch[i]);

delay_sec(1);

i++;

B.V.R.I.T. Page 83
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

RX8_1_CmdReset();

i=0;

TX8_1_CPutString("received encrypted data");

TX8_1_PutString(ch);

TX8_1_PutCRLF();

decrypt(ch,key);

if(ch[0]=='A') // to check the sync character with the Tx

ch[0]=' '; // for masking the initial A character

TX8_1_CPutString("After Decryption");

//for(i=0;i<8;i++)

TX8_1_PutString(ch);

TX8_1_PutCRLF();

i=0;

while(i<8){

LCD_1_Position(1,i);

LCD_1_WriteData(ch[i]);

delay_sec(1);

i++;

for(i=0;i<8;i++)

B.V.R.I.T. Page 84
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

ch[i]='\0';

LCD_1_Control(0x01);

delay_sec(2);

void delay_sec(int sec)

int i,j,secd;

for (secd=0;secd<=sec;secd++)

for(i=0;i<=2;i++)

for (j= 0;j<=15000;j++)

void decrypt (unsigned long int *v, unsigned long int *k) {

unsigned long int v0=v[0], v1=v[1], sum=0xC6EF3720, i; /* set up */

unsigned long int delta=0x9e3779b9; /* a key schedule constant */

unsigned long int k0=k[0], k1=k[1], k2=k[2], k3=k[3]; /* cache key */

for (i=0; i<32; i++) { /* basic cycle start */

v1 -= ((v0<<4) + k2) ^ (v0 + sum) ^ ((v0>>5) + k3);

B.V.R.I.T. Page 85
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

v0 -= ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + k1);

sum -= delta;

} /* end cycle */

v[0]=v0; v[1]=v1;

CHAPTER 8

Results and Conclusion

8.1 Results
8.2 Applications
8.3 Advantages
8.4 Disadvantages
8.5 Conclusion

B.V.R.I.T. Page 86
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

8.6 Contributions of the Project


8.7 Future Work

1.1 Results:
a. When we power ON the transmitter and receiver sections, the welcome note on the LCD
at both the nodes will be displayed.

Figure8.1: Welcome note on LCD at transmitter

B.V.R.I.T. Page 87
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Figure 8.2: Welcome note on LCD at receiver

b. At the transmitter side, the temperature sensor senses the surrounding temperature and it
sends to PSoC micro controller for the encryption process. On LCD at the transmitter
side, the original and encrypted data will be displayed.

Here, A character is used to synchronize the receiver with the transmitter.

B.V.R.I.T. Page 88
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Figure 8.3: The Encryption Process

c. At the receiver side, when A comes, it starts receiving the encrypted data and sends to
PSoC micro controller for the decryption process. On LCD, the encrypted and decrypted
data will be displayed.

B.V.R.I.T. Page 89
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Figure 8.4: Decryption of Received Data

Figure 8.5: Decrypted Data at the Receiver Side

8.2Applications:
i. Defense :

In defense, a code is allotted to each file in which the information is furnished regarding
transport of missiles and machinery. To send this code from one block to the other block,
the code should be encrypted into the other form so as to keep it secret.

B.V.R.I.T. Page 90
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

ii. Atomic Nuclear Plants:

In the atomic nuclear plants, the physical quantities like temperature and pressure in the
nuclear reactor are measured to maintain certain conditions for the process. The inspection
of these parameters should be done continuously and this data should be sent to the Process
Control Room simultaneously to maintain the threshold values.

iii. Oil and Gas Project Plants:

In the natural oil and gas plants, the physical quantities like temperature and pressure in the
oil wells are measured to maintain certain conditions for the process. The inspection of
these parameters should be done continuously and this data should be sent to the Process
Control Room simultaneously to maintain the threshold values.

8.3 Advantages:

1. It needs few lines of code only.

2. The key is set at 128 bits as this is enough to prevent simple search techniques being
effective.

3. The TEA Algorithm is neither the fastest, nor the shortest but it provides

ease of implementation,
the best compromise for safety,

lack of specialized tables, and

Reasonable performance.

4. The algorithm can be translated into a number of different languages and assembly
languages very easily.

B.V.R.I.T. Page 91
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

5. It is safe because of the number of cycles in the encoding and length of key.

8.4 Disadvantages:

Relatively less secure with respect to standard (used in internet) encryption and decryption
scheme.

8.5 Conclusion:

We present a simple algorithm which can be translated into a number of different languages
and assembly languages very easily. It is short enough to be programmed from memory or
a copy. It is hoped it is safe because of the number of cycles in the encoding and length of
key. It uses a sequence of word operations rather than wasting the power of a computer by
doing byte or 4 bit operations.

8.6 Contributions of the Project:


This project presented a comprehensive in-depth perceptive of TEA.

This project implemented the TEA.

8.7 Future Work:

We feel that cryptanalysis of TEA like feistel ciphers is far from complete task. In this
section we present several directions for future project.

Finding more equivalent keys (if exists) for TEA.

B.V.R.I.T. Page 92
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

Increasing number of rounds to make TEA more complex which will improve security
level.

Extending the results in this project to study other feistel ciphers.

Investigation of key space for other feistel ciphers.

Extensions of TEA like XTEA, Block TEA are proposed which will minimize threats due
to improper keys but they need further research for implementation.

REFERENCES:

B.V.R.I.T. Page 93
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

1. Books:

1. Wheeler,D.J., & Needham, R.J. (1994). TEA, a tiny encryption algorithm. In Fast
Software Encryption Proceedings of the 2nd International Workshop,1008.
2. Wheeler,D.J., & Needham, R.J. (1997). Tea extensions. Unpublished manuscript,
Computer Laboratory, Cambridge University, England.

3. Mirza, F. (1998). Block ciphers and cryptanalysis. England: Royal Holloway University
of London, Department of Mathematics.

4. National Institute of Standards, Data Encryption Standard, Federal Information


Processing Standards Publication 46. January 1977

5. E. Biham and A. Shamir, Differential Analysis of the Data Encryption Standard,


Springer-Verlag, 1993

6. B. Schneier, Applied Cryptology, John Wiley & sons, New York 1994.

2. Websites:

1. www.cypress.com/psocexampleprojects

2. www.hoperf.com

3. www.scribd.com

B.V.R.I.T. Page 94
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

APPENDIX

Flow Charts

A. Interfacing TX8 with PSoC Micro Controller


B. Interfacing RX8 with PSoC Micro Controller
C. Interfacing Temperature Sensor with PSoC Micro Controller

B.V.R.I.T. Page 95
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

FLOW CHARTS:

A. Interfacing TX8 with PSoC microcontroller:

Flow Chart for TX-232 Interfacing

B.V.R.I.T. Page 96
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

B. Interfacing RX8 with PSoC Microcontroller:

Flow Chart for RX-232 Interfacing

B.V.R.I.T. Page 97
SECURED WIRELESS COMMUNICATION LINK FOR SENSOR NETWORK APPLICATIONS

C. Interfacing Temperature Sensor with PSoC Micro Controller:

Flow Chart for Temperature Sensor Interfacing

B.V.R.I.T. Page 98