Embedded System Lab Manual Final Complete Final
Embedded System Lab Manual Final Complete Final
DEPARTMENT OF ECE
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE EMBEDDED SYSTEM LAB MANUAL
CONTENTS
Introduction to EMBEDDED SYSTEMS EMBEDDED SYSTEMS LAB SYLLABUS
.....................1 .....................2 . . . . . . . . . . . . . . . . . . . . . 18 . . . . . . . . . . . . . . . . . . . . . 28 . . . . . . . . . . . . . . . . . . . . . 39 . . . . . . . . . . . . . . . . . . . . . 43 . . . . . . . . . . . . . . . . . . . . . 61 . . . . . . . . . . . . . . . . . . . . . 65 . . . . . . . . . . . . . . . . . . . . . 72 . . . . . . . . . . . . . . . . . . . . . 75
EXPERIMENT NO.1 EXPERIMENT NO.2 EXPERIMENT NO.3 EXPERIMENT NO.4 EXPERIMENT NO.5 EXPERIMENT NO.6
APPENDIX A APPENDIX B APPENDIX C
DEPARTMENT OF ECE
ii
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE EMBEDDED SYSTEM LAB MANUAL
WHAT IS
AN
EMBEDDED
SYSTEM?
DEPARTMENT OF ECE
iii
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE EMBEDDED SYSTEM LAB MANUAL
EMBEDDED SYSTEM
An Embedded System is a special-purpose computer system designed to
perform one or a few dedicated functions. In contrast, a general-purpose computer, such as a personal computer, can do many different tasks depending on programming. . It is usually embedded as part of a complete device including hardware and mechanical parts. Embedded systems control many of the common devices in use today.
The main difference between an embedded controller and a PC is that the embedded controller is dedicated to one specific task or set of tasks. A PC is designed to run many different types of programs and to connect too many different external devices. An Embedded controller has a single program which includes the computing power and the hardware to perform that dedicated task. An Embedded Controller is reasonably priced compared to that of a PC .A PC has a relatively expensive generalized central processing unit (CPU) at its heart with many other external devices (memory, disk drives, video controllers, network interface circuits, etc.).
An embedded system has a low-cost microcontroller unit (MCU) for its intelligence, with many peripheral circuits on the same chip, and with relatively few external devices. Often, an embedded system is an invisible part, or sub-module of another product, such as a cordless drill, refrigerator or garage door opener. The controller in these products performs a small function in the entire device. The controller adds low-cost intelligence to some of the critical sub-systems in these devices. Embedded systems are not always separate devices. Most often they are physically built-in (Embedded) to the devices they control. It is a combination of both HARDWARE and SOFTWARE.
HARDWARE : Processor associated with peripherals (Interface to the real world) SOFTWARE : Programmed to get specified task (how to deal with inputs)
DEPARTMENT OF ECE
iv
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE EMBEDDED SYSTEM LAB MANUAL
HISTORY OF PROCESSOR
The first microprocessor for example, the Intel 4004, was designed for calculators and other small systems but it required more of external memory and support chips. It was a simple calculator which could only add and subtract numbers, 4 bits (a nibble) at a time. 4040 chip was very successful that it was soon followed by Intels 8-bit 8008 microprocessor. It was a simple microprocessor with limited resources, poorly implemented interrupt mechanisms, and multiplexed address and data busses. The first very powerful
8-bit microprocessor appeared in early 1974 as the Intel 8080 chip. This microprocessor had separate address and data busses with 64 Kbyte of address space which was enormous in 1975 standards. 8080 microprocessor was the first microprocessor used in homes as a personal computer named Altair.
Motorola introduced the 8-bit 6800 chip which had a different architecture to that of the 8080 but has also been very popular. In 1976, Zilog introduced the Z80 microprocessor which was very much advanced than the 8080. The instruction set of Z80 was downward compatible with the 8080 and this made Z80 to be one of the most successful microprocessors of that time. Z80 was used in many microprocessor-based applications, including home computers and games consoles. In 1976, Motorola created a microprocessor chip called 6801 which replaced a 6800 chip plus some of the chips required to make a complete computer system. This was a major step in the evolution of the microcontrollers which are basically computers consisting of only one chip. In later years, we see many other micro-controller chips in the market, such as Intel 8048, 8049, 8051, Motorola 6809,
A Microcontroller is a single chip computer .Micro suggests that the device is small and controller suggests that the device can be used in control applications. Another term used for microcontrollers is embedded controller, since most of the microcontrollers are built into (or embedded in) the devices they control. A microprocessor differs from a microcontroller in many
DEPARTMENT OF ECE
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE EMBEDDED SYSTEM LAB MANUAL
ways. The main difference is that a microprocessor requires several other components for its operation, such as program memory and data memory, I/O devices, and external clock circuit.
A microcontroller on the other hand has the entire support chips incorporated inside the same chip. All microcontrollers operate on a set of instructions (or the user program) stored in their memory. A microcontroller fetches the instructions from its program memory one by one, decodes these instructions, and then carries out the required operations.
RAM
CPU
ROM
S IN G L E C H IP
TIM E R
IO P O R T S
System-On-A-Chip (SOC) refers to integrating all components of a computer or other electronic system into a single integrated circuit (chip). These microcontrollers combine a microprocessor unit (like the CPU in a desk-top PC) with some additional circuits called peripherals, plus some additional circuits on the same chip to create a small control module DEPARTMENT OF ECE vi baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE EMBEDDED SYSTEM LAB MANUAL
requiring few other external devices. This single device can then be embedded into other electronic and mechanical devices for low-cost digital control.
Since PIC is a RISC microcontroller, it has a reduced set of instructions, more precisely 35 instructions. (Ex. Intel's and Motorola's microcontrollers have over hundred instructions) All of these instructions are executed in one cycle except for jump and branch instructions. HARVARD ARCHITECTURE
8, 14, 16
DEPARTMENT OF ECE
vii
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE EMBEDDED SYSTEM LAB MANUAL
VON-NEUMANN ARCHITECTURE
MEMORY
(DATA PROGRAM)
CPU
MEMORY UNIT
PROGRAM MEMORY (FLASH)
The Program memory is used to store a written program. Since memory made in FLASH technology can be programmed and cleared more than once, it makes this microcontroller suitable for device development. Program memory is the space where your PIC BASIC program resides. Those sizes 0.5k, 1k, 2k , 4k, and 8kare the program memory sizes for the majority of the PIC devices. Program memory in a PIC is actually 14 bits wide even though PICs are considered 8-bit microcontrollers. The 8-bit terminology comes from the data memory buss, which is 8 bits wide. A 14-bit-wide memory is commonly referred as bytes even though a byte by definition is 8 bits wide. Microchip names the 14-bit-wide addresses as Words even though a word is 16 bits long. On a 0.5k PIC, the memory moves from 0000h to 01ffh (0 to 511 decimal, 14-bit wide words). A 1k part is 0000h to 03ffh, and a 2k part is 0000h to 07ffh.
DATA MEMORY (EEPROM, RAM) EEPROM A Data memory needs to be saved when there is no supply. It is usually used for storing important data which is not lost when the power supply goes off. For instance, one such data is an assigned temperature in temperature regulators. During loss of power supply, when all the unsaved data was lost, we would have to make the changes once again. Thus our device looses on self-reliance. The data memory is used to store all of your program variables. EEPROM data memory is provided for long-term storage of data.
DEPARTMENT OF ECE
viii
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE EMBEDDED SYSTEM LAB MANUAL
RAM
RAM (Random Access Memory) is the Data memory used by programs during execution. RAM stores all inter-results or temporary data during run-time. Data memory is where all your variables are stored. The data memory is 8 bits wide, and so the PICs are considered 8-bit microcontrollers.
PROGRAM MEMORY
MEMORY
DATA MEMORY
DEPARTMENT OF ECE
ix
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
EMBEDDED SYSTEMS LAB List of Experiments as per syllabus and suggested experiments from HDL SOLUTIONS
1.
Open source software such as Linux flavors will be used. Ability to use industry standard tools for Verification and validation. Using Linux Operating System (VI Editor) developing some set of programs in high level language (C). High level language programming (c, c++ & Java) and porting it on a processor. I/O Porting using the external peripheral devices in ARM9 Processor (LED Display, SEVEN SEGMENT Display, KEYPAD).
Create FSM of a typical application and implement on an FPGA. FSM concept of Traffic Light Controller Interface on FPGA
2.
3.
4.
Application development, download partition between FPGA and ARM on Performance characteristics. A simple 4-bit Counter program to show FPGA is faster than ARM Application development & Hardware and Software Partitioning. Partitioning the FPGA using SOC concept and implement a simple 4-bit Counter program with a Embedded Core. Projects (implementation of a wireless communication protocol on an embedded system) File Transfer Application using Zigbee, Bluetooth, RF, RFID, GPS & WiFi Interface Modules
5.
6.
T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
EXPERIMENT 1: Open source software such as Linux flavors will be used. Ability to use industry standard tools for Verification and validation. AIM: To Port a compressed Embedded Linux kernel image (Linux 2.6 Kernel) to the RAM of ARM9 Processor and network the Linux-bootable ARM9 Single Board Computer to PC through Ethernet to display a message. TYPE OF PROTOBOARD USED: EXPLORER ARM-9 DEVELOPMENT BOARD HOW TO START WITH TRITON IDE Double click on the icon-Triton on your Desktop Select the workspace in which you can create all
your projects as shown in the figure below. Click OK.
Triton IDE C/C++ Environment opens as shown in below figure in which you can create new project, open existing one etc.
2 T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
Then clickProject
T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
In the Project Name field, type name of the project asdisplay. Do not use spacesor special characters in the project name.
Select the Target as per the board you have. i.e.ARM9 Select the Variant from the variant list. i.e.AT91SAM9260 Select Operating System as per your requirement. Here we should select Linux as the operating system Select the Port from Port field. i.e.COM1 Select the Baud Rate from dropdown list.i.e.38400
4 T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
Select the Build options as SDRAM, Download options as ISP Utility, Debug as MONITOR.
You can also change the location of project. For that, uncheck use default location and then browse your location. Check Create Project Using Template. then click NEXT
Below screen will appear, Debug and Release configurations would be checked. Select the type of project that you want to build. By default Project Type is Executable (Gnu)
T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
Debug-Project can be debugged on target board using serial JTAG and Ethernet Release-Project is run on Target board without debugging Uncheck the debug and click FINISH The project is created and opened in the IDE. You should see the following components: To create a new file, CLICK FILE > NEW > SOURCE FILE Browse the source folder location & enter source filename display.c
T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
The
Projects window contains a tree view of the components of the project,source files and file properties.
You can enter the code in the display.c file. 7 T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
You can double click the display.c tab in the Editor view to expand the view. /************************************************************** Display.c ***************************************************************/ #include<stdio.h> int main() { int i = 0; for(;i<5;i++) { printf("\n%d HDL SOLUTIONS...",i); } return 0; } ******************************************************************** Save thedisplay.cby choosingFile > Save. You will notice an asterisk in front of the file name on the tab in the Editor view (Workspace). The asterisk indicates that the file has changed, but has not been saved. So, save the file for every modification in the program. To compile project you need to select Release mode. Debug mode: This creates an executable hex file which you, after downloading on the target board, are able to debug. Release mode: This creates an executable hex file which you can download on the target board, but you wont be able to debug. To build project in Release mode---Right click on the DISPLAY project and point to Active Build Configuration and select Release as shown in the below screen
ToBuildProject right click on DISPLAY project and selectBuild Project. Click Build Console view to check for any errors as shown in the below figure.
If your project has built successful display.hex will be created. If there are any errors in the project Build Console view will display the error messages and from Build Output view you can check the location of errors in your code. When you build the project, the display.hex is generated
T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
SWITCH ON THE POWER SUPPLY OF ARM 9 SINGLE BOARD COMPUTER Output on HyperTerminal Open Triton IDE; from TOOLS menu, click Hyper terminal and set the Baud rate as 38400
10
T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
12
T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
To stop the running process, pressCONTROL+C To Create a new file in Linux, type touch <your filename>. This command creates an empty file. touch display.out Then press enter
Type ls, then press enter It creates your file name display.out To change the file permission to read/write & execution operation , Type chmod 777 display.out then press enter & type ls, then press enter. (To get permission to receive/execute the file from your ARM9 EMB linux OS) It shows the output file namedisplay.out Go to Start. Go to Run mode Open the command prompt TypeOasis\ide\workspace, then press enter Typec:\windows\system32\ping 192.168.0.240,then press enter Typecd displaythencd release, then press enter Typedirto check your output file, then press enter
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
enter Minimize the run mode and open the HyperTerminal window Type ./display.out then enter, you will see the output message on hyper terminal window
14
T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
15
T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
16
T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG
RESULT:
We create the open source software in C/C++ and implement to the ARM9 Linux Boot Shell with simple printing our message in Linux kernel. We are able to create source codes for Mutex, Semaphore, Fork, Pipes, Message Send & Receiving and Socket Server Programming, etc.,. (Refer: Appendix A) 17 T.M.Baskar baskarmtech@gmail.com
EXPERIMENT 2: High level language programming (C, C++) and porting it on a processor. Aim: To implement the I/O Porting using the external peripheral devices in ARM7 Processor (UART, STEPPER MOTOR, Graphical LCD Display, LED Display, SEVEN SEGMENT Display, KEYPAD, ADC/DAC, SD/MMC, I2C, SPI, I2S, CAN, LIN, USB, PCI, Ethernet). TYPE OF PROTOBOARD USED: Spirit-II / Voyager II ARM-7 Protoboard HOW TO START WITH TRITON IDE Double click on the icon-Triton on your Desktop Select the workspace in which you can create all your projects as shown in the figure below. Click OK. Triton IDE C/C++ Environment opens as shown in below figure in which you can create new project, open existing one etc.
Then clickProject
New
In the Project Name field, type name of the project asLED. Do not use spaces orspecial characters in the project name. Select the Target as per the board you have. i.e.ARM7 Select the Variant from the variant list. i.e.LPC2148 Select Operating System as per your requirement. Here we should select NONE as the operating system Select the Port from Port field. i.e.COM1 Select the Baud Rate from dropdown list.i.e.38400 Select the Build options as ROM, Download options as ISP Utility, Debug as MONITOR. You can also change the location of project. For that, uncheck use default location and then browse your location. Check Create Project Using Template. then click NEXT
19 T.M.Baskar baskarmtech@gmail.com
Below screen will appear, select Debug and Release configurations. Select the type of project that you want to build. By default Project Type is Executable (Gnu) Debug-Project can be debugged on target board using serial JTAG and Ethernet Release-Project is run on Target board without debugging Uncheck the debug and click FINISH The project is created and opened in the IDE. You should see the following components: The Projects window contains a tree view of the components of the project, source files and file properties. o The Source Editor window with a file called LED_main.c open. You can enter the code in the LED_main.c file, by replacing the line: //TODO: You can write your code at here You can double click theLED_main.c tabin the Editor view to expand the view. Save the LED_main.c by choosing File > Save. You will notice an asterisk in front of the file name on the tab in the Editor view (Workspace). The asterisk indicates that the file has changed, but has not been saved. So, save the file for every modification in the program.
20 T.M.Baskar baskarmtech@gmail.com
To compile project you need to select Release mode. Debug mode: This creates an executable hex file which you, after downloading on the target board, is able to step-by-step debugging. Release mode: This creates an executable hex file which you can download on the target board but you wont be able to debug.
21
T.M.Baskar baskarmtech@gmail.com
To build project in Release mode---Right click on the LED project and point to Active Build Configuration
22 T.M.Baskar baskarmtech@gmail.com
Open the build console view to check for any errors as shown in the
23 T.M.Baskar baskarmtech@gmail.com
belowfigure.
If your project has built successful, LED.hex will be created. If there are any errors in the project, Build Console view will display the error messages and from Build Output view you can check the location of errors in your code. When you build the project, the led.hex is generated. You can see where the new file is generated by opening the C/C++ Projects view and expanding the LED project node as shown in the following figure.
24
T.M.Baskar baskarmtech@gmail.com
Here LED.hex file is created which is to be downloaded on target board and run the program. Right click on the LED.hex file generated and click Download as shown below.
25
T.M.Baskar baskarmtech@gmail.com
Connect the hardware kit with the serial connector and power supply provided. Switch on the hardware kit. Put the switch in ISP mode for the program to be downloaded. Right click on the LED.hex file and download the executable file on to the board. Once, the program is downloaded, shift the mode from ISP to RUN and reset the board to verify the output.
DETAILS OF ON BOARD INTERFACES Switch S1- Power ON/OFF the board Switch S2- Reset switch Switch S7- To select ISP or RUN mode
26 T.M.Baskar baskarmtech@gmail.com
PIN CONFIGURATION LED (P0.15 to P0.22) Switch (P0.2 to P0.6) & (P0.8 to P0.10) Buzzer (P0.7) Relay (P1.26)
SETTINGS & DESCRIPTIONS 8 LEDs on by DIP switch Connect JP8 to ON /OFF buzzer Connect CN14 (3 pin connector )to ON relay
RESULT: We create and implement the simple I/O Porting with LEDs using the GPIO ports in ARM7 Processor. We are able to create and I/O porting of the peripherals likes LED & DIP- SWITCH, BUZZER, and RELAY.
27
T.M.Baskar baskarmtech@gmail.com
EXPERIMENT 3: Create FSM of a typical application and implement on an FPGA. AIM: To create the Finite State Machine for Traffic Light Controller and implement using Xilinx Spartan 3 (XC3S400) FPGA. Traffic Light controller is implemented on FPGA and verified using Traffic Light Interface Module. There are simple rules for traffic lights on one node, and complex ways of regulating a whole infrastructure of them. It is necessary to adjust general algorithms.Spartan-3 - IM includes a TRAFFIC LIGHT Interface Module. This module is interfaced to the Trainer using 60 pin FRC cable. DESIGN DESCRIPTION:Initially all Red Lights will be ON (South, West, North, East, Pedestrian) Green Lights will be ON , Right, Left & Straight paths are free for Traffic. Yellow Phase will be ON, respective left & pedestrian paths are free for traffic. Same flow is repeated for all four paths. (South, west, north, east). Flowchart:-
28
T.M.Baskar baskarmtech@gmail.com
Algorithm is implemented in VERILOG with a 13 state Finite State Machine. Refer Fig
Abbreviation used:
South PSG Pedestrian South Green PSR Pedestrian South Red RS Right South LS Left South SS Straight South YS Yellow South REDS Red South West PWR Pedestrian West Red PWG Pedestrian West Green RW Right West LW Left West SW South West YW Yellow West REDW Red West
29
T.M.Baskar baskarmtech@gmail.com
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG North PNR- Pedestrian North red PNG Pedestrian North green RN Right North LN Left North SN Straight North YN - Yellow North
REDN Red North
East PEG Pedestrian East green PER Pedestrian Ease Red RE Right East LE Left East SE Straight East YE Yellow East
REDE Red East
30
T.M.Baskar baskarmtech@gmail.com
Description of above Code: To Start the Traffic light controller Initially the Red light of all the directions is ON. Traffic starts from the South Direction; hence the green light of South direction goes ON. The signals that are ON, now are :TRC_LS (left south) 1. TRC_RS (right south) 1. TRC_SS (straight south) 1. TRC_LE (left east) 1. TRC_REDW (red west) 1. TRC_REDN (red north) 1. TRC_REDE (red east) 1. TRC_PSG (pedestrian south red) 1. TRC_PWG (pedestrian west red) 1. TRC_PNG (pedestrian north red) 1. TRC_PEG (pedestrian east red) 1. Similarly when Yellow light of South direction is ON then the signals that are ON now are TRC_LS (left south) 1. TRC_YS (yellow south) 1. TRC_LE (left east) 1. TRC_REDW (red west) 1. TRC_REDN (red north) 1. TRC_REDE (red east) 1. TRC_PSR (pedestrian south red) 1. TRC_PWR (pedestrian west red) 1. TRC_PNR (pedestrian north red) 1. TRC_PER (pedestrian east red) 1. Similarly when Red light of South direction is ON then the signals that are ON now are TRC_LS (left south) 1. TRC_REDW (red west) 1. TRC_REDN (red north) 1. TRC_REDE (red east) 1. TRC_PSR (pedestrian south red) 1. TRC_PWR (pedestrian west red) 1. TRC_PNR (pedestrian north red) 1. TRC_PER (pedestrian east red) 1. During this time all ways are Blocked for 1 second except left south ( ls -1 ) and so on. After that it goes clockwise for all Direction (i.e.:- South then West then North then East) similarly.
31 T.M.Baskar baskarmtech@gmail.com
Double click on the icon-Xilinx ISE 9.1ion your Desktop(or) Start---All Programs---Xilinx ISE 9.1i---Project Manager
32
T.M.Baskar baskarmtech@gmail.com
TRANSCRIPT
PROCESS WINDOW
Create a new ISE project which will target the FPGA device on the Spartan-3 IM demo board. To create a new project: 1. Select File > New Project... The New Project Wizard appears. 2. Type tutorial in the Project Name field. 3 Enter or browse to a location (directory path) for the new project. A tutorial subdirectory is created automatically. Verify that HDL is selected from the Top-Level Source Type list. Click Next to move to the device properties page. Enter the Project Name and Location , then click NEXT
33
T.M.Baskar baskarmtech@gmail.com
6. Fill in the properties in the table as shown below: Product Category: All Family: Spartan3 Device: XC3S400 Package: PQ208
Speed Grade: -4 Top-Level Source Type: HDL Synthesis Tool: XST (VERILOG/Verilog) Simulator: ISE Simulator (VERILOG/Verilog) Preferred Language: Verilog (or VERILOG)
Verify that Enable Enhanced Design Summary is selected. Leave the default values in the remaining fields. Clicknextto proceed to the Create New Source window in
the New ProjectWizard. At the end of the next section, your new project will be complete.
34
T.M.Baskar baskarmtech@gmail.com
Create an HDL Source In this section, you will create the top-level HDL file for your design. Determine the language that you wish to use for the tutorial. Then, continue either to the Creating a VERILOG Source section below, or skip to the Creating a Verilog Source section. Creating a Verilog Source Create the top-level Verilog source file for the project as follows: Click New Source in the New Project dialog box. Select Verilog Module as the source type in the New Source dialog box. Type in the file name counter. Verify that the Add to Project checkbox is selected. Click Next.
35
T.M.Baskar baskarmtech@gmail.com
Declare the ports for the counter design by filling in the port information as shown below:
and then Finish in the New Source Information dialog box to complete the new source file template. 8. Click Next, then Next, then Finish. Creating a VERILOG Source Create a VERILOG source file for the project as follows: Click the New Source button in the New Project Wizard. Select VERILOG Module as the source type. Type in the file name counter. Verify that the Add to project checkbox is selected. Click Next. Declare the ports for the counter design by filling in the port information as shown below:
7. Click next,
36
T.M.Baskar baskarmtech@gmail.com
7. Click next, and then Finish in the New Source Wizard - Summary dialog box to complete the new source file template. 8. Click Next, then Next, then Finish. The source file containing the entity/architecture pair displays the Workspace, and the counter displays in the Source tab, as shown below:Click on the symbol of FPGA device ,then right click to select New source Write the VERILOG code in VERILOG editor
37
T.M.Baskar baskarmtech@gmail.com
Testing the Traffic Controller design on the FPGA board Once design is synthesized successfully it is ready to be implemented on FPGA.
constraint file specifies the FPGA pins used for accessing the design. Step 2: To create new UCF file. Right click on the device name and select NEW SOURCE Select IMPLEMENTATION CONSTRAINT FILE in NEW SOURCE WIZARD and give suitable name for the Project. Click NEXT for the DEFINE MODULE Window. Step 3: Click on the UCF File (Traffic_Light.ucf) and Select the Edit Constraints (Text). Write the constraint file as shown in figure below. For implementing your design, from the source window select Generate Programming File from the process menu Step 4: Procedure for downloading using iMPACT Boundary Scan Mode Right click on Configure Device (iMPACT) -> and Say RUN or Double click on Configure Device (iMPACT) . Right click in workspace and select Initialize chain .The device is seen. Right click on the device and select Program .
Step 1: The first step for implementation is to generate constraint file. The
RESULT: We had done the Finite State Machine for Traffic Light Controller and implement using Xilinx Spartan 3 (XC3S400) FPGA.
38
T.M.Baskar baskarmtech@gmail.com
EXPERIMENT 4: Application development, download partition between FPGA and ARM on Performance characteristics. AIM: To create and analyze performance between ARM and FPGA Processor application using a simple 4-bit counter program. TYPE OF PROTOBOARD USED: Herculis ARM-FPGA Fusion Board PROCEDURE: 1. Create and Generate the Hex file for 4 bit Counter C / C++ program with Triton IDE.
/************************************************************
ARM_Counter.c
************************************************************/ #define ALL 0x00FF0000 #define ALL 0x00FF0000 #include<LPC21xx.h> void delay (unsigned int); int main(void) { *IODIR0=0x0000200 0; *IODIR1=0x00FF00 00; *IOCLR1=0x00FF00 00; *IOSET1=0x00FF00 00; *IOCLR0=0x000020 00; //*IOSET0=0x000020 00; while(1) { *IOSET1=0x00010000; //1 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00040000; //2 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00050000; //3 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00020000; //4 delay(400000);*IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00060000; //5 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00030000; //6 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00070000; //7 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00080000; //8 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00090000; //9
39
T.M.Baskar baskarmtech@gmail.com
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x000c0000; //10 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x000a0000; //11 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x000b0000; //12 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x000d0000; //13 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x000e0000; //14 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x000f0000; //15 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00000000; //16 delay(400000); *IOCLR1=0x00FF0000; delay(150000); delay(400000); } return 0; } void delay(unsigned int count) { while(count !=0) count--; }
2.
Download the ARM_Counter.Hex file into ARM+FPGA Fusion Board and RUN the file. 3. In that , ARM7s LED outputs are connected with Output LED LD8 to LD11 4. Create and Generate the Bit file for 4 bit Counter in VHDL program with Xilinx ISE.
/************************************************************
FPGA_Counter.vhd
************************************************************/ library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity fpga_counter is Port ( RESET : in STD_LOGIC; CLK_4M : in STD_LOGIC; COUNTER : out STD_LOGIC_VECTOR (4 downto 0)); end fpga_counter; architecture Behavioral of fpga_counter is SIGNAL CLKDIV : STD_LOGIC_VECTOR(30 DOWNTO 0); SIGNAL CNTR : STD_LOGIC_VECTOR(4 DOWNTO 0); SIGNAL en0,en1,en2,en3 : STD_LOGIC; begin 40 T.M.Baskar baskarmtech@gmail.com
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG PROCESS(RESET,CLK_4M) BEGIN IF(RESET = '1') THEN CLKDIV <= (OTHERS =>'0'); ELSIF(CLK_4M'EVENT AND CLK_4M = '1')THEN CLKDIV <= CLKDIV + '1'; END IF; END PROCESS; PROCESS(RESET,CLK_4M,clkd iv) BEGIN IF(RESET = '1') THEN en1 <= '0'; en2 <= '0'; ELSIF(CLK_4M'EVENT AND CLK_4M = '1')THEN en1 <= CLKDIV (20); en2 <= en1; END IF; END PROCESS; en0 <= en1 and (not en2); PROCESS(RESET,CLK_4M,e n0) BEGIN IF(RESET = '1') THEN CNTR <= (OTHERS =>'0'); ELSIF(CLK_4M'EVENT AND CLK_4M = '1')THEN IF(en0 = '1')THEN CNTR <= CNTR + '1'; END IF; END IF; END PROCESS; COUNTER <= CNTR; end Behavioral; -------------------------------------------------------UCF File for ARM+FPGA Fusion Board -------------------------------------------------------net "CLK_4M" loc = "p79"; net "RESET" loc = "p113"; net "COUNTER<0>" loc = "p61"; net "COUNTER<1>" loc = "p63"; net "COUNTER<2>" loc = "p64"; net "COUNTER<3>" loc = "p62"; 5. 6. Download the FPGA_Counter.bit file in to ARM+FPGA Fusion Board. Now check the FPGA Counter output in LD1 to LD4 and verify the ARM and FPGA Counter delay variations.
41
T.M.Baskar baskarmtech@gmail.com
RESULT: We create and analyze performance between ARM and FPGA Processor with 4-bit counter application by Xilinx ISE and Triton. Then, verify the speed and performance of Counter on ARM+FPGA Fusion Board. We able to create applications like UART and RTC based application on Fusion Board similarly.
42
T.M.Baskar baskarmtech@gmail.com
EXPERIMENT 5: Application development & Hardware and Software Partitioning. AIM: To Partition the FPGA using SOC concept and implement a simple 4bit Counter program with a Embedded Core TYPE OF PROTOBOARD USED: Herculis ARM-FPGA Fusion Board Introduction This lab guides you through the process of using Xilinx Platform Studio (XPS) to create a simple processor system. An MHS file and design netlists will be created. Objectives After completing this lab, you will be able to: Create an XPS project by using Base System Builder (BSB) Create a Counter hardware design by using Xilinx IPs available in the Embedded Design Kit
Procedure
The purpose of the lab exercises is to walk you through a complete hardware and software processor system design. Each lab will build upon the previous lab. In this lab, you will use the BSB of the XPS system to create a processor system consisting of the following processor IP: Microblaze DCM OPB bus OPB BRAM controller BRAM GPIO LEDs for displaying results
Figure 1-1. Processor IP
This lab comprises three primary steps: You will create a project using Base System Builder, analyze the project created, and generate the processor system netlists. Below each general instruction for a given procedure, you will find accompanying step-by-step directions and illustrated figures providing more detail for performing the general instruction. If you feel confident about a specific instruction, feel free to
43 T.M.Baskar baskarmtech@gmail.com
skip the step-by-step directions and move on to the next general instruction in the procedure. Open the Project Step 1
Launch Xilinx Platform Studio (XPS) and create a project file in D:/mb/ by using Base System Builder. Select the Microblaze processor, the processor clock frequency as 32 MHz, the bus clock frequency as 32 MHz, and no debug interface.
1. Open XPS by selecting Start Programs Studio 8.1i Xilinx Platform Studio Xilinx Platform
Do not select Platform Studio SDK; this opens the Software Development Kit IDE.
2.
This opens the Create New Project Using Base System Builder Wizard dialog box.
44
T.M.Baskar baskarmtech@gmail.com
Figure 1-3. Create New Project Using Base System Builder Wizard Dialog Box
Specify the Project File as D:/mb/system.xmp and click <OK> Select the I would like to create a new design option Click Next to display the Select Board dialog box. Select I would like to create system for Custom board.
Figure 1-4. Select I would like to create a system for custom board
Click Next to display the Select Processor dialog box Choose the FPGA device configuration
45 T.M.Baskar baskarmtech@gmail.com
Select Microblaze as the processor , spartan3 as a architecture, xc3s400 as device, PQ208 as a package, -4 as a speed grade.
Click Next to display the Configure Microblaze dialog box. Specify settings to match the following: Reference Clock Frequency: 4MHz This the external clock source on the board you are using. This clock will be used to generate the processor and bus clocks. The values allowed may depend on the FPGA or board you are using because certain on-chip resources (DCMs) may be required to perform clock division or multiplication. Processor Bus Clock Frequency: 4 MHz Reset polarity Active High Debug Interface: No debug Local memory (data and instruction) 8kB Cache setup No cache
46
T.M.Baskar baskarmtech@gmail.com
Select LEDs as the external device.Click Next to display the Configure IO Interfaces dialog box. Click on add device and select the GPIO option in IO interface type. Select LEDS under Device tab and click OK. Select 4 under GPIO Data width tab and leave the remaining parameters with the default settings. Refer to Figure 1-7. Note that the number of peripherals that appear on each window will depend on the resolution of your monitor.
Figure 1-7. Configure IO Interfaces Dialog Box
47
T.M.Baskar baskarmtech@gmail.com
Click <Next> to display the Add Internal Peripherals dialog box. At this point you could click Add Peripheral to add additional internal peripherals.
13. Click <Next> to view the memory configuration options 48 T.M.Baskar baskarmtech@gmail.com
Click Next to display the System Created dialog box which summarizes the system being created. Note that the address map for the peripheral may differ.
A congratulations dialog box appears, indicating the files that BSB has created.Click Finish to finish generating the project Click <OK> when the Next Step dialog appears
49
T.M.Baskar baskarmtech@gmail.com
Step 2
Under the Project tab, study the created project files and view the project in block diagram view.
Figure 2-1.
Under the XPS Project tab, click on Generate and view Block Diagram to open a block diagram view Observe the various components that are used in the design
50
T.M.Baskar baskarmtech@gmail.com
You will see the Microblaze processor, dlmb_if_cntlr, ilmb_if_cntlr connected to the Microblaze processor side. Notice that the opb_gpio LEDs, opb_gpio LEDs_1 are connected to the opb bus. 1. Right-click the LEDs block in system assembly view and click on configure IP, go through the various fields, and
51 T.M.Baskar baskarmtech@gmail.com
complete the following: Base address: High address: GPIO Data Bus Width: Channel 1 is bidirectional: Channel 1 is input only:
2. Why do you think that the DCM_module instances do not have connections to any of the other blocks in the design?
________________________________________________ ________________________________________________ Notice that you can change the parameters (such as base address, address range, or C_BAUDRATE) here to reflect the design specifications. Close the block diagram view without saving any changes The block diagram viewer is useful for viewing the overall system and bus connectivity. For more detail, you will utilize other tools.
Generate the Hardware Netlists
Step 3
Using PlatGen, generate the hardware netlist. 21. Open MHS file and change the following lines
PORT fpga_0_LEDS_GPIO_d_out_pin = fpga_0_LEDS_GPIO_d_out, DIR = 0, VEC = [0:3] To PORT fpga_0_LEDS_GPIO_d_out_pin = fpga_0_LEDS_GPIO_d_out, DIR = 0, VEC = [3:0]
And save the changes. 22. In XPS, select hardware Generate Netlist or click in the toolbar Observe the netlist generation in the console window as the generation progresses
24. Open Windows Explorer by selecting Start
Programs
Accessories
Windows Explorer
Browse to the mb project directory Several directories containing VHDL implementation netlists have been created. 3. List the directories that were created. Step 4
52 T.M.Baskar baskarmtech@gmail.com
wrappers
and
In project information area, Select Project, open UCF file by double clicking over it given in Project Files. Enter the pin constraints and uncomment them. The dedicated ucf is provided at the end of this document.
27. In XPS, select hardware
Generate Bitstream. Observe the bitstream generation in the console window as the generation progresses Step 5
In XPS, select software Generate Libraries and BSPs. Observe the Libraries generation in the console window as the generation progresses Observe the xparameters.h file created in the testapp_memory under applications tab
Writing C code
Step 6
53 T.M.Baskar baskarmtech@gmail.com
In XPS, under Application tab, select Project: Testapp_memory open TestApp_Memory.c. Write the C code application in the workspace. Source code for this project is given at the end of this document.
35.In XPS, select software Build all users applications. 36.Observe the elf file generation in the console window as the generation progresses. 37.Create and Generate the Bit file for 4 bit Counter in VHDL program with Xilinx ISE.
/************************************************************
FPGA_Counter.vhd
************************************************************/ library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity fpga_counter is Port ( RESET : in STD_LOGIC; CLK_4M : in STD_LOGIC; COUNTER : out STD_LOGIC_VECTOR (8 downto 0)); end fpga_counter; architecture Behavioral of fpga_counter is SIGNAL CLKDIV : STD_LOGIC_VECTOR(30 DOWNTO 0); SIGNAL CNTR : STD_LOGIC_VECTOR(4 DOWNTO 0); SIGNAL en0,en1,en2,en3 : STD_LOGIC; 54 T.M.Baskar baskarmtech@gmail.com
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG begin PROCESS(RESET,CLK_4M) BEGIN IF(RESET = '1') THEN CLKDIV <= (OTHERS =>'0'); ELSIF(CLK_4M'EVENT AND CLK_4M = '1')THEN CLKDIV <= CLKDIV + '1'; END IF; END PROCESS; PROCESS(RESET,CLK_4M,clkdiv) BEGIN IF(RESET = '1') THEN en1 <= '0'; en2 <= '0'; ELSIF(CLK_4M'EVENT AND CLK_4M = '1')THEN en1 <= CLKDIV (20); en2 <= en1; END IF; END PROCESS; en0 <= en1 and (not en2); PROCESS(RESET,CLK_4M,en0) BEGIN IF(RESET = '1') THEN CNTR <= (OTHERS =>'0'); ELSIF(CLK_4M'EVENT AND CLK_4M = '1')THEN IF(en0 = '1')THEN CNTR <= CNTR + '1'; END IF; END IF; END PROCESS; COUNTER <= CNTR; end Behavioral; -------------------------------------------------------UCF File for ARM+FPGA Fusion Board -------------------------------------------------------net "CLK_4M" loc = "p79"; net "RESET" loc = "p113"; net "COUNTER<0>" loc = "p61"; net "COUNTER<1>" loc = "p63"; net "COUNTER<2>" loc = "p64"; net "COUNTER<3>" loc = "p62"; net "COUNTER<4>" loc = "p58"; net "COUNTER<5>" loc = "p57"; net "COUNTER<6>" loc = "p54"; net "COUNTER<7>" loc = "p52";
38.In ISE, select Device Configuration download.bit file Downloading into FPGA
55
Programs
Xilinx ISE
40.Impact project dialog box will open. Select create a new project (.ipf) option and click on OK. This will open Welcome to iMPACT dialog box.
41.Keep the default setting Configure devices using Boundary-Scan [JTAG]. Click on Finish. This will identify the device xc3s400.
56
T.M.Baskar baskarmtech@gmail.com
In the Assign New Configuration File, select the download.bit file from implementation directory of your ISE project. Click on Open. The download.bit file will be assigned to the FPGA. Right click on the device and Click on Program to configure the FPGA with download.bit file. Download the download.bit file in to ARM+FPGA Fusion Board. Now check the FPGA Counter output in LD1 to LD4 for software-hardware partitioned output ie., through embedded core of FPGA and LD5 to LD8 for direct FPGA output.
Base System Builder can be used in XPS to create a project. Several files including an MHS file representing the processor system and a PBD file representing the schematic vieware created. After the system has been defined, the netlist of the processor system can be created. Answers Right-click the top LEDS block, configure IP and go through the
57 T.M.Baskar baskarmtech@gmail.com
various fields, and complete the following: Instance name: LEDS Base address: 0x40020000 High address: 0x4002ffff GPIO Data Bus Width: 4 Channel 1 is bidirectional: FALSE Channel 1 is Input only: FALSE Why do you think that the DCM_module instance does not have connections to any of the other blocks in the design? This module generate signals which are area connected to almost every module in the design. For example, the clock signal generated by DCM_module is connected to the processor and opb controller. 3. List the directories that were created. data etc hd l implementatio n pcores mb_0 synthesis TestApp_Memory __xps
B
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG PARAMETER INSTANCE = dlmb PARAMETER HW_VER = 1.00.a PARAMETER C_EXT_RESET_HIGH = 1 PORT SYS_Rst = sys_rst_s PORT LMB_Clk = sys_clk_s END BEGIN lmb_bram_if_cntlr PARAMETER INSTANCE = dlmb_cntlr PARAMETER HW_VER = 1.00.b PARAMETER C_BASEADDR = 0x00000000 PARAMETER C_HIGHADDR = 0x00001fff BUS_INTERFACE SLMB = dlmb BUS_INTERFACE BRAM_PORT = dlmb_port END BEGIN lmb_bram_if_cntlr PARAMETER INSTANCE = ilmb_cntlr PARAMETER HW_VER = 1.00.b PARAMETER C_BASEADDR = 0x00000000 PARAMETER C_HIGHADDR = 0x00001fff BUS_INTERFACE SLMB = ilmb BUS_INTERFACE BRAM_PORT = ilmb_port END BEGIN bram_block PARAMETER INSTANCE = lmb_bram PARAMETER HW_VER = 1.00.a BUS_INTERFACE PORTA = ilmb_port BUS_INTERFACE PORTB = dlmb_port END BEGIN opb_v20 PARAMETER INSTANCE = mb_opb PARAMETER HW_VER = 1.10.c PARAMETER C_EXT_RESET_HIGH = 1 PORT SYS_Rst = sys_rst_s PORT OPB_Clk = sys_clk_s END BEGIN opb_gpio PARAMETER INSTANCE = LEDS PARAMETER HW_VER = 3.01.b PARAMETER C_GPIO_WIDTH = 4 PARAMETER C_IS_DUAL = 0 PARAMETER C_ALL_INPUTS = 0 PARAMETER C_IS_BIDIR = 0 PARAMETER C_BASEADDR = 0x40020000 PARAMETER C_HIGHADDR = 0x4002ffff BUS_INTERFACE SOPB = mb_opb PORT OPB_Clk = sys_clk_s PORT GPIO_d_out = fpga_0_LEDS_GPIO_d_out END BEGIN dcm_module PARAMETER INSTANCE = dcm_0 PARAMETER HW_VER = 1.00.a PARAMETER C_CLK0_BUF = TRUE 59 T.M.Baskar baskarmtech@gmail.com
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG PARAMETER C_CLKIN_PERIOD = 31.250000 PARAMETER C_CLK_FEEDBACK = 1X PARAMETER C_DLL_FREQUENCY_MODE = LOW PARAMETER C_EXT_RESET_HIGH = 1 PORT CLKIN = dcm_clk_s PORT CLK0 = sys_clk_s PORT CLKFB = sys_clk_s PORT RST = net_gnd PORT LOCKED = dcm_0_lock END
C
Completed .c File
#include "xparameters.h" #include "xutil.h" #include "xio.h" #include "xgpio_l.h" main () {long count = 0, i; while(1){XGpio_mSetDataReg(XPAR_LEDS_BASEADDR, 1, count); count = count + 1; for(i=0; i<10000000; i++); }}
RESULT:
We create an embedded core through software partitioning of the actual hardware and implement a simple 4-bit counter application by Xilinx EDK Tool. Then verify the speed and performance of Partition on FPGA processor. In these Xilinx EDK, performs many kind of processing in Partitioning.
60
T.M.Baskar baskarmtech@gmail.com
1. 2.
3. 4.
5.
6. 7. 8. 9.
EXPERIMENT 6: Implementation of a wireless communication protocol on an embedded system AIM: To implement wireless communication protocol (like. ZigBee / Bluetooth / RF) on an Embedded System. PROCEDURE FOR ZIGBEE Aim: To Interface a ZigBee module with ARM7 TYPE OF PROTOBOARD USED: Spirit-II/Voyager-II ARM-7 Protoboard 2 Nos Zigbee Transceiver Pair - 1 Pair Theory of Operation: Zigbee is a specification for a suite of high level communication protocols using small, low powered digital radios based on IEEE 802.15.4-2003 standard and are used extensively for Wireless Home Area Networks (WHANs), such as wireless light switches with lamps, electrical meters with in-home displays etc. ZigBee is targeted towards at RF applications that require a low data rate, long battery life and secure networking. Procedure and Observation: Open Triton IDE. Select a workspace and create a new Project ZIGBEE_LPC2148 Write in the program for ZIGBEE_LPC2148 as provided in the Documentation CD and ignore step 3 or else click File menu -> Add Project ->Existing Project into Workspace and click next. If importing project browse the Documentation CD and select ZIGBEE_LPC2148 and also check option Copy projects into workspace and click finish. Save the file, build the Project in Release Mode and generate hex file (ZIGBEE_LPC2148.hex) Download the hex file to ARM7 Board. Disconnect ARM7 UART1 from the PCs COM port. Connect the ZigBee module to ARM7 board using the provided male to male serial cable. Attach USB A to B cable between PCs USB port and the USB connector on ARM7 Processor add-on board. 10.Repeat steps 6, 7, 8 and 9 for another ARM7 board.Slide RUN/ISP switch into Run mode and press momentarily.Once the initialization is over type anything into one hyper terminal and that will be visible in the other hyper terminal.
61
T.M.Baskar baskarmtech@gmail.com
RESULT: We interfaced two ZigBee modules to two separate ARM7 protoboards and established communication between them. These ZigBee modules can be configured in various Network Topologies and are a drop-in replacement wireless application such as Home Automation and Wireless Sensor Networks. (Refer Appendix C) B) PROCEDURE FOR BLUETOOTH Aim: To Interface a Bluetooth connected to ARM7 with a Computer TYPE OF PROTOBOARD USED: Spirit-II/Voyager-II ARM-7 Protoboard 1 No. Bluetooth Interface Module with dongle - 1 No. Theory of Operation: Conceived by Ericsson in 1994 as a wireless replacement to RS232 bluetooth today is a wireless technology for exchanging data over short distances (using short wavelength radio transmissions) and creating PANs (Personal Area Networks) with high levels of security. Utilizing the frequency hopping spread spectrum the modulation details of which are as under Basic data rate 1Mbit/s GFSK (Gaussian Frequency Shift Keying) Extended Rate 2 Mbit/s /4 DPSK (Differential Phase Shift Keying) Extended Rate 3 Mbit/s 8 DPSK (Differential Phase Shift Keying) Procedure and Observation: Open Triton IDE. Select a workspace and create a new Project Bluetooth_LPC2148 1. Write in the program for Bluetooth_LPC2148 as provided in the Documentation CD and ignore step 3 or else click File menu -> Add Project ->Existing Project into Workspace and click next. 2. If importing project browse the Documentation CD and select .Bluetooth_LPC2148 and also check option Copy projects into workspace and click finish. Save the file, build the Project in Release Mode and generate hex file (Bluetooth_LPC2148.hex) Download the hex file to ARM7 Board and Disconnect ARM7 UART1 from the PCs COM port. 3. Connect the Bluetooth module to ARM7 board using the provided male to male serial cable. Attach USB A to B cable between PCs USB port and the USB connector on ARM7 Processor add-on board. Slide RUN/ISP switch into Run mode and press momentarily and Power on the bluetooth addon board.If Computer finds a new device and asks for drivers browse and upload the drivers for this cable provided in the Documentation CD. 4. Check the virtual COM port number on device manager.Open a
62 T.M.Baskar baskarmtech@gmail.com
Hyper terminal with the found COM port number and select baud rate as 115200. 5. Connect the provided USB Bluetooth Dongle to any of the Computers free USB port.Wait for the automatic installation of the bluetooth software.Double click the bluetooth icon visible in the system tray and use the software for searching and connecting to the bluetooth module. 6. If asked for a passkey the default passkey is 8888.When connected open the device manager to again see the assigned outgoing COM port number.Open hyper terminal for the COM port and type anything. This will be visible on another HT. RESULT: File transfer between a PC and ARM7 Protoboard through Bluetooth Interface is studied. C) PROCEDURE FOR RF MODULE Aim: To interface a RF Module to ARM7 Processor. TYPE OF PROTOBOARD USED: Spirit-II/Voyager-II ARM-7 Protoboard 2 Nos RF Transceiver Pair - 1 Pair Theory of Operation: In this exercise we establish communication between two RF modules from Nordic Semiconductors. These modules work in the ISM band of 2.4 GHz and have a SPI interface through which they are controlled and configured. Being a transceiver they establish full duplex communication. Communication between ARM7 and RF module are also of two types. They are command mode and data mode. In command mode we tell the module that we will be using it as a transmitter or receiver etc. In data mode we either send or receive data depending on the operating mode. Procedure and Observation: Open Triton IDE. Select a workspace and create a new Project nordic_rf24l01p_LPC2148 Write in the program for nordic_rf24l01p_LPC2148 as provided in the Documentation CD and ignore step 3 or else click File menu -> Add Project ->Existing Project into Workspace and click next. If importing project browse the Documentation CD and select nordic_rf24l01p_LPC2148 and also check option Copy projects into workspace and click finish. Now open file nordic_rf24l01p_LPC2148_main.c and scroll to line number 16 Assign values to NRF24l01_MODE_TX as 1 and to
63 T.M.Baskar baskarmtech@gmail.com
1. 2. 3.
4.
5.
6.
NRF24l01_MODE_RX as 0 so that it looks like for Transmitter Enable. #define NRF24l01_MODE_TX 1 #define NRF24l01_MODE_RX0 7. Save the file, build the Project in Release Mode and generate hex file (nordic_rf24l01p_LPC2148.hex) 8. Download the hex file to ARM7 Board. 9. Reverse the assigned values for NRF24l01_MODE so that they look like for Receiver Enable. #define NRF24l01_MODE_TX 0 #define NRF24l01_MODE_RX1 10.Repeat step 7.ownload into another ARM7 board and not the one to which we had downloaded earlier. Connect two separate RF modules to these two ARM7 boards to their appropriate connectors. One ARM7 board will act as a transmitter and the other as a receiver. Connect these two boards to two different computers and open HyperTerminal in each one of them at baud rate 115200. 14.Slide RUN/ISP switch into Run mode and press momentarily. 15.Both these Hyper Terminals will give some initialization prints and at the end will tell the operating mode in which they are configured. 16.The board that is in Tx mode will ask for characters to send after initialization as completed. Type in anything and that will be visible on the hyper terminal connected on other board. RESULT:
File transfer between a PC and ARM7 Protoboard through an ISM band 2.4 GHz RF module pair over SPI is studied. This interface can be used in applications like Remote Monitoring, Wireless data transfer, Wireless Sensor Networks etc.
64
T.M.Baskar baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
Appendix A
DEPARTMENT OF ECE
65
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
} pthread_mutex_unlock(&mutex); printf("waiting for thrd to finish...\n"); res = pthread_join(thrd,&thread_res); if(res != 0){ printf("thread join failed\n"); exit(EXIT_FAILURE); } printf("Thread joined\n"); pthread_mutex_destroy(&mutex); exit(EXIT_SUCCESS); } void *thread_func(void *arg) { sleep(1); pthread_mutex_lock(&mutex); while(strncmp("end",warea,3) != 0){ printf("No. of characters = %d \n",strlen(warea) - 1); warea[0] = '\0'; pthread_mutex_unlock(&mutex); sleep(1); pthread_mutex_lock(&mutex); while(warea[0] == '\0') { pthread_mutex_unlock(&mutex); sleep(1); pthread_mutex_lock(&mutex); } } time_to_exit = 1; warea[0] = '\0'; pthread_mutex_unlock(&mutex); pthread_exit(0); } /*************************************************************** Semaphore.c ***************************************************************/ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <semaphore.h> void *thread_func(void *arg); sem_t sem; #define WORK_SIZE 50 char warea[WORK_SIZE]; int main() { int res; pthread_t thrd; void *thread_res;
DEPARTMENT OF ECE
66
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
DEPARTMENT OF ECE
67
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
DEPARTMENT OF ECE
68
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
DEPARTMENT OF ECE
69
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
DEPARTMENT OF ECE
70
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
DEPARTMENT OF ECE
71
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
Appendix B
/*************************************************************** LED_main.c ***************************************************************/ #define ALL 0x007f8000 #define ALL 0x007f8000 #include<LPC21xx.h> void delay (unsigned int); int main(void) { *IODIR0=ALL; *IOCLR0=ALL; while(1) { *IOSET0= ALL; delay(150000); *IOCLR0=ALL; delay(150000); }return 0; } void delay(unsigned int count) { while(count!=0) count--; } /*********************************************************************** DIP_SWITCH.c ************************************************************************/ #include <lpc21xx.h> int main(void) { *IODIR0=*IODIR0 | 0X000000F7C; *IOSET0 = 0X000000F7C; int i; whil e(1) { *IODIR0 =*IODIR0 | 0x007f8000; //Set Direction of LED *IOCLR0 = 0x007f8000; //Clear all LED's *IOSET0 = ((*IOPIN0 & 0X000000F7C) << 12); for(i=0;i<200000;i++); for(i=0;i<20000;i++); } return 0; } *IOSET0 = 0X000000F7C;
/ /
/ /
DEPARTMENT OF ECE
72
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
DEPARTMENT OF ECE
73
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
} return 0; }
DEPARTMENT OF ECE
74
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
Appendix C
A) ZIGBEE
#include <string.h> // memcpy #include "type.h" #include "target.h" #include "usbdebug.h" #define LPC214x #ifdef LPC214x #include "lpc214x.h" #endif #ifdef LPC23xx #include "lpc23xx.h" #endif #include "armVIC.h" #include "uart.h" #include "usbapi.h" #include "serial_fifo.h" #define MODE_ZIGBEE #if defined(MODE_BLUETOOTH) #define UART_BAUD_RATE 115200 #elif defined(MODE_ZIGBEE) || defined(MODE_WIFI) #define UART_BAUD_RATE 9600 #endif #define INT_IN_EP 0x81 #define BULK_OUT_EP 0x05 #define BULK_IN_EP 0x82 #define MAX_PACKET_SIZE 64 #define LE_WORD(x) ((x)&0xFF),((x)>>8) // CDC definitions #define CS_INTERFACE 0x24 #define CS_ENDPOINT 0x25 #define SET_LINE_CODING 0x20 #define GET_LINE_CODING 0x21 #define SET_CONTROL_LINE_STATE 0x22 #define INT_VECT_NUM 0 #define IRQ_MASK 0x00000080 // data structure for GET_LINE_CODING / SET_LINE_CODING class requests typedef struct { U32 dwDTERate; U8 bCharFormat; U8 bParityType; U8 bDataBits; } TLineCoding; static TLineCoding LineCoding = {115200, 0, 0, 8}; static U8 abBulkBuf[64];
DEPARTMENT OF ECE
75
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL static U8 abClassReqData[8]; static volatile BOOL fBulkInBusy; static volatile BOOL fChainDone; static U8 txdata[VCOM_FIFO_SIZE]; static U8 rxdata[VCOM_FIFO_SIZE]; static fifo_t txfifo; static fifo_t rxfifo; // forward declaration of interrupt handler static void USBIntHandler(void) __attribute__ ((interrupt("IRQ"))); static const U8 abDescriptors[] = { // device descriptor 0x12, DESC_DEVICE, LE_WORD(0x0101), // bcdUSB 0x02, // bDeviceClass 0x00, // bDeviceSubClass 0x00, // bDeviceProtocol MAX_PACKET_SIZE0, // bMaxPacketSize LE_WORD(0xFFFF), // idVendor LE_WORD(0x0005), // idProduct LE_WORD(0x0100), // bcdDevice 0x01, // iManufacturer 0x02, // iProduct 0x03, // iSerialNumber 0x01, // bNumConfigurations // configuration descriptor 0x09, DESC_CONFIGURATION, LE_WORD(67), // wTotalLength 0x02, // bNumInterfaces 0x01, // bConfigurationValue 0x00, // iConfiguration 0xC0, // bmAttributes 0x32, // bMaxPower // control class interface 0x09, DESC_INTERFACE, 0x00, // bInterfaceNumber 0x00, // bAlternateSetting 0x01, // bNumEndPoints 0x02, // bInterfaceClass 0x02, // bInterfaceSubClass 0x01, // bInterfaceProtocol, linux requires value of 1 for the cdc_acm module 0x00, // iInterface // header functional descriptor DEPARTMENT OF ECE 76 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL 0x05, CS_INTERFACE, 0x00, LE_WORD(0x0110), // call management functional descriptor 0x05, CS_INTERFACE, 0x01, 0x01, // bmCapabilities = device handles call management 0x01, // bDataInterface // ACM functional descriptor 0x04, CS_INTERFACE, 0x02, 0x02, // bmCapabilities // union functional descriptor 0x05, CS_INTERFACE, 0x06, 0x00, // bMasterInterface 0x01, // bSlaveInterface0 // notification EP 0x07, DESC_ENDPOINT, INT_IN_EP, // bEndpointAddress 0x03, // bmAttributes = intr LE_WORD(8), // wMaxPacketSize 0x0A, // bInterval // data class interface descriptor 0x09, DESC_INTERFACE, 0x01, // bInterfaceNumber 0x00, // bAlternateSetting 0x02, // bNumEndPoints 0x0A, // bInterfaceClass = data 0x00, // bInterfaceSubClass 0x00, // bInterfaceProtocol 0x00, // iInterface // data EP OUT 0x07, DESC_ENDPOINT, BULK_OUT_EP, // bEndpointAddress 0x02, // bmAttributes = bulk LE_WORD(MAX_PACKET_SIZE), // wMaxPacketSize 0x00, // bInterval DEPARTMENT OF ECE 77 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL // data EP in 0x07, DESC_ENDPOINT, BULK_IN_EP, // bEndpointAddress 0x02, // bmAttributes = bulk LE_WORD(MAX_PACKET_SIZE), // wMaxPacketSize 0x00, // bInterval // string descriptors 0x04, DESC_STRING, LE_WORD(0x0409), 0x0E, DESC_STRING, 'L', 0, 'P', 0, 'C', 0, 'U', 0, 'S', 0, 'B', 0, 0x14, DESC_STRING, 'U', 0, 'S', 0, 'B', 0, 'S', 0, 'e', 0, 'r', 0, 'i', 0, 'a', 0, 'l', 0, 0x12, DESC_STRING, 'D', 0, 'E', 0, 'A', 0, 'D', 0, 'C', 0, '0', 0, 'D', 0, 'E', 0, // terminating zero 0 }; /** Local function to handle incoming bulk data @param [in] bEP @param [in] bEPStatus */ static void BulkOut(U8 bEP, U8 bEPStatus) { int i, iLen; if (fifo_free(&rxfifo) < MAX_PACKET_SIZE) { // may not fit into fifo return; } // get data from USB into intermediate buffer iLen = USBHwEPRead(bEP, abBulkBuf, sizeof(abBulkBuf)); for (i = 0; i < iLen; i++) { // put into FIFO if (!fifo_put(&rxfifo, abBulkBuf[i])) { // overflow... :( ASSERT(FALSE); break; } }}
DEPARTMENT OF ECE
78
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL /** Sends the next packet in chain of packets to the host @param [in] bEP @param [in] bEPStatus */ static void SendNextBulkIn(U8 bEP, BOOL fFirstPacket) { int iLen; // this transfer is done fBulkInBusy = FALSE; // first packet? if (fFirstPacket) { fChainDone = FALSE; } // last packet? if (fChainDone) { return; } // get up to MAX_PACKET_SIZE bytes from transmit FIFO into intermediate buffer for (iLen = 0; iLen < MAX_PACKET_SIZE; iLen++) { if (!fifo_get(&txfifo, &abBulkBuf[iLen])) { break; } } // send over USB USBHwEPWrite(bEP, abBulkBuf, iLen); fBulkInBusy = TRUE; // was this a short packet? if (iLen < MAX_PACKET_SIZE) { fChainDone = TRUE; }} /** Local function to handle outgoing bulk data @param [in] bEP @param [in] bEPStatus */ static void BulkIn(U8 bEP, U8 bEPStatus) { SendNextBulkIn(bEP, FALSE); } /** Local function to handle the USB-CDC class requests @param [in] pSetup @param [out] piLen @param [out] ppbData */ static BOOL HandleClassRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData) DEPARTMENT OF ECE 79 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL { switch (pSetup->bRequest) { // set line coding case SET_LINE_CODING: DBG("SET_LINE_CODING\n"); memcpy((U8 *)&LineCoding, *ppbData, 7); *piLen = 7; DBG("dwDTERate=%u, bCharFormat=%u, bParityType=%u, bDataBits=%u\n", LineCoding.dwDTERate, LineCoding.bCharFormat, LineCoding.bParityType, LineCoding.bDataBits); break; // get line coding case GET_LINE_CODING: DBG("GET_LINE_CODING\n"); *ppbData = (U8 *)&LineCoding; *piLen = 7; break; // set control line state case SET_CONTROL_LINE_STATE: // bit0 = DTR, bit = RTS DBG("SET_CONTROL_LINE_STATE %X\n", pSetup->wValue); break; default: return FALSE; } return TRUE; } /** Initialises the VCOM port. Call this function before using VCOM_putchar or VCOM_getchar */ void VCOM_init(void) { fifo_init(&txfifo, txdata); fifo_init(&rxfifo, rxdata); fBulkInBusy = FALSE; fChainDone = TRUE; } /** Writes one character to VCOM port @param [in] c character to write @returns character written, or EOF if character could not be written */ int VCOM_putchar(int c) DEPARTMENT OF ECE 80 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL { return fifo_put(&txfifo, c) ? c : EOF; } void VCOM_putstring(const char *string,int len) { int i; for(i=0;i<len;i++) { VCOM_putchar((int)string[i]); }} /** Reads one character from VCOM port @returns character read, or EOF if character could not be read */ int VCOM_getchar(void) { U8 c; return fifo_get(&rxfifo, &c) ? c : EOF; } /** Interrupt handler Simply calls the USB ISR, then signals end of interrupt to VIC */ static void USBIntHandler(void) { USBHwISR(); VICVectAddr = 0x00; // dummy write to VIC to signal end of ISR } /** USB frame interrupt handler Called every milisecond by the hardware driver. This function is responsible for sending the first of a chain of packets to the host. A chain is always terminated by a short packet, either a packet shorter than the maximum packet size or a zero-length packet (as required by the windows usbser.sys driver). */ static void USBFrameHandler(U16 wFrame) { if (!fBulkInBusy && (fifo_avail(&txfifo) != 0)) { // send first packet SendNextBulkIn(BULK_IN_EP, TRUE); }} /** USB device status handler Resets state machine when a USB reset is received. */ DEPARTMENT OF ECE 81 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL static void USBDevIntHandler(U8 bDevStatus) { if ((bDevStatus & DEV_STATUS_RESET) != 0) { fBulkInBusy = FALSE; } } #define MAX_DATA_LENGTH 256 typedef struct { unsigned char data[MAX_DATA_LENGTH]; unsigned int data_ptr; }data_fifo_t; typedef struct { data_fifo_t rx; data_fifo_t tx; }uart_buffer_t; uart_buffer_t vcp_buff; / *********************************************************************** ** main ==== ***********************************************************************/ int main(void) { int vcp_ch,uart_ch,i; // PLL and MAM //HalSysInit(); target_init(); #if 0 #ifdef LPC214x // init DBG ConsoleInit(60000000 / (16 * UART_BAUD_RATE)); #else // init DBG ConsoleInit(72000000 / (16 * UART_BAUD_RATE)); #endif #endif // init DBG uart0_init(UART_BAUD_RATE,8,'N',1); printf("Initialising USB stack\n\r"); // initialise stack USBInit(); // register descriptors USBRegisterDescriptors(abDescriptors); // register class request handler DEPARTMENT OF ECE 82 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData); // register endpoint handlers USBHwRegisterEPIntHandler(INT_IN_EP, NULL); USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn); USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut); // register frame handler USBHwRegisterFrameHandler(USBFrameHandler); // register device event handler USBHwRegisterDevIntHandler(USBDevIntHandler); // initialise VCOM VCOM_init(); #ifdef LPC214x (*(&VICVectCntl0+INT_VECT_NUM)) = 0x20 | 22; // choose highest priority ISR slot (*(&VICVectAddr0+INT_VECT_NUM)) = (int)USBIntHandler; #else VICVectCntl22 = 0x01; VICVectAddr22 = (int)USBIntHandler; #endif // set up USB interrupt VICIntSelect &= ~(1<<22); // select IRQ for USB VICIntEnable |= (1<<22); enableIRQ(); // connect to bus USBHwConnect(TRUE); VCOM_putstring("Starting USB Communication",26); #if 0 // echo any character received (do USB stuff in interrupt) while (1) { vcp_ch = VCOM_getchar(); if (vcp_ch != EOF) { // show on console if ((vcp_ch == 9) || (vcp_ch == 10) || (vcp_ch == 13) || ((vcp_ch >= 32) && (vcp_ch <= 126))) { printf("%c", vcp_ch); } else { printf("."); } VCOM_putstring("We got a character = ",21); VCOM_putchar(ch); DEPARTMENT OF ECE 83 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL VCOM_putstring("\r\n",2); } } #else while(1) { // Receive a character from VCP [ Virtual COM Port ] vcp_ch = VCOM_getchar(); // show on console if( (vcp_ch == 8) || (vcp_ch == 13) || ( (vcp_ch >= 32) && (vcp_ch < 127) && (vcp_ch != EOF ) ) ) { switch(vcp_ch) { case 8: // Back space vcp_buff.tx.data_ptr--; break; case '\r': // Carriage Return -> send the data to device // Is there any data in buffer if(vcp_buff.tx.data_ptr == 0) { VCOM_putchar('\n'); break; // No sense in sending data } // Adding a '\n' and null terminating the string if(vcp_buff.tx.data[vcp_buff.tx.data_ptr - 1] != '$' && vcp_buff.tx.data[vcp_buff.tx.data_ptr - 1] != '+') { vcp_buff.tx.data[vcp_buff.tx.data_ptr++] = vcp_ch; } vcp_buff.tx.data[vcp_buff.tx.data_ptr] = 0; // Sending the data to UART0 VCOM_putstring("\r\nSending command:[",19); VCOM_putstring(vcp_buff.tx.data,vcp_buff.tx.data_ptr); VCOM_putstring("]\r\n",3); uart0_send((vcp_buff.tx.data),vcp_buff.tx.data_ptr,false); // Null terminate the data because it has been used vcp_buff.tx.data_ptr = 0; vcp_buff.tx.data[vcp_buff.tx.data_ptr] = 0; break; default: vcp_buff.tx.data[vcp_buff.tx.data_ptr++] = vcp_ch; break; } VCOM_putchar(vcp_ch); } // Now lets listen to what UART has say to us DEPARTMENT OF ECE 84 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL // We will fill the received data into vcp_buff.rx for(i=0;i<6500;i++); // Intercharacter delay on UART typically 1 ms if(uart0_getc(&uart_ch,1000) == false) { continue; // Nothing available on UART now } if((uart_ch == 8) || (uart_ch == 13) || ((uart_ch >= 32) && (uart_ch < 127))) { switch(uart_ch) { case 8: // Backspace vcp_buff.rx.data_ptr--; break; case '\n': // new Line vcp_buff.rx.data[vcp_buff.rx.data_ptr++] = uart_ch; vcp_buff.rx.data[vcp_buff.rx.data_ptr++] = '\r'; vcp_buff.rx.data[vcp_buff.rx.data_ptr] = 0; VCOM_putstring("\n\rGot response=[",16); VCOM_putstring(vcp_buff.rx.data,vcp_buff.rx.data_ptr); VCOM_putstring("]\r\n",3); // Clearing the buffers vcp_buff.rx.data_ptr = 0; vcp_buff.rx.data[vcp_buff.rx.data_ptr] = 0; break; case '\r': // Carriage return vcp_buff.rx.data[vcp_buff.rx.data_ptr++] = uart_ch; vcp_buff.rx.data[vcp_buff.rx.data_ptr++] = '\n'; vcp_buff.rx.data[vcp_buff.rx.data_ptr] = 0; VCOM_putstring("\n\rGot response=[",16); VCOM_putstring(vcp_buff.rx.data,vcp_buff.rx.data_ptr); VCOM_putstring("]\r\n",3); // Clearing the buffers vcp_buff.rx.data_ptr = 0; vcp_buff.rx.data[vcp_buff.rx.data_ptr] = 0; break; default: vcp_buff.rx.data[vcp_buff.rx.data_ptr++] = uart_ch; break; } } } #endif return 0; } /** End of file. */
// //
// //
DEPARTMENT OF ECE
85
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
B) BLUETOOTH
#include <string.h> // memcpy #include "type.h" #include "target.h" #include "usbdebug.h" #define LPC214x #ifdef LPC214x #include "lpc214x.h" #endif #ifdef LPC23xx #include "lpc23xx.h" #endif #include "armVIC.h" #include "uart.h" #include "usbapi.h" #include "serial_fifo.h" #define MODE_ZIGBEE #if defined(MODE_BLUETOOTH) #define UART_BAUD_RATE 115200 #elif defined(MODE_ZIGBEE) || defined(MODE_WIFI) #define UART_BAUD_RATE 9600 #endif #define INT_IN_EP 0x81 #define BULK_OUT_EP 0x05 #define BULK_IN_EP 0x82 #define MAX_PACKET_SIZE 64 #define LE_WORD(x) ((x)&0xFF),((x)>>8) // CDC definitions #define CS_INTERFACE 0x24 #define CS_ENDPOINT 0x25 #define SET_LINE_CODING 0x20 #define GET_LINE_CODING 0x21 #define SET_CONTROL_LINE_STATE 0x22 #define INT_VECT_NUM 0 #define IRQ_MASK 0x00000080 // data structure for GET_LINE_CODING / SET_LINE_CODING class requests typedef struct { U32 dwDTERate; U8 bCharFormat; U8 bParityType; U8 bDataBits; } TLineCoding; static TLineCoding LineCoding = {115200, 0, 0, 8}; static U8 abBulkBuf[64];
DEPARTMENT OF ECE
86
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL static U8 abClassReqData[8]; static volatile BOOL fBulkInBusy; static volatile BOOL fChainDone; static U8 txdata[VCOM_FIFO_SIZE]; static U8 rxdata[VCOM_FIFO_SIZE]; static fifo_t txfifo; static fifo_t rxfifo; // forward declaration of interrupt handler static void USBIntHandler(void) __attribute__ ((interrupt("IRQ"))); static const U8 abDescriptors[] = { // device descriptor 0x12, DESC_DEVICE, LE_WORD(0x0101), // bcdUSB 0x02, // bDeviceClass 0x00, // bDeviceSubClass 0x00, // bDeviceProtocol MAX_PACKET_SIZE0, // bMaxPacketSize LE_WORD(0xFFFF), // idVendor LE_WORD(0x0005), // idProduct LE_WORD(0x0100), // bcdDevice 0x01, // iManufacturer 0x02, // iProduct 0x03, // iSerialNumber 0x01, // bNumConfigurations // configuration descriptor 0x09, DESC_CONFIGURATION, LE_WORD(67), // wTotalLength 0x02, // bNumInterfaces 0x01, // bConfigurationValue 0x00, // iConfiguration 0xC0, // bmAttributes 0x32, // bMaxPower // control class interface 0x09, DESC_INTERFACE, 0x00, // bInterfaceNumber 0x00, // bAlternateSetting 0x01, // bNumEndPoints 0x02, // bInterfaceClass 0x02, // bInterfaceSubClass 0x01, // bInterfaceProtocol, linux requires value of 1 for the cdc_acm module 0x00, // iInterface // header functional descriptor DEPARTMENT OF ECE 87 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL 0x05, CS_INTERFACE, 0x00, LE_WORD(0x0110), // call management functional descriptor 0x05, CS_INTERFACE, 0x01, 0x01, // bmCapabilities = device handles call management 0x01, // bDataInterface // ACM functional descriptor 0x04, CS_INTERFACE, 0x02, 0x02, // bmCapabilities // union functional descriptor 0x05, CS_INTERFACE, 0x06, 0x00, // bMasterInterface 0x01, // bSlaveInterface0 // notification EP 0x07, DESC_ENDPOINT, INT_IN_EP, // bEndpointAddress 0x03, // bmAttributes = intr LE_WORD(8), // wMaxPacketSize 0x0A, // bInterval // data class interface descriptor 0x09, DESC_INTERFACE, 0x01, // bInterfaceNumber 0x00, // bAlternateSetting 0x02, // bNumEndPoints 0x0A, // bInterfaceClass = data 0x00, // bInterfaceSubClass 0x00, // bInterfaceProtocol 0x00, // iInterface // data EP OUT 0x07, DESC_ENDPOINT, BULK_OUT_EP, // bEndpointAddress 0x02, // bmAttributes = bulk LE_WORD(MAX_PACKET_SIZE), // wMaxPacketSize 0x00, // bInterval DEPARTMENT OF ECE 88 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL // data EP in 0x07, DESC_ENDPOINT, BULK_IN_EP, // bEndpointAddress 0x02, // bmAttributes = bulk LE_WORD(MAX_PACKET_SIZE), // wMaxPacketSize 0x00, // bInterval // string descriptors 0x04, DESC_STRING, LE_WORD(0x0409), 0x0E, DESC_STRING, 'L', 0, 'P', 0, 'C', 0, 'U', 0, 'S', 0, 'B', 0, 0x14, DESC_STRING, 'U', 0, 'S', 0, 'B', 0, 'S', 0, 'e', 0, 'r', 0, 'i', 0, 'a', 0, 'l', 0, 0x12, DESC_STRING, 'D', 0, 'E', 0, 'A', 0, 'D', 0, 'C', 0, '0', 0, 'D', 0, 'E', 0, // terminating zero 0 }; /** Local function to handle incoming bulk data @param [in] bEP @param [in] bEPStatus */ static void BulkOut(U8 bEP, U8 bEPStatus) { int i, iLen; if (fifo_free(&rxfifo) < MAX_PACKET_SIZE) { // may not fit into fifo return; } // get data from USB into intermediate buffer iLen = USBHwEPRead(bEP, abBulkBuf, sizeof(abBulkBuf)); for (i = 0; i < iLen; i++) { // put into FIFO if (!fifo_put(&rxfifo, abBulkBuf[i])) { // overflow... :( ASSERT(FALSE); break; DEPARTMENT OF ECE 89 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
} /**
Sends the next packet in chain of packets to the host @param [in] bEP @param [in] bEPStatus */ static void SendNextBulkIn(U8 bEP, BOOL fFirstPacket) { int iLen; // this transfer is done fBulkInBusy = FALSE; // first packet? if (fFirstPacket) { fChainDone = FALSE; } // last packet? if (fChainDone) { return; } // get up to MAX_PACKET_SIZE bytes from transmit FIFO into intermediate buffer for (iLen = 0; iLen < MAX_PACKET_SIZE; iLen++) { if (!fifo_get(&txfifo, &abBulkBuf[iLen])) { break; } } // send over USB USBHwEPWrite(bEP, abBulkBuf, iLen); fBulkInBusy = TRUE; // was this a short packet? if (iLen < MAX_PACKET_SIZE) { fChainDone = TRUE; } } /** Local function to handle outgoing bulk data @param [in] bEP @param [in] bEPStatus */ static void BulkIn(U8 bEP, U8 bEPStatus) { SendNextBulkIn(bEP, FALSE); } /**
DEPARTMENT OF ECE
90
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL Local function to handle the USB-CDC class requests @param [in] pSetup @param [out] piLen @param [out] ppbData */ static BOOL HandleClassRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData) { switch (pSetup->bRequest) { // set line coding case SET_LINE_CODING: DBG("SET_LINE_CODING\n"); memcpy((U8 *)&LineCoding, *ppbData, 7); *piLen = 7; DBG("dwDTERate=%u, bCharFormat=%u, bParityType=%u, bDataBits=%u\n", LineCoding.dwDTERate, LineCoding.bCharFormat, LineCoding.bParityType, LineCoding.bDataBits); break; // get line coding case GET_LINE_CODING: DBG("GET_LINE_CODING\n"); *ppbData = (U8 *)&LineCoding; *piLen = 7; break; // set control line state case SET_CONTROL_LINE_STATE: // bit0 = DTR, bit = RTS DBG("SET_CONTROL_LINE_STATE %X\n", pSetup->wValue); break; default: return FALSE; } return TRUE; } /** Initialises the VCOM port. Call this function before using VCOM_putchar or VCOM_getchar */ void VCOM_init(void) { fifo_init(&txfifo, txdata); fifo_init(&rxfifo, rxdata); fBulkInBusy = FALSE; fChainDone = TRUE; DEPARTMENT OF ECE 91 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL } /** Writes one character to VCOM port @param [in] c character to write @returns character written, or EOF if character could not be written */ int VCOM_putchar(int c) { return fifo_put(&txfifo, c) ? c : EOF; } void VCOM_putstring(const char *string,int len) { int i; for(i=0;i<len;i++) { VCOM_putchar((int)string[i]); } } /** Reads one character from VCOM port @returns character read, or EOF if character could not be read */ int VCOM_getchar(void) { U8 c; return fifo_get(&rxfifo, &c) ? c : EOF; } /** Interrupt handler Simply calls the USB ISR, then signals end of interrupt to VIC */ static void USBIntHandler(void) { USBHwISR(); VICVectAddr = 0x00; // dummy write to VIC to signal end of ISR } /** USB frame interrupt handler Called every milisecond by the hardware driver. This function is responsible for sending the first of a chain of packets to the host. A chain is always terminated by a short packet, either a packet shorter than the maximum packet size or a zero-length packet (as required by the windows usbser.sys driver). */ static void USBFrameHandler(U16 wFrame) { DEPARTMENT OF ECE 92 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL if (!fBulkInBusy && (fifo_avail(&txfifo) != 0)) { // send first packet SendNextBulkIn(BULK_IN_EP, TRUE); }} /** USB device status handler Resets state machine when a USB reset is received. */ static void USBDevIntHandler(U8 bDevStatus) { if ((bDevStatus & DEV_STATUS_RESET) != 0) { fBulkInBusy = FALSE; }} #define MAX_DATA_LENGTH 256 typedef struct { unsigned char data[MAX_DATA_LENGTH]; unsigned int data_ptr; }data_fifo_t; typedef struct { data_fifo_t rx; data_fifo_t tx; }uart_buffer_t; uart_buffer_t vcp_buff; / *********************************************************************** ** main ==== *********************************************************************** ***/ int main(void) { int vcp_ch,uart_ch,i; // PLL and MAM //HalSysInit(); target_init(); #if 0 #ifdef LPC214x // init DBG ConsoleInit(60000000 / (16 * UART_BAUD_RATE)); #else // init DBG ConsoleInit(72000000 / (16 * UART_BAUD_RATE)); #endif #endif DEPARTMENT OF ECE 93 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL // init DBG uart0_init(UART_BAUD_RATE,8,'N',1); printf("Initialising USB stack\n\r"); // initialise stack USBInit(); // register descriptors USBRegisterDescriptors(abDescriptors); // register class request handler USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData); // register endpoint handlers USBHwRegisterEPIntHandler(INT_IN_EP, NULL); USBHwRegisterEPIntHandler(BULK_IN_EP, BulkIn); USBHwRegisterEPIntHandler(BULK_OUT_EP, BulkOut); // register frame handler USBHwRegisterFrameHandler(USBFrameHandler); // register device event handler USBHwRegisterDevIntHandler(USBDevIntHandler); // initialise VCOM VCOM_init(); #ifdef LPC214x (*(&VICVectCntl0+INT_VECT_NUM)) = 0x20 | 22; // choose highest priority ISR slot (*(&VICVectAddr0+INT_VECT_NUM)) = (int)USBIntHandler; #else VICVectCntl22 = 0x01; VICVectAddr22 = (int)USBIntHandler; #endif // set up USB interrupt VICIntSelect &= ~(1<<22); // select IRQ for USB VICIntEnable |= (1<<22); enableIRQ(); // connect to bus USBHwConnect(TRUE); VCOM_putstring("Starting USB Communication",26); #if 0 // echo any character received (do USB stuff in interrupt) while (1) { vcp_ch = VCOM_getchar(); if (vcp_ch != EOF) { // show on console if ((vcp_ch == 9) || (vcp_ch == 10) || (vcp_ch == 13) || ((vcp_ch >= 32) && (vcp_ch <= 126))) DEPARTMENT OF ECE 94 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL { printf("%c", vcp_ch); } else { printf("."); } VCOM_putstring("We got a character = ",21); VCOM_putchar(ch); VCOM_putstring("\r\n",2); } } #else while(1) { // Receive a character from VCP [ Virtual COM Port ] vcp_ch = VCOM_getchar(); // show on console if( (vcp_ch == 8) || (vcp_ch == 13) || ( (vcp_ch >= 32) && (vcp_ch < 127) && (vcp_ch != EOF ) ) ) { switch(vcp_ch) { case 8: // Back space vcp_buff.tx.data_ptr--; break; case '\r': // Carriage Return -> send the data to device // Is there any data in buffer if(vcp_buff.tx.data_ptr == 0) { VCOM_putchar('\n'); break; // No sense in sending data } // Adding a '\n' and null terminating the string if(vcp_buff.tx.data[vcp_buff.tx.data_ptr - 1] != '$' && vcp_buff.tx.data[vcp_buff.tx.data_ptr - 1] != '+') { vcp_buff.tx.data[vcp_buff.tx.data_ptr++] = vcp_ch; } vcp_buff.tx.data[vcp_buff.tx.data_ptr] = 0; // Sending the data to UART0 VCOM_putstring("\r\nSending command:[",19); VCOM_putstring(vcp_buff.tx.data,vcp_buff.tx.data_ptr); VCOM_putstring("]\r\n",3); uart0_send((vcp_buff.tx.data),vcp_buff.tx.data_ptr,false); // Null terminate the data because it has been used DEPARTMENT OF ECE 95 baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL vcp_buff.tx.data_ptr = 0; vcp_buff.tx.data[vcp_buff.tx.data_ptr] = 0; break; default: vcp_buff.tx.data[vcp_buff.tx.data_ptr++] = vcp_ch; break; } VCOM_putchar(vcp_ch); } // Now lets listen to what UART has say to us // We will fill the received data into vcp_buff.rx for(i=0;i<6500;i++); // Intercharacter delay on UART typically 1 ms if(uart0_getc(&uart_ch,1000) == false) { continue; // Nothing available on UART now } if((uart_ch == 8) || (uart_ch == 13) || ((uart_ch >= 32) && (uart_ch < 127))) { switch(uart_ch) { case 8: // Backspace vcp_buff.rx.data_ptr--; break; case '\n': // new Line vcp_buff.rx.data[vcp_buff.rx.data_ptr++] = uart_ch; vcp_buff.rx.data[vcp_buff.rx.data_ptr++] = '\r'; vcp_buff.rx.data[vcp_buff.rx.data_ptr] = 0; VCOM_putstring("\n\rGot response=[",16); VCOM_putstring(vcp_buff.rx.data,vcp_buff.rx.data_ptr); VCOM_putstring("]\r\n",3); // Clearing the buffers vcp_buff.rx.data_ptr = 0; vcp_buff.rx.data[vcp_buff.rx.data_ptr] = 0; break; case '\r': // Carriage return vcp_buff.rx.data[vcp_buff.rx.data_ptr++] = uart_ch; vcp_buff.rx.data[vcp_buff.rx.data_ptr++] = '\n'; vcp_buff.rx.data[vcp_buff.rx.data_ptr] = 0; VCOM_putstring("\n\rGot response=[",16); VCOM_putstring(vcp_buff.rx.data,vcp_buff.rx.data_ptr); VCOM_putstring("]\r\n",3); // Clearing the buffers vcp_buff.rx.data_ptr = 0; vcp_buff.rx.data[vcp_buff.rx.data_ptr] = 0; DEPARTMENT OF ECE 96 baskarmtech@gmail.com
// //
// //
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE
EMBEDDED SYSTEM LAB MANUAL break; default: vcp_buff.rx.data[vcp_buff.rx.data_ptr++] = uart_ch; break; } } } #endif return 0; } /** End of file. */
C) RF MODULE
/*********************************************************************** * nordic_rf24l01p_LPC2148_main.c *********************************************************************** */ #include "./system/core.h" #include "./spi/spi.h" #include "./tools/print.h" #include "./tools/delays.h" #include "./time/time.h" #include "./time/timer.h" #include "./time/rtc.h" #include "./uart/uart.h" #include "./led/led.h" #include "./tools/debug.h" #include "./nordic/nrf24l01.h" #define NRF24l01_MODE_TX #define NRF24l01_MODE_RX 0 1
char txData[] = "Oasis Technologies Pvt Ltd."; unsigned int txUserData; unsigned int txUserDataCounter; unsigned int txDataCounter; unsigned char data; unsigned int counter; void nrf24l01_hardware_init(void); void hardware_init(void); int main(void) { //TODO: You can write your code at here
DEPARTMENT OF ECE
97
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE hardware_init(); printf("Hardware Init complete...\n\r"); nrf24l01_hardware_init(); printf("Nordic Init complete...\n\r"); int i=0; unsigned char regData[35]; // #if 1 while(1) { nrf24l01_get_all_registers(®Data[0]); for(i=0;i<35;i++) { printf("nrf24L01+[%d] = [0x%x]\n\r",i,regData[i]); delay_ms(10); } delay_sec(10); } #endif #if (NRF24l01_MODE_TX) printf("Nordic in Tx Mode...\n\r"); while(1) { #if 0 txDataCounter=0; while(txDataCounter<sizeof(txData)) { data = (unsigned char)txData[txDataCounter]; nrf24l01_write_tx_payload(&data, 1, true); //transmit received char over RF //wait until the packet has been sent or the maximum number of retries has been reached while(!(nrf24l01_irq_pin_active())); if(nrf24l01_irq_tx_ds_active()) { nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01 printf("."); txDataCounter++; } else if(nrf24l01_irq_max_rt_active()) { nrf24l01_flush_tx(); nrf24l01_flush_rx(); nrf24l01_irq_clear_all(); printf("X"); }
DEPARTMENT OF ECE
98
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE } #else printf("Type characters to send: "); while(1) { if(uart0_getc(&txUserData,1000)!=true) { delay_ms(10); continue; } nrf24l01_write_tx_payload((unsigned char *)&txUserData, 1, true); //transmit received char over RF while(!(nrf24l01_irq_pin_active())); if(nrf24l01_irq_tx_ds_active()) { nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01 printf("."); txUserDataCounter++; } else if(nrf24l01_irq_max_rt_active()) { nrf24l01_flush_tx(); nrf24l01_flush_rx(); nrf24l01_irq_clear_all(); printf("X"); } uart0_putc(txUserData); } #endif printf("\n\rTransmitted data [%d]\n\r",counter++); delay_sec(1); } #elif (NRF24l01_MODE_RX) printf("Nordic in RX mode ...\n\r"); unsigned char status; while(1) { while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active())); status = nrf24l01_read_rx_payload(&data,1); // Read the packet into data if(status == 64) { printf("%c",data); if(data == '.') { printf("\r\n Read Byte:"); } }
DEPARTMENT OF ECE
99
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE delay_ms(100); } #endif while(1); } return 0;
void nrf24l01_hardware_init() { // Configure SPI pins on PINSEL // Configure CSN(P0.20) CE(P0.21) and IRQ(PO.15) pin as fast GPIO as output only // IODIR0 |= (( 1 << 20 ) | ( 1 << 21 )); // Setting up CSN and CE // IODIR0 &= (~( 1 << 15 ) ); // Setting up IRQ
// Configure CSN(P1.17) CE(P1.16) and IRQ(P1.18) pin as fast GPIO as output only // IODIR1 |= (( 1 << 17 ) | ( 1 << 18 )); // Setting up CSN and CE // IODIR1 &= (~( 1 << 19 ) ); // Setting up IRQ
// Configure pin as fast GPIO as output only from nrf24l01.h IODIR1 |= ( nrf24l01_CE_PINMASK | nrf24l01_CSN_PINMASK ); // Setting up CSN and CE up IRQ IODIR1 &= (~ nrf24l01_IRQ_PINMASK ); spi0_open(); //open SPI1 // initialize the 24L01 to the debug configuration as TX, // 1 data byte, and auto-ack disabled delay_sec(2); // while(1) { nrf24l01_clear_ce(); nrf24l01_set_ce(); nrf24l01_clear_csn(); nrf24l01_set_csn(); // // // // // // if( nrf24l01_IRQ_IOREGISTER & nrf24l01_IRQ_PINMASK ) { printf("+"); } else { // Setting
DEPARTMENT OF ECE
100
baskarmtech@gmail.com
PONNAIYAH RAMAJAYAM COLLEGE OF ENGG & TECH VALLAM, THANJAVUR 613403 DEPARTMENT OF ECE // // printf("-");
void hardware_init() { target_init(); irq_vic_init(); uart0_init(115200,8,'N',1); timer_init(SYSTEM_TIMER,Fpclk/1000 -1 ); timer_enable(SYSTEM_TIMER); #ifdef __WRITE_START_RTC__ time.seconds = 0; time.minutes = 22; time.hours = 12; time.day_of_month = 21; time.day_of_week = 3; time.day_of_year = 233; time.month = 7; time.year = 2010; rtc_init(); rtc_set_time(&time); #else rtc_init(); #endif // // // // // } initLED(); while(1) { circleLED(); }
DEPARTMENT OF ECE
101
baskarmtech@gmail.com