Documente Academic
Documente Profesional
Documente Cultură
User Manual
Vi Microsystems Pvt. Ltd.
1
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
The VSK STM4 syllabus board is a demonstration and development platform for the
STM32F4 series and includes an embedded STM32F407VG high-performance ARM
Cortex-M4 32-bit microcontroller. The full range of hardware features on the board is
2
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
provided to help you evaluate all peripherals (Ethernet, motor control, CAN, USART
etc.) and develop your own applications. Extension headers make it possible to easily
connect a daughterboard or wrapping board for your specific application
2. VLEDD 02
The VLEDD 02 boards is having 12 LEDs. The LEDs are controlled by two transistors.
The operating voltage can be varied as per the industrial requirement. The possible
voltages are 3.3V, 5V and 12V. The operational voltage can be selected depending on the
hardware design.
The LED sequence D1, D2, D3, D7, D8 and D9 are controlled by the transistor Q1 and
the sequence D4, D5, D6, D10, D11 and D12 are controlled by the transistor Q2.
3
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
The board is also having an LDR. The LEDs can be used to lighten the zone with this
output of the LDR.
3. Vi -XBB
The Xbee board is a Wireless board that has to be interfaced with the controller. It can be
interfaced with a PC or another controller via RS232 cable.
4
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
The IDE is the framework where all necessary tools are seamlessly integrated:
The highly optimizing IAR C/C++ Compiler
The IAR Assembler
The versatile IAR ILINK Linker, including accompanying tools
A powerful editor
A project manager
A command line build utility
The IAR C-SPY Debugger, a state-of-the-art high-level language
debugger.
5
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
FEATURES
PROJECT MANAGEMNET
The IDE comes with functions that will help you to stay in control of all project
modules, for example, C or C++ source code files, assembler files, include files, and
other related modules. You create workspaces and let them contain one or several
projects. Files can be grouped, and options can be set on all levelsproject, group, or
file. Changes are tracked so that a request for rebuild will retranslate all required
modules, making sure that no executable files contain out-of-date modules. This list
shows some additional features:
Project templates to create a project that can be built and executed out of the box
for a smooth development startup
Hierarchical project representation
Source browser with an hierarchical symbol presentation
Options can be set globally, on groups of source files, or on individual source files
The Make command automatically detects changes and performs only the required
operations.
Text-based project files
Custom Build utility to expand the standard tool chain in an easy way
Command lines build with the project file as input.
6
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
FLASH MAGIC
Flash Magic provides a clear and simple user interface to these features and more
as described in the following sections. Under Windows, only one application may have
access the COM Port at any one time, preventing other applications from using the COM
Port. Flash Magic only obtains access to the selected COM Port when ISP operations are
being performed. This means that other applications that need to use the COM Port, such
as debugging tools, may be used while Flash Magic is loaded.
Win X talk
Win X talk software is windows software that allows send and receives the data
from serial port. COM port configuration is variable.
7
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
advantage of the ARM- specific facilities. The compiler is integrated with other IAR
Systems software in the IDE.
FEATURES
CODE GENERATION
LANGUAGE FACILITIES
IAR Assembler
The IAR Assembler is integrated with other IAR Systems software for the ARM
core. It is a powerful relocating macro assembler (supporting the Intel/Motorola style)
with a versatile set of directives and expression operators. The assembler features a built-
in C language preprocessor and supports conditional assembly. The assembler uses the
same mnemonics and operand syntax as the Advanced RISC Machines Ltd Assembler for
ARM, which simplifies the migration of existing code.
FEATURES
C preprocessor
List file with extensive cross-reference output
Number of symbols and program size limited only by available memory
Support for complex expressions with external references
255 significant characters in symbol names
Support for ARM EABI ELF/DWARF object format.
10
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
1. To create a new project, choose Project>Create New Project. The Create New
Project
Dialog box appears, which lets you base your new project on a project template.
11
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
2. Make sure the Tool chain is set to ARM, and click OK.
3. Select the project template Empty project, and click ok button. This simply
creates an empty project that uses default project setting.
4. In the standard Save As dialog box that appears, specify where you want to
place your project file, that is, in your newly created projects directory. Type
your project name in the File name box, and click Save to create the new
project. E.g. LED.
12
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
To Creating your Application C file, Choose FILE menu and select NEW>File
Edit the application code in C Language. E.g. Led_1.c. To Save your C file, Choose
File>Save As. In the standard Save As dialog box that appears, specify where you want
to place your project file, that is, in your project directory. Type your filename in the File
name box, and click Save to create the new project. E.g. Led_1.c
13
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
1. In the Workspace window, select the destination to which you want to add a
source file; a group or, as in this case, directly to the project.
2. Choose Project>Add Files to open a standard browse dialog box. Locate the files
LED_1.c
Select them in the file selection list, and click Open to add them to the project.
14
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
15
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
To save your work space, Choose File>Save Workspace and specify where you
want to place your workspace file. In this tutorial, you should place it in your newly
created project directory. Type LED in the File name box, and click save button.
Now you will set the project options. For application projects, options can be set
on all levels of nodes. First you will set the general options to suit the processor
16
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
configuration in this tutorial. Because these options must be the same for the whole build
configuration, they must be set on the project node.
1. Select the project folder icon LED_OUT - Debug in the Workspace window and
choose Project>Options. Then select General Options to select your Controller.
17
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
ST STM32F407 STM32F407ZG.
18
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
3. The Output options are used for specifying details about the output format and the
level of debugging information included in the output file. Select output format as
Intel Extended, output file in the format of .hex format.
4. Select the linker file menu, linker configuration file available at project directory.
To Compile your Project, Choose Project>Rebuild ALL
19
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
5. Now click ok. Now your project is configured for your specified controller (i.e.)
STM32F407ZG.
20
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Then right click on your project file and click add add files.
21
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
22
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
2. Define USE_STDPERIPH_DRIVER:
USE_STDPERIPH_DRIVER
23
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
24
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
25
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
26
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
2. If your project has no error, then it will show Building successfully and the
Hex file will be generated.
27
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
28
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
3. Select the COM port and set the baud rate as 115200
29
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
5. Click next and Select the target as STM32F4_1024K and Click next.
30
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
6. Click next and browse your hex file in your project folder location project_folder
\debug \exe.
31
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
7. Click Next
32
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
8. After downloading your program change the board to execution mode and reset it.
33
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Syllabus Programs in C
Instruction:
Follow the given steps for getting started with the syllabus experiments:
1. Install IAR Embedded Workbench IDE software and Win X-Talk software.
2. After successful installation of IAR and Win X- Talk, Install Flash Magic.
3. Connect the RS232 cable/USB cable provided to the PC and the STM32 Syllabus
Board, and Power on the Development Board.
4. If you are using USB cable, then install the required USB to Serial driver (FTDI for
on beard converter).
5. Search/Set the COM Port no here :
Start >> My Computer >> Manage (on right click) >> Device Manager >>
Ports (COM & LPT).
6. Now, Identify the Mode-Select-Switch(SW9) provided on the Vi-STM32 Board
marked with the text +3.3V & GND.
+3.3V: Programming Mode used for downloading the code/program into the
flash memory.
GND: Execution Mode used for executing program after downloading.
34
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
After selecting any position (+3.3V / GND) press the reset switch provided on the
board.
7. After setting the proper COM port number & selecting the Mode-Select-Switch
position properly, Extract the Vi STM32 SB SOURCE CODES V 1.0
(WinRAR archive) file.
8. Open the project and follow the instructions given in each experiment.
35
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Experiment 1
Aim
To learn about the evolution, core features, general characteristics and applications of
ARM processors.
Theory
The VSK STM4 syllabus board is a demonstration and development platform for the
STM32F4 series and includes an embedded STM32F407VG high-performance ARM
Cortex-M4 32-bit microcontroller. The full range of hardware features on the board is
provided to help you evaluate all peripherals (Ethernet, motor control, CAN, USART
etc.) and develop your own applications. Extension headers make it possible to easily
connect a daughterboard or wrapping board for your specific application.
Features
Core: ARM 32-bit Cortex-M4 CPU with FPU, Adaptive real-time accelerator
(ART Accelerator) allowing 0-wait state execution from Flash memory,
frequency up to 168 MHz, memory protection unit, 210 DMIPS/ 1.25
DMIPS/MHz (Dhrystone 2.1), and DSP instructions
Memories
Up to 1 Mbyte of Flash memory
Up to 192+4 Kbytes of SRAM including 64- Kbyte of CCM (core coupled
memory) data RAM
36
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
37
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
ARCHITECTURAL OVERVIEW
In STM32F405xx/07xx and STM32F415xx/17xx, the main system consists of 32-bit
multilayer AHB bus matrix that interconnects: The main system consists of 32-bit
multilayer AHB bus matrix that interconnects:
38
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Eight masters:
Cortex -M4 with FPU core I-bus, D-bus and S-bus
DMA1 memory bus
DMA2 memory bus
DMA2 peripheral bus
Ethernet DMA bus
USB OTG HS DMA bus
Seven slaves:
Internal Flash memory ICode bus
Internal Flash memory DCode bus
Main internal SRAM1 (112 KB)
Auxiliary internal SRAM2 (16 KB)
AHB1 peripherals including AHB to APB bridges and APB peripherals
AHB2 peripherals
FSMC
The bus matrix provides access from a master to a slave, enabling concurrent access and
efficient operation even when several high-speed peripherals work simultaneously. The
64- Kbyte CCM (core coupled memory) data RAM is not part of the bus matrix and can
be accessed only through the CPU.
39
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
BLOCK DIAGRAM
40
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Result
The evolution, core features, general characteristics and the applications of ARM
processors has been studied and is evaluated.
41
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Experiment 2
Aim
4. CRO
Theory
ADC
Three 12-bit analog-to-digital converters are embedded and each ADC shares up to 16
external channels, performing conversions in the single-shot or scan mode. In scan mode,
automatic conversion is performed on a selected group of analog inputs.
Additional logic functions embedded in the ADC interface allow:
Simultaneous sample and hold
Interleaved sample and hold
42
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Procedure
43
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Program
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_adc.h"
void adc_configure()
/* Clock configuration */
RCC->APB2ENR |= 1<<10; /*The ADC3 is connected the APB2 peripheral bus thus we
will use its clock source */
RCC->AHB1ENR |= 1<<0; /* Clock for the ADC port!! Do not forget about this one ;) */
GPIOA->OSPEEDR = 0xFFFFFFFF;
GPIOA->PUPDR = 0x00000000;
/* ADC configuration */
44
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
int adc_convert()
void USART2_config()
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
45
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
int main(void)
USART2_config();
while(1)
{}
return data;
46
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
47
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
DAC
The two 12-bit buffered DAC channels can be used to convert two digital signals into
two analog voltage signal outputs.
This dual digital Interface supports the following features:
two DAC converters: one for each output channel
8-bit or 12-bit monotonic output
left or right data alignment in 12-bit mode
synchronized update capability
noise-wave generation
triangular-wave generation
dual DAC channel independent or simultaneous conversions
DMA capability for each channel
external triggers for conversion
input voltage reference VREF+
Eight DAC trigger inputs are used in the device. The DAC channels are triggered through
the timer update outputs that are also connected to different DMA streams.
Procedure
48
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
PROGRAM
#include "stm32f4xx.h"
#include "stm32f4xx_dac.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_syscfg.h"
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 0xFF;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
49
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);
TIM_Cmd(TIM6, ENABLE);
DAC_InitTypeDef DAC_InitStructure;
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Triangle;
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_1023;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
DAC_Cmd(DAC_Channel_1, ENABLE);
DAC_SetChannel2Data(DAC_Align_12b_R, 0x100);
int main(void)
GPIO_InitTypeDef GPIO_InitStructure;
50
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
TIM6_Config();
while (1)
DAC_Ch2_TriangleConfig();
51
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
52
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Experiment 3
Aim
To write a C program to generate a PWM and to vary the brightness of the LED
depending on the duty cycle.
4. CRO
Theory
The PWM is based on the standard timer block and inherits all of its features,. The timer
is designed to count cycles of the peripheral clock (PCLK) and optionally generate
interrupts or perform other actions when specified timer values occur, based on seven
match registers. The PWM function is also based on match register events
53
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary
file, compile and build the program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.
54
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Program
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include <stdio.h>
uint16_t PrescalerValue = 0;
int duty;
void TIM10_Config(void);
void TIM11_Config(void);
void TIM3_Config(void);
int switch_read();
void mx_pinout_config(void);
void USART2_config();
int main(void)
USART2_config();
TIM3_Config();
while(1)
55
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
TIM3->PSC =PrescalerValue;
TIM3->CR1 = 0<<8|0<<9;
TIM3->CCMR1 = 1<<4|1<<5|1<<6;
TIM3->CCMR1 = 1<<12|1<<13|1<<14;
56
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
TIM3->CR1 =1<<0;
void TIM3_Config(void)
RCC->APB1ENR |=1<<1;
RCC->AHB1ENR |=1<<2;
GPIOC->MODER |=0x0000A000;
GPIOC->AFR[0]|=0x22000000;
int switch_read()
int val;
mx_pinout_config();
val = ((GPIOE->IDR)&0x14);
if(val == 0x04)
if(duty_cycle <= 0)
duty_cycle =1;
57
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
delay(250);
delay(250);
duty =1500;
return(duty_cycle);
{}
return data;
58
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
void mx_pinout_config(void)
GPIOE->MODER |=0x00000000; /*set portE as i/p mode, other pins are input mode */
GPIOE->OTYPER =0x00000000;
GPIOE->PUPDR = 0x00000000;
GPIOE->OSPEEDR =0xAAAAAAAA;
void USART2_config()
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
59
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
int d1,d2;
for(d1=0;d1<delay;d1++)
for(d2=0;d2<delay;d2++);
60
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Result
The C program to vary the intensity of the LED depending on the duty cycle of the
PWM has been developed and is verified.
61
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Experiment 4
Aim
To develop a C-Language program for reading the RTC, convert into decimal and to
display it.
Theory
RTC
62
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Two alarm registers are used to generate an alarm at a specific time and calendar fields
can be independently masked for alarm comparison. To generate a periodic interrupt, a
16-bit programmable binary auto-reload down counter with programmable resolution is
available and allows automatic wakeup and periodic alarms from every 120 s to every
36 hours
Serial Communication
Serial communication takes a byte of data and transmits the 8 bits in the byte one at a
time. The advantage is that a serial port needs only one wire to transmit the 8 bits (while
a parallel port needs 8). The disadvantage is that it takes 8 times longer to transmit the
data than it would if there were 8 wires. Serial ports lower cable costs and make cables
smaller.
63
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Procedure
64
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Program
#include "stm32f4xx.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
#include "misc.h"
#include "stdio.h"
/* prototype functions */
void init_I2C1();
void USART2_config();
65
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
int main(void)
USART2_config();
init_I2C1();
int gk_sec,gk_min,gk_hrr;
I2C_stop(I2C1);
Delay(500);
while(1)
66
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
void Delay(int t)
int y,u;
for(y=0;y<t;y++)
for(u=0;u<t;u++);
int r_value,gj;
Delay(200);
I2C_stop(I2Cx);
Delay(200);
Delay(200);
67
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
gj = I2C_ReceiveData(I2Cx);
r_value = BCD_to_DECIMAL(gj);
I2C_stop(I2Cx);
Delay(3700);
return(r_value);
int gk_MSB,gk_LSB,decimal;
gk_MSB = (bcd&0xF0)>>4;
gk_LSB = (bcd&0x0F);
decimal =(gk_MSB*10)+gk_LSB;
return(decimal);
void USART2_config()
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1 <<17;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
68
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
{}
return data;
void init_I2C1()
I2C_InitTypeDef I2C_InitStruct;
* pairs of pins:
*/
69
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
GPIOB->AFR[0] = 0x04000000;
GPIOB->AFR[1] = 0x00000040;
/* configure I2C1 */
I2C_InitStruct.I2C_Ack = I2C_Ack_Disable;
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
/* enable I2C1 */
I2C_Cmd(I2C1, ENABLE);
70
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));
I2C_GenerateSTART(I2Cx, ENABLE);
/* wait for I2C1 EV5 --> Slave has acknowledged start condition */
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
* direction
*/
if(direction == I2C_Direction_Transmitter)
while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
71
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
I2C_SendData(I2Cx, data);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_AcknowledgeConfig(I2Cx, ENABLE);
// read data from I2C data register and return data byte
return data;
72
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
I2C_AcknowledgeConfig(I2Cx, DISABLE);
I2C_GenerateSTOP(I2Cx, ENABLE);
// read data from I2C data register and return data byte
return data;
I2C_GenerateSTOP(I2Cx, ENABLE);
73
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Result
The C-Language program for reading RTC and displaying it in PC was written &
output is verified with running the RTC from a default/specified time.
74
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Experiment 5
Aim
To develop a C-Language program for displaying the Key pressed in the Keypad in the
LCD module. The display should come in the desired line and column.
Apparatus & Software Required
Theory
Keypad
The Matrix keyboard is used to minimize the number of I/O lines. Normally it is possible
to connect only one key or switch with an I/O line. If the number of keys in the system
exceeds the more I/O lines are required. To reduce the number of I/O lines the keys are
connected in the matrix circuit. Keyboards use a matrix with the rows and columns made
up of wires. Each key acts like a switch. When a key is pressed a column wire makes
contact with row wire and completes a circuit.
For example 16 keys arranged in a matrix circuit uses only 8 I/O lines
75
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
LCD
Liquid crystals are a phase of matter whose order is intermediate between that of a liquid
and that of a crystal. The molecules are typically rod-shaped organic matters about 25
Angstroms in length and their ordering is a function of temperature. The molecular
orientation can be controlled with applied electric fields.
A standard character LCD is probably the most widely used data Visualization
component.
Character LCDs are available in various kinds of models.
1. No. Of characters x Lines: 8x1, 16x1, 16x2, 16x4, 20x4, 40x4
2. Color: Yellow, Green, Gray, Blue
The Character LCD communicates with the microcontroller via 8 bit data bus. The pin
description for character LCD is given below.
76
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
VCC, GND AND V0 - While VCC and VSS provide +5V and ground, respectively; V0
is used for controlling LCD contrast.
RS (Register Select) - If RS = 0, the instruction command code register is selected,
allowing the user to send a command such as clear display, cursor at home, etc.
If RS = 1, the data register is selected, allowing the user to send data to be displayed on
the LCD.
RW (Read/Write) - RW allows the user to write information to the LCD or read
information from it. RW=1 when reading; RW=0 when writing.
EN (Enable) - The LCD to latch information presented to its data pins uses the enable
pin. When data is supplied to data pins, a high to low pulse must be applied to this pin in
order for the LCD to latch in the data present at the data pins.
D0 D7 - The 8-bit data pins, are used to send information to the LCD or read the
contents of the LCDs internal registers. To display letters and numbers, we send ASCII
codes for the letters A-Z, a-z, and numbers 0-9 to these pins while making RS = 1
77
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Procedure
78
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Program
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
unsigned char i;
/*ptototype functions */
void mx_pinout_config(void);
void busy_check();
void lcd_init();
void mx_pinout_config(void);
void Row1_check();
void Row2_check();
void Row3_check();
void Row4_check();
int val;
79
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
void main(void)
mx_pinout_config();
command_write(0x80);
lcd_stringout(d1);
command_write(0xC0);
lcd_stringout(d2);
while (1)
Row1_check();
Row2_check();
Row3_check();
Row4_check();
void Row1_check()
/*1 st row */
80
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
command_write(0x01);
command_write(0x80);
delay(100);
command_write(0x01);
command_write(0x80);
delay(100);
command_write(0x01);
command_write(0x80);
delay(100);
81
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
command_write(0x01);
command_write(0x80);
delay(100);
void Row2_check()
/*2nd row */
command_write(0x01);
command_write(0x80);
delay(100);
82
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
command_write(0x01);
command_write(0x80);
delay(100);
command_write(0x01);
command_write(0x80);
delay(100);
command_write(0x01);
command_write(0x80);
delay(100);
83
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
void Row3_check()
/*3rd row */
command_write(0x01);
command_write(0x80);
delay(100);
command_write(0x01);
command_write(0x80);
delay(100);
84
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
command_write(0x01);
command_write(0x80);
delay(100);
command_write(0x01);
command_write(0x80);
delay(100);
void Row4_check()
/*4th row*/
85
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
command_write(0x01);
command_write(0x80);
delay(100);
command_write(0x01);
command_write(0x80);
delay(100);
command_write(0x01);
command_write(0x80);
delay(100);
command_write(0x01);
86
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
command_write(0x80);
delay(100);
void delay(int a)
int i,j;
for(i=0;i<a;i++)
for(j=0;j<a;j++);
void busy_check()
delay(200);
busy_check();
87
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
delay(200);
void lcd_init()
command_write(0x38);
command_write(0x01);
command_write(0x0f);
command_write(0xC0);
command_write(0x06);
busy_check();
GPIOE->ODR = (a<<8)|(1<<5); /*write the data from 8th bit.(i.E) PG8 to PG15*/
delay(200);
88
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
int i;
busy_check();
for(i=0;gk[i] !='\0';i++)
GPIOE->ODR =( gk[i]<<8)|(1<<5); /*write the data from 8th bit.(i.E) PG8 to PG15 */
delay(200);
void mx_pinout_config(void)
/* GPIO_InitTypeDef GPIO_InitStruct; */
GPIOD->MODER |=0x00000055; /* set port D0-D3 as o/p mode, other pins are input mode */
GPIOD->OTYPER =0x00000000;
GPIOD->PUPDR = 0x00000000;
GPIOD->OSPEEDR =0xAAAAAAAA;
89
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
/*Enable pin */
GPIOE->OTYPER = 0x00000000;
GPIOE->PUPDR = 0x00000000;
GPIOE->OSPEEDR = 0xAAAAAAAA;
GPIOE->ODR = 0x00000000;
90
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Result
The C-Language program for displaying the Key pressed in the Keyboard is displayed in
the LCD module and the output was verified on the LCD on the desires line and
column/address.
91
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Experiment 6
Aim
To develop a C-Language program to write and read a data in EEPROM and also to
analyze its performance with the interrupt
Theory
92
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Procedure
93
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Program
#include "stm32f4xx.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
#include "misc.h"
#include "stdio.h"
/* prototype functions */
void init_I2C1();
void USART2_config();
94
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
int main(void)
USART2_config();
init_I2C1();
int i,gk;
for(i=0;i<64;i++)
gk = I2C_read(I2C1,0x00,i);
void Delay(int t)
int y,u;
for(y=0;y<t;y++)
for(u=0;u<t;u++);
95
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
void USART2_config()
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1 <<17;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
{}
return data;
96
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
void init_I2C1()
GPIO_InitTypeDef GPIO_InitStruct;
I2C_InitTypeDef I2C_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
* pairs of pins:
*/
97
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
/* configure I2C1 */
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
/* enable I2C1 */
I2C_Cmd(I2C1, ENABLE);
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));
I2C_GenerateSTART(I2Cx, ENABLE);
/* wait for I2C1 EV5 --> Slave has acknowledged start condition */
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
98
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
* direction
*/
if(direction == I2C_Direction_Transmitter)
while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
I2C_SendData(I2Cx, data);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
99
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
I2C_AcknowledgeConfig(I2Cx, ENABLE);
/* read data from I2C data register and return data byte */
return data;
I2C_AcknowledgeConfig(I2Cx, DISABLE);
I2C_GenerateSTOP(I2Cx, ENABLE);
/* read data from I2C data register and return data byte */
return data;
100
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
I2C_GenerateSTOP(I2Cx, ENABLE);
int j;
Delay(200);
I2C_write(I2C1,MSB_addr);
I2C_write(I2C1,LSB_addr);
I2C_stop(I2C1);
Delay(200);
Delay(200);
j = I2C_ReceiveData(I2C1);
//printf("\n %d",j);
I2C_stop(I2C1);
Delay(200);
return(j);
101
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
#include "stm32f4xx.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
#include "misc.h"
#include "stdio.h"
/* prototype functions */
void init_I2C1();
void USART2_config();
102
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
int main(void)
USART2_config();
init_I2C1();
int i;
I2C_write(I2C1,i);
Delay(200);
Delay(2000);
void Delay(int t)
int y,u;
for(y=0;y<t;y++)
for(u=0;u<t;u++);
103
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
void USART2_config()
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1 <<17;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
{}
return data;
104
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
void init_I2C1()
GPIO_InitTypeDef GPIO_InitStruct;
I2C_InitTypeDef I2C_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
* pairs of pins:
*/
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
/* set output to open drain --> the line has to be only pulled low, not driven high */
105
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
/* configure I2C1 */
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
/* enable I2C1 */
I2C_Cmd(I2C1, ENABLE);
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));
I2C_GenerateSTART(I2Cx, ENABLE);
106
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
/* wait for I2C1 EV5 --> Slave has acknowledged start condition */
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
* direction
*/
if(direction == I2C_Direction_Transmitter)
while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
107
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
I2C_SendData(I2Cx, data);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_AcknowledgeConfig(I2Cx, ENABLE);
/* read data from I2C data register and return data byte */
return data;
I2C_GenerateSTOP(I2Cx, ENABLE);
108
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
int j;
Delay(200);
I2C_write(I2C1,MSB_addr);
I2C_write(I2C1,LSB_addr);
I2C_stop(I2C1);
Delay(200);
Delay(200);
j = I2C_ReceiveData(I2C1);
//printf("\n %d",j);
I2C_stop(I2C1);
Delay(200);
return(j);
109
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Result
The C-Language program to write and read a data in EEPROM and also to analyze its
performance with the interrupt is developed and is verified.
110
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Experiment 7
Mailbox
Aim
Theory
111
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
In providing this "abstraction layer" the RTOS kernel supplies five main categories of
basic services to application software
The most basic category of kernel services is Task Management. This set of services
allows application software developers to design their software as a number of separate
"chunks" of software -- each handling a distinct topic, a distinct goal, and perhaps its own
real-time deadline. Each separate "chunk" of software is called a "task." The main RTOS
service in this category is the scheduling of tasks as the embedded system is in operation.
Since many embedded systems have stringent timing requirements, most RTOS kernels
also provide some basic Timer services, such as task delays and time-outs.
Many (but not all) RTOS kernels provide Dynamic Memory Allocation services. This
category of services allows tasks to "borrow" chunks of RAM memory for temporary use
in application software. Often these chunks of memory are then passed from task to task,
as a means of quickly communicating large amounts of data between tasks. Some very
small RTOS kernels that are intended for tightly memory-limited environments, do not
offer Dynamic memory allocation.
Many (but not all) RTOS kernels also provide a "Device I/O Supervisor" category of
services. These services, if available, provide a uniform framework for organizing and
accessing the many hardware device drivers that are typical of an embedded system.
112
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Procedure
113
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Program
#include "ucos_ii.h"
#include "bsp.h"
OS_STK AppStk_send[TASK_STK_SIZE];
OS_STK AppStk_recv[TASK_STK_SIZE];
OS_EVENT *pmailbox;
int main(void)
.{
BSP_IntDisAll();
RCC_ClocksTypeDef rcc_clocks;
RCC_GetClocksFreq(&rcc_clocks);
SysTick_Config(rcc_clocks.HCLK_Frequency/OS_TICKS_PER_SEC);
114
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
OSStatInit(); /*DetermineCPUcapacity.*/
OSTaskCreate(Mailbox_App_Tx,NULL,(OS_STK *)&AppStk_send[TASK_STK_SIZE-
1],(INT8U)10); /*sending task */
OSTaskCreate(Mailbox_App_Rx,NULL,(OS_STK *)&AppStk_recv[TASK_STK_SIZE-
1],(INT8U)30); /*receiving task */
return 0;
buffer[0] = "1.RCC";
buffer[1] = "2.DMA";
buffer[2] = "3.NVIC";
buffer[3] = "4.FPU";
//buffer[4] = "5.FSMC";
p_arg = p_arg;
pmailbox=OSMboxCreate(NULL);
115
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
for (i=0;i<=5;)
if((err=OSMboxPost(pmailbox,buffer[i]))==NO_ERROR_GK) /* if success */
i++;
OSTimeDlyHMSM(0, 0, 5, 0);
OSTimeDlyHMSM(0, 0, 5, 0);
INT8U err;
INT16U timeout=100;
116
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
INT8U *buffer;
p_arg = p_arg;
for (;;)
buffer=OSMboxPend(pmailbox,timeout,&err);
OSTimeDly(200);
printf("\n\rTimeout");
break;
else
break;
OSTimeDlyHMSM(0,0,6, 0);
117
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Result
The C-Language program to create a mailbox and to understand the about the RTOS
functions is developed and is verified.
118
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Experiment 8
Aim
To study about the Interrupt performance characteristics between ARM and FPGA
6. ModelSim SE
7. JTAG 5.5
8. CRO
Procedure in ARM
119
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Program in ARM
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_gpio.h"
#include "misc.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_exti.h"
#include "stm32f4xx_syscfg.h"
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
uint16_t PrescalerValue = 0;
uint16_t capture = 0;
120
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
void TIM_Config(void);
void delay(int a)
int t1,t2;
for(t1=0;t1<a;t1++)
for(t2=0;t2<a;t2++);
void usart2_init()
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1 <<17;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
USART2->BRR = 0x16D;
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
121
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
int main(void)
/* TIM Configuration */
TIM_Config();
usart2_init();
EXTILine2_Config();
EXTILine4_Config();
while (1);
{}
return data;
122
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC->AHB1ENR |= 0x00000010;
RCC->APB2ENR |= 0x00004000;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_Init(GPIOE, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource2);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
123
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/**
* @param None
* @retval None
*/
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC->AHB1ENR |= 0x00000010;
RCC->APB2ENR |= 0x00004000;
124
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_Init(GPIOE, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource4);
EXTI_InitStructure.EXTI_Line = EXTI_Line4;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
125
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
/**
* @param None
* @retval None
*/
void TIM_Config(void)
NVIC_InitTypeDef NVIC_InitStructure;
RCC->APB1ENR |= 0x00000002;
RCC->APB1ENR |= 0x00000004;
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0x00;
126
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC->AHB1ENR |= 1<<3;
GPIOD->MODER = 0x00550000;
GPIOD->OTYPER = 0x00000000;
GPIOD->OSPEEDR = 0xAAAAAAAA;
GPIOD->PUPDR = 0x00000000;
TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
127
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
/* Prescaler configuration */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);
TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* Prescaler configuration */
128
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR2_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Disable);
TIM_ITConfig(TIM3, TIM_IT_CC1,ENABLE);
TIM_ITConfig(TIM4, TIM_IT_CC1,ENABLE);
TIM_Cmd(TIM4, ENABLE);
TIM_Cmd(TIM3, ENABLE);
void EXTI2_IRQHandler(void)
if(EXTI_GetITStatus(EXTI_Line2) != RESET)
/* Toggle LED1 */
GPIOD->ODR = 0x00000200;
129
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
delay(1000);
EXTI_ClearITPendingBit(EXTI_Line2);
void EXTI4_IRQHandler(void)
if(EXTI_GetITStatus(EXTI_Line4) != RESET)
GPIOD->ODR = 0x00000400;
/* Toggle LED2 */
delay(1000);
EXTI_ClearITPendingBit(EXTI_Line4);
void TIM3_IRQHandler(void)
TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);
130
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
GPIOD->ODR = 0x00000100;
capture = TIM_GetCapture1(TIM3);
delay(1000);
void TIM4_IRQHandler(void)
TIM_ClearITPendingBit(TIM4, TIM_IT_CC1);
GPIOD->ODR = 0x00000800;
capture = TIM_GetCapture1(TIM4);
delay(0000);
131
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Step 1: Create a New project in Xilinx ISE Project Navigator from File
Button.
Step 3: Check/ modify the properties for the FPGA hardware and click
Next.
Step 4: Click Finish for the Summary window.(Now the new project
window has been displayed in the ISE Project Navigator.)
Step 5: Right click on the Xilinx FPGA hardware in the Hierarchy window
pane and select add New Source.
Step 6: Select VHDL Module and enter the file name before clicking
Next.
Step 7: Define the port details of the VHDL module and click Next.
Step 9: Now copy and paste the below program in the module.
(Follow the same procedure from Step 5 to Step 8 for adding the
VHDL modules for the below program.)
Step 10: Right click on the Xilinx FPGA hardware in the Hierarchy window
pane and select add New Source.
Step 11: Select Implementation Constraint File and enter the file name
before clicking Next.
132
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Step 12: Copy and Paste the Implementation Constraint File module in the
appropriate module.
Step 13: Click Generate Programming File in the Processes pane for the
entire project.(Now the .bit file has been generated for the project)
Step 14: Before continuing with the further process please Connect the
FPGA hardware kit with the CPU by using serial cable and Switch
ON.
Step 15: Now Open the JTAG 5.5 software from Start menu in your
computer and initialize the FPGA device for dumping the program
into it.
Step 16: While initializing please Assign the .bit file and Program
your FPGA by in the JTAG 5.5 application.
(Now the coded instructions have been loaded in the FPGA hardware kit.
133
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Program (FPGA)
Top module
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-- DECLARATION OF THE PORT DETAILS IN TOP MODULE SECTION
ENTITY TOP_MODULE IS
PORT ( CLK : IN STD_LOGIC;
GEN_CLK1 : OUT STD_LOGIC;
GEN_CLK2 : OUT STD_LOGIC;
GEN_CLK3 : OUT STD_LOGIC;
INPUT1 : IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT2 : IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT3 : IN STD_LOGIC; ---- SQUARE SIGNAL
RISING_INTERRUPT : OUT STD_LOGIC;
RISING_INTERRUPT1: OUT STD_LOGIC;
RISING_INTERRUPT2: OUT STD_LOGIC
);
END TOP_MODULE;
134
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
BEGIN
--DECLARING THE SIGNAL DETAILS OF THE COMPONENTS FOR PORT MAPPING --
CLK_SECTION :CLK_GEN PORT MAP
(CLK,GEN_CLK1,GEN_CLK2,GEN_CLK3);
INTERRUPT_SECTION :INTERRUPT PORT MAP
(CLK,INPUT1,INPUT2,INPUT3,RISING_INTERRUPT,RISING_INTERRUPT1,RISING
_INTERRUPT2);
END BEHAVIORAL;
CLK_GEN
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-- DECLARATION OF PORT DETAILS --
ENTITY CLK_GEN IS
PORT ( CLK : IN STD_LOGIC;
GEN_CLK1 : OUT STD_LOGIC;
GEN_CLK2 : OUT STD_LOGIC;
GEN_CLK3 : OUT STD_LOGIC);
END CLK_GEN;
ARCHITECTURE BEHAVIORAL OF CLK_GEN IS
135
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Interrupt
-------------------------------------------------------------------------
-- LIBRARY PART --
-------------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-------------------------------------------------------------------------
-- PORT DECLARATION PART --
-------------------------------------------------------------------------
ENTITY INTERRUPT IS
PORT ( CLK : IN STD_LOGIC ; -- INPUT
CLOCK
INPUT1 : IN STD_LOGIC; -- SQUARE
SIGNAL
INPUT2 : IN STD_LOGIC; -- SQUARE
SIGNAL
INPUT3 : IN STD_LOGIC; -- SQUARE
SIGNAL
RISING_INTERRUPT : OUT STD_LOGIC; -- INTERRUPT OUTPUT
1
RISING_INTERRUPT1 : OUT STD_LOGIC; -- INTERRUPT OUTPUT
2
RISING_INTERRUPT2 : OUT STD_LOGIC -- INTERRUPT OUTPUT
3
);
END INTERRUPT ;
-------------------------------------------------------------------------
--DESIGN ARCHITECTURE BEGIN'S --
-------------------------------------------------------------------------
136
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
--------------------------------------------------------------------------
-- FIRST INTERRUT DESIGN --
--------------------------------------------------------------------------
137
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Y<='1';
END IF;
WHEN '1'=>
IF INPUT2='0' THEN --ROUTINE WILL CONTINUE IF INPUT 1 IN
'0' CONDITION
Y<='0'; -- VALUE OF X
TENDS TO '0'
END IF;
138
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
END CASE;
END PROCESS;
END BEHAVIORAL;
139
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
By connecting the probes of CRO/MSO/DSO to the Desired Input and Output pins of the
I/O connectors we will acquire the result of the Interrupt performance of FPGA device.
Step 1: Run the Simulation process of the Project by selecting Simulation in the
View pane and select the Simulator (ModelSim) in the Processes pane.
Step 2: Force clock input to the CLK variable by right clicking the variable
Step 3: Now you can observe the Input and output result in the Simulator.
140
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Experiment 9
Flashing of LEDS
Aim
To develop a C program to make the LED blink (including delay routine). Upon change
in the delay program the speed should vary.
Theory
LEDs are based on the semiconductor diode. When the diode is forward biased (switched
on), electrons are able to recombine with holes and energy is released in the form of light.
This effect is called electroluminescence and the color of the light is determined by the
energy gap of the semiconductor
141
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Procedure
142
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Program
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_rcc.h"
void LED_init();
/* delay function */
for(b=0;b<a;b++)
for(c=0;c<a;c++);
void main()
while(1)
delay(3000); /* delay */
delay(3000); /* delay */
143
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
void LED_init()
144
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Result:
The C-Language program to make the LED blink was developed and output was
verified. Upon change in the delay program the speed variation was verified.
145
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Experiment 10
Aim
4. Stepper motor
Theory
Stepper Motor
Stepper motors, effectively have multiple "toothed" electromagnets arranged around a
central metal gear. To make the motor shaft turn, first one electromagnet is given power,
which makes the gear's teeth magnetically attracted to the electromagnet's teeth. When
the gear's teeth are thus aligned to the first electromagnet, they are slightly offset from the
next electromagnet.
So when the next electromagnet is turned on and the first will turn off, the gear rotates
slightly to align with the next one and from there the process is repeated. Each of those
slight rotations is called a "step." In that way, the motor can be turned to a precised angle.
There are two basic arrangements for the electromagnetic coils: bipolar and unipolar.
146
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Procedure
147
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Programs
#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
void anticlock_wise();
void clock_wise();
void delay()
for(int i=0;i<0xFF;i++)
for(int j=0;j<0xFF;j++);
void mx_pinout_config(void)
RCC->AHB1ENR |= 1<<1;
GPIOB->MODER = 0x55555555;
GPIOB->OTYPER =0x00000000;
GPIOB->PUPDR = 0x00000000;
GPIOB->OSPEEDR = 0xFFFFFFFF;
148
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
int main(void)
mx_pinout_config();
while (1)
anticlock_wise();
delay();
clock_wise();
delay();
void anticlock_wise()
for(i=0;i<52;i++)
GPIOB->ODR = 0xA000;
GPIOB->ODR = 0x6000;
GPIOB->ODR = 0x5000;
149
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
GPIOB->ODR = 0x9000;
void clock_wise()
for(i=0;i<52;i++)
GPIOB->ODR = 0x9000;
GPIOB->ODR = 0x5000;
GPIOB->ODR = 0x6000;
GPIOB->ODR = 0xA000;
150
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
151
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Temperature Sensor
The temperature sensor has to generate a voltage that varies linearly with temperature.
The conversion range is between 1.8 V and 3.6 V. The temperature sensor is internally
connected to the ADC1_IN16 input channel which is used to convert the sensor output
voltage into a digital value.
As the offset of the temperature sensor varies from chip to chip due to process variation,
the internal temperature sensor is mainly suitable for applications that detect temperature
changes instead of absolute temperatures. If an accurate temperature reading is needed,
then an external temperature sensor part should be used.
Procedure
152
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Program
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_adc.h"
#include "stm32f4xx_gpio.h"
void anticlock_wise();
void clock_wise();
void USART2_config();
void adc_configure();
int adc_convert();
uint32_t temp;
void delay()
for(int i=0;i<0xFF;i++)
for(int j=0;j<0xFF;j++);
153
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
void USART2_config()
RCC->AHB1ENR |= 0x01;
RCC->APB1ENR |= 0x20000;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
USART2->BRR = 0x16D;
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
void adc_configure()
//Clock configuration
RCC->AHB1ENR |= 1<<0; /*Clock for the ADC port!! Do not forget about this
one ;) */
154
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
GPIOA->MODER |=0x0000000F;
GPIOA->OSPEEDR = 0xFFFFFFFF;
GPIOA->PUPDR = 0x00000000;
/* ADC configuration */
int adc_convert()
155
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
{}
return data;
void motor_PIN_config(void)
RCC->AHB1ENR |= 1<<1;
GPIOB->MODER = 0x55555555;
GPIOB->OTYPER =0x00000000;
GPIOB->PUPDR = 0x00000000;
GPIOB->OSPEEDR = 0xFFFFFFFF;
void main(void)
motor_PIN_config();
USART2_config();
156
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
while(1)
temp =ConvertedValue;
gk =temp*3.3;
gk /=4095;
gk *=100;
anticlock_wise();
delay();
clock_wise();
delay();
157
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
void anticlock_wise()
for(i=0;i<52;i++)
GPIOB->ODR = 0xA000;
GPIOB->ODR = 0x6000;
GPIOB->ODR = 0x5000;
GPIOB->ODR = 0x9000;
void clock_wise()
for(i=0;i<52;i++)
GPIOB->ODR = 0x9000;
158
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
GPIOB->ODR = 0x5000;
GPIOB->ODR = 0x6000;
GPIOB->ODR = 0xA000;
159
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
160
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Experiment 11
Theory
The X Bee/X Bee-PRO ZNet 2.5 (formerly known as Series 2 and Series 2 PRO) RF
Modules were directed to operate within the ZigBee protocol. The modules provide
reliable delivery of data between remote devices. Zigbee is the communication protocol
like wifi and Bluetooth. Xbee is the module using Zigbee protocol
using local addressing, simple networks of more than 65,000 nodes can be
configured, with reduced address overhead
The radios use direct-sequence spread spectrum coding, which is managed by the
digital stream into the modulator.
161
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
162
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Aim
To transmit the data via Xbee and view the output data in the PC.
Procedure
163
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
Program
#include "stm32f4xx.h"
#include <stdio.h>
void USART2_config();
void delay(int j)
int g,k;
for(g=0;g<j;g++)
for(k=0;k<j;k++);
void main()
int i;
USART2_config();
while(1)
for(i=0;gk[i] != '\0';i++)
164
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
send_data(gk[i]);
send_data(0x0d);
send_data(0x0A);
void USART2_config()
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1 <<17;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
USART2->BRR = 0x1117;
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
165
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
{}
{}
return data;
166
EC6711 Embedded Systems Laboratory
User Manual
Vi Microsystems Pvt. Ltd.
167