Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Embedded Lab: Kgisl Institute of Technology Department of Electronics and Communication

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 111

2020

Embedded Lab

KGiSL Institute of Technology


Department Of Electronics and
Communication
Introduction

An embedded system combines mechanical, electrical, and chemical components along with a
computer, hidden inside, to perform a single dedicated purpose. There are more computers on
this planet than there are people, and most of these computers are single-chip microcontrollers
that are the brains of an embedded system. Embedded systems are a ubiquitous component of our
everyday lives. We interact with hundreds of tiny computers every day that are embedded into
our houses, our cars, our bridges, our toys, and our work. As our world has become more
complex, so have the capabilities of the microcontrollers embedded into our devices. Therefore
the world needs a trained workforce to develop and manage products based on embedded
microcontrollers.
Objectives
Lab Experiments: To complement and practically clarify the ideas presented in the Embedded
Systems course, a set of experiments have been devised that closely follow the plan laid down
for the course. Below is a listing of the main topics of the lab sessions:

1. Introduction to Lab and ARM Programming: Microchip ARM addressing modes,


internal registers and memory map. ARM instruction set and assembler directives,
mathematical and logical operations, comparisons, arrays, BCD arithmetic, conditional
statements, repetition techniques and look-up tables. Programming techniques and
methodologies, modularity concepts.
2. Introduction to Embedded Systems Hardware/Software Design and Basic
HMI: This part is concerned with introducing off-the-shelf components and ICs covering
regulators, resonators, 7-segments, LEDs, switches, push buttons, LCDs and keypads.
System requirement analysis and definition, program flow analysis and flowchart design,
system and subsystem design. Unit and system testing through simulation. An Industrial
filling machine as an example
3. Introduction to Embedded Systems Peripherals: Introducing the built-in 8 bit timers.
Intersystem communication "USART peripheral”; communicating with PC through hyper
terminal. A/D module, software and hardware Pulse Width Modulation (PWM), DC
motor. Optical speed sensor circuit.
4. Lab project: To make it possible for the students to grasp and practically implement the
ideas learned during the course and lab sessions, the students are required to design,
implement and then demonstrate a working embedded system project.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 2


KGiSL Institute of Technology - KiTE
Coimbatore – 641 035.
(Approved by AICTE & Affiliated to Anna University)

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 3


EC6711 EMBEDDED LABORATORY

LIST OF EXPERIMENTS

1. Study of ARM evaluation system


2. Interfacing ADC and DAC.
3. Interfacing LED and PWM.
4. Interfacing real time clock and serial port.
5. Interfacing keyboard and LCD.
6. Interfacing EPROM and interrupt.
7. Mailbox.
8. Interrupt performance characteristics of ARM and FPGA.
9. Flashing of LEDS.
10. Interfacing stepper motor and temperature sensor.
11. Implementing zigbee protocol with ARM.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 4


INDEX

S.No Description Page no

1. STUDY OF ARM EVALUATION SYSTEM 6-8

2. INTERFACING ADC AND DAC 9-17

3. INTERFACING LED AND PWM 18-23

4. INTERFACING REAL TIME CLOCK AND 24-33


SERIAL PORT
5. INTERFACING KEYBOARD AND LCD 34-44

6. INTERFACING EPROM AND INTERRUPT 45-57

7. MAILBOX 58-63

8. INTERRUPT PERFORMANCE 64-82


CHARACTERISTICS OF ARM AND FPGA
9. FLASHING OF LEDS 83-86

10. INTERFACING STEPPER MOTOR AND 87-95


TEMPERATURE SENSOR
11. IMPLEMENTING ZIGBEE PROTOCOL 96-111
WITH ARM

EX: No: 1 STUDY OF ARM EVALUATION SYSTEM

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 5


AIM
To study about the core features and general characteristics of ARM processor development
board.

THEORY
The VSK – STM4 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
 1 Mbyte of Flash memory
 192+4 Kbytes of SRAM including 64- Kbyte of CCM (core coupled memory) data RAM
 Flexible static memory controller supporting Compact Flash, SRAM, PSRAM, NOR and
NAND memories
 LCD parallel interface, 8080/6800 modes.
 Clock, reset and supply management.
 Low-power operation.
 3×12-bit, 2.4 MSPS A/D converters: up to 24 channels and 7.2 MSPS in triple
interleaved mode.
 2×12-bit D/A converters
 General-purpose DMA: 16-stream DMA controller with FIFOs and burst support.
 17 timers: up to twelve 16-bit and two 32- bit timers up to 168 MHz.
o 2×12-bit D/A converters
 Serial wire debug (SWD) & JTAG interfaces.
 140 I/O ports with interrupt capability.
 15 communication interfaces
 8- to 14-bit parallel camera interface up to 54 Mbytes/s.
 True random number generator.
 CRC calculation unit.
 96-bit unique ID.
 RTC: subsecond accuracy, hardware calendar.
 USB 2.0 full-speed device/host/OTG controller with on-chip PHY.

BLOCK DIAGRAM

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 6


ARCHITECTURAL OVERVIEW

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 7


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 eight masters and seven slaves.
Eight masters:
(i) Cortex -M4 with FPU core I-bus
(ii) Cortex -M4 with FPU core D-bus
(iii) Cortex -M4 with FPU core S-bus
(iv) DMA1 memory bus
(v) DMA2 memory bus
(vi) DMA2 peripheral bus
(vii) Ethernet DMA bus
(viii) USB OTG HS DMA bus
Seven slaves:
(i) Internal Flash memory ICode bus
(ii) Internal Flash memory DCode bus
(iii) Main internal SRAM1 (112 KB)
(iv) Auxiliary internal SRAM2 (16 KB)
(v) AHB1 peripherals including AHB to APB bridges and APB peripherals
(vi) AHB2 peripherals
(vii) 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.

RESULT
Thus the core features and general characteristics of ARM processor have been studied and are
evaluated.

EX: No: 2(i) INTERFACING ADC WITH ARM

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 8


AIM
To interface and convert analog signal in digital form using ADC in ARM processor.

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.

2. IAR IDE software.

3. Flash Loader Demonstrator. .

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

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 9


PROCEDURE
1. Double click IAR Embedded Workbench in the Desktop.
2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the ADC program, select new from file menu and save it with the name
( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
6. Change the mode of the program into downloading mode by using Flash loader
software.
7. To view the output, after downloading your program change the board to execution
mode and reset it.
8. The ADC values will be varying depending on the setting of the POTMETER 2.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 10


PROGRAM
#include “stm32f4xx.h”
#include<stdio.h>
#include “stm32f4xx_gpio.h”
#include “stm32f4xx_rcc.h”
int ConvertedValue =0; /*converted value read from ADC1 */
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 ;)*/
/*Analog pin configuration*/
GPIOA->MODER|0x0000000F; /* analog mode PA1,PA2 */
GPIOA->OSPEEDR = 0xFFFFFFFF;
GPIOA->PUPDR = 0x00000000;
/* ADC configuration */
ADC3->CR1 = 0x00000000; /* scan mode disable, 12-bit resolution. */
ADC3->CR2 = 0x00000002; /* data right alignment, continuous conversion mode. */
ADC3->SQR1 = 0x00000000; /* single mode conversion */
ADC3->CR2 |= 0x00000001; /* ADC enable */
ADC3->SMPR2 = 0x00000030; /*ADC3 channel-1 with 144 cycles */
ADC3->SQR3 = 0x00000001; /* rank1 to ADC3 channel-1 */
}
int adc_convert()
{
ADC_SoftwareStartConv(ADC3); /*Start the conversion*/
while(!ADC_GetFlagStatus(ADC3, ADC_FLAG_EOC)); /* Processing the conversion */
return ADC_GetConversionValue(ADC3); /*Return the converted data*/
}
void USART2_config()
{
RCC->AHB1ENR |= 1 <<0;
/*clockto portA */
RCC->APB1ENR |= 1 <<17;
/* clock to USART2 */
GPIOA->MODER |
=0x000000A0; GPIOA-
>AFR[0] |= 0x00007700;
USART2->BRR = 0x16D;
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;

}
Int main(void)

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 11


{
USART2_config();
adc_configure(); /*start
configuration*/
while(1)
{
ConvertedValue=adc_convert(
);
Printf(“\n ADC value =>
%d”,ConvertedValue”);
}
}
int putchar(int data)
{
USART2->DR=(data &
0x01FF);
/*Loop until the end of
transmission*/
while((USART2->SR &
0x40)==0)
{}
return data();
}

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 12


RESULT
Thus the Conversion of Analog to Digital is performed and verified with ARM
processor successfully.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 13


EX: No: 2(ii) INTERFACING DAC WITH ARM

AIM
To interface and convert Digital to Analog using DAC in ARM processor Development
Board.

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.

2. IAR IDE software.

3. Flash Loader Demonstrator.

4. Digital Storage Oscilloscope.

THEORY
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.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 14


PROCEDURE

1. Double click IAR Embedded Workbench in the Desktop.


2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the DAC program, select new from file menu and save it with the name
( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
6. Change the mode of the program into downloading mode by using Flash loader
software.
7. To view the output, after downloading your program change the board to execution
mode in cortex M4 development board and reset it.
8. Make use of a CRO or DSO to view the DAC output by connecting the +ve terminal to
pin 5 and the –ve terminal to GND.
9. The waveforms can be viewed in either the CRO or DSO.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 15


PROGRAM
#include "stm32f4xx.h"
#include "stm32f4xx_dac.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_syscfg.h"

static void TIM6_Config(void)


{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* TIM6 Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
/* Time base configuration */
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);
/* TIM6 TRGO selection */
TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);
/* TIM6 enable counter */
TIM_Cmd(TIM6, ENABLE);
}

static void DAC_Ch2_TriangleConfig(void)


{
DAC_InitTypeDef DAC_InitStructure;
/* DAC channel2 Configuration */
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);

/* Enable DAC Channel2 */


DAC_Cmd(DAC_Channel_1, ENABLE);

/* Set DAC channel2 DHR12RD register */


DAC_SetChannel2Data(DAC_Align_12b_R, 0x100);
}

int main(void)

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 16


{
GPIO_InitTypeDef GPIO_InitStructure;
/* DMA1 clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
/* GPIOA clock enable (to be used with DAC) */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* DAC Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
/* DAC channel 1 & 2 (DAC_OUT1 = PA.4)(DAC_OUT2 = PA.5) configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; //DAC pin A5 as analog mode//
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);

TIM6_Config ();

while (1)
{
DAC_Ch2_TriangleConfig();
}
}

RESULT
Thus the Conversion of Digital to Analog is performed and verified with ARM processor
successfully.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 17


EX: No: 3 INTERFACING LED AND PWM

AIM

To write a C program to generate a PWM and to vary the brightness of the LED
depending on the duty cycle.

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.


2. IAR IDE software.
3. Flash Loader Demonstrator.
4. CRO.
5. LED board Setup.

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.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 18


PROCEDURE

1. Double click IAR Embedded Workbench in the Desktop.


2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the program, select new from file menu and save it with the name
( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
6. Change the mode of the program into downloading mode by using Flash loader
software.
7. To view the output, after downloading your program change the board to execution
mode in cortex M4 development board and reset it.
8. Connect the positive terminal of the LED board to the connector and negative terminal
to GND.
9. On varying the duty cycle of the PWM, the intensity of the LEDs will vary.
10. To increase the duty cycle press SW2 and to decrease, press SW5.

PROGRAM
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include <stdio.h>
uint16_t PrescalerValue = 0;
static int duty_cycle =1 ;
int duty;

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 19


/* Private function prototypes -----------------------------------------------*/
void TIM10_Config(void);
void TIM11_Config(void);
void TIM3_Config(void);
void delay(int delay);
int switch_read();
void mx_pinout_config(void);
void USART2_config();

/* main functions ---------------------------------------------------------*/

int main(void)
{
USART2_config();
TIM3_Config();
while(1)
{
duty = switch_read(); //receive switch value
/* for debug purpose */
// printf("\n duty =%d",duty);

/* Compute the prescaler value */


PrescalerValue = (uint16_t) ((SystemCoreClock /2) / 21000000) - 1; //21MHZ timer/counter
clock
TIM3->ARR =0x348;//25khz
TIM3->PSC =PrescalerValue;
TIM3->CR1 = 0<<8|0<<9;
TIM3->CCMR1 = 1<<4|1<<5|1<<6;
TIM3->CCER |= 1<<0|1<<1; //enable capture/compare2
TIM3->CCR1 = duty; // apply duty cycle
TIM3->CCMR1 = 1<<3; //enable channel1 preload register
TIM3->CCMR1 = 1<<12|1<<13|1<<14;
TIM3->CCER |= 1<<4|1<<5; //enable capture/compare2
TIM3->CCR2 = duty; // apply duty cycle
TIM3->CCMR1 = 1<<11; //enable channel2 preload register
/* TIM10 enable counter */
TIM3->CR1 =1<<0;
}
}
void TIM3_Config(void)
{
RCC->APB1ENR |=1<<1;
RCC->AHB1ENR |=1<<2;
GPIOC->MODER |=0x0000A000;
GPIOC->AFR[0]|=0x22000000;

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 20


}
int switch_read()
{
int val;
mx_pinout_config();
val = ((GPIOE->IDR)&0x14);
if(val == 0x04)
{
if(duty_cycle <= 0)
{
duty_cycle =1;
}
duty_cycle--; //variable decrement
delay(250);
}
else if(val == 0x10)
{
duty_cycle++; //variable increment
delay(250);
if(duty >= 1500)
{
duty =1500;
}
}
return(duty_cycle);
}
int putchar(int data)
{
USART2->DR = (data & 0x01FF);
/* Loop until the end of transmission */
while((USART2->SR & 0x40) ==0)
{}
return data;
}
void mx_pinout_config(void)
{
/*Enable or disable the AHB1 peripheral clock */
RCC->AHB1ENR |= 1<<3; // enable the clock to portD
RCC->AHB1ENR |= 1<<4; //enable clock to portE
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()
{

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 21


RCC->AHB1ENR |= 1 << 0; //clock to PORTA
RCC->APB1ENR |= 1 <<17; //clock to USART2
GPIOA->MODER |= 0x000000A0; //AF mode
GPIOA->AFR[0] |= 0x00007700; //USART2 AF
USART2->BRR = 0x16D;//115200 baud rate
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
}
void delay(int delay)
{
int d1,d2;
for(d1=0;d1<delay;d1++)
for(d2=0;d2<delay;d2++);
}

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 22


RESULT
Thus the C program to vary the intensity of the LED depending on the duty cycle of the
PWM has been developed and is verified.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 23


EX: No: 4 INTERFACING REAL TIME CLOCK AND SERIAL PORT

AIM

To develop a C-Language program for reading the RTC, convert into decimal and to
display it.

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.


2. IAR IDE software.
3. Flash Loader Demonstrator.

THEORY

REAL TIME CLOCK (RTC)

The real-time clock (RTC) is an independent BCD timer/counter. Dedicated registers contain the
second, minute, hour (in 12/24 hour), week day, date, month, year, in BCD (binary coded
decimal) format. Correction for 28, 29 (leap year), 30, and 31 day of the month are performed
automatically. The RTC provides a programmable alarm and programmable periodic interrupts
with wakeup from Stop and Standby modes. The sub-seconds value is also available in binary
format.

It is clocked by a 32.768 kHz external crystal, resonator or oscillator, the internal low-power RC
oscillator or the high-speed external clock divided by 128. The internal low-speed RC has a
typical frequency of 32 kHz. The RTC can be calibrated using an external 512 Hz output to
compensate for any natural quartz deviation.

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.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 24


Fig (a): Real time Clock

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.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 25


Fig (b): Serial Port

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 26


PROCEDURE
1. Double click IAR Embedded Workbench in the Desktop.
2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the DAC program, select new from file menu and save it with the name
( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
6. Change the mode of the program into downloading mode by using Flash loader
software.
7. To view the output, after downloading your program change the board to execution
mode in cortex M4 development board and reset it.
8. The time will be executed in PC.
9. To change the time i.e. hours and minutes press the switches SW5 and SW2
respectively.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 27


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"

//uint8_t GK[64] = "ABCD";

#define SLAVE_ADDRESS1 0xD0 // the slave address for write


#define SLAVE_ADDRESS2 0xD1 // the slave address for read

/* prototype functions */
void I2C_stop(I2C_TypeDef* I2Cx);
void I2C_write(I2C_TypeDef* I2Cx, uint8_t data);
void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction);
void init_I2C1();
void Delay(int t);
void USART2_config();
int BCD_to_DECIMAL(int bcd);
int RTC_read(I2C_TypeDef* I2Cx,uint8_t address);

int main(void)
{

USART2_config();

printf("\n welcome to RTC");


init_I2C1();

int gk_sec,gk_min,gk_hrr;

I2C_start(I2C1, SLAVE_ADDRESS1, I2C_Direction_Transmitter); // start a


transmission in Master transmitter mode

I2C_write(I2C1,0x00); //send RTC second address

I2C_write(I2C1,0x00); //send RTC second data


I2C_write(I2C1,0x00); //send RTC min data
I2C_write(I2C1,0x08); //send RTC hour data
I2C_stop(I2C1);
Delay(500);
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 28
while(1)
{

gk_sec = RTC_read(I2C1,0x00); //read RTC second


gk_min = RTC_read(I2C1,0x01); //read RTC minute
gk_hrr = RTC_read(I2C1,0x02); //read RTC hour
printf("\n\t RTC_TIME => %d:%d:%d",gk_hrr,gk_min,gk_sec);
}
}

void Delay(int t)
{
int y,u;
for(y=0;y<t;y++)
for(u=0;u<t;u++);
}

int RTC_read(I2C_TypeDef* I2Cx,uint8_t address)


{
int r_value,gj;
I2C_start(I2Cx, SLAVE_ADDRESS1, I2C_Direction_Transmitter); // start a transmission in
Master transmitter mode

I2C_write(I2Cx,address); //send EEPROM MSB address


Delay(200);
I2C_stop(I2Cx);
Delay(200);
I2C_start(I2Cx, SLAVE_ADDRESS2, I2C_Direction_Receiver); // start a transmission in
Master transmitter mode
Delay(200);

gj = I2C_ReceiveData(I2Cx);
r_value = BCD_to_DECIMAL(gj);

I2C_stop(I2Cx);
Delay(3700);
return(r_value);
}
int BCD_to_DECIMAL(int bcd)
{
int gk_MSB,gk_LSB,decimal;
gk_MSB = (bcd&0xF0)>>4;
gk_LSB = (bcd&0x0F);
decimal =(gk_MSB*10)+gk_LSB;
return(decimal);
}
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 29
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1 <<17;

GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;

USART2->BRR = 0x16D;//115200 baud rate


USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;

int putchar(int data)


{
USART2->DR = (data & 0x01FF);
/* Loop until the end of transmission */
while((USART2->SR & 0x40) ==0)
{}
return data;
}
void init_I2C1()
{

I2C_InitTypeDef I2C_InitStruct;

/* setup SCL and SDA pins


* You can connect I2C1 to two different
* pairs of pins:
* 1. SCL on PB6 and SDA on PB9
*/

RCC->AHB1ENR |= 1<<1; //CLK to port B


RCC->APB1ENR |= 1<<21; // CLK to I2C1

GPIOB->MODER = 0x00082000; //PB6 & PB9 =>i2c pins (SDA,SCL)


GPIOB->AFR[0] = 0x04000000;
GPIOB->AFR[1] = 0x00000040;
GPIOB->OTYPER = 0xFFFFFFFF; //open drain
GPIOB->OSPEEDR =0xAAAAAAAA; //50 MHZ
GPIOB->PUPDR = 0x55555555; //pull up
// configure I2C1

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 30


I2C_InitStruct.I2C_ClockSpeed = 100000; // 100kHz
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; // I2C mode
I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2; // 50% duty cycle --> standard
I2C_InitStruct.I2C_OwnAddress1 = 0x00; // own address, not relevant in master
mode
I2C_InitStruct.I2C_Ack = I2C_Ack_Disable; // disable acknowledge when reading
(can be changed later on)
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; // set address
length to 7 bit addresses
I2C_Init(I2C1, &I2C_InitStruct); // init I2C1

// enable I2C1
I2C_Cmd(I2C1, ENABLE);
}

void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)


{

// wait until I2C1 is not busy anymore


while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));

// Send I2C1 START condition


I2C_GenerateSTART(I2Cx, ENABLE);

// wait for I2C1 EV5 --> Slave has acknowledged start condition
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));

// Send slave Address for write


I2C_Send7bitAddress(I2Cx, address, direction);

/* wait for I2C1 EV6, check if


* either Slave has acknowledged Master transmitter or
* Master receiver mode, depending on the transmission
* direction
*/
if(direction == I2C_Direction_Transmitter)
{

while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
}
else if(direction == I2C_Direction_Receiver)
{

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 31


while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
}
}

void I2C_write(I2C_TypeDef* I2Cx, uint8_t data)


{
I2C_SendData(I2Cx, data);
// wait for I2C1 EV8_2 --> byte has been transmitted
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
}

uint8_t I2C_read_ack(I2C_TypeDef* I2Cx)


{
// enable acknowledge of recieved data
I2C_AcknowledgeConfig(I2Cx, ENABLE);
// wait until one byte has been received
while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED) );
// read data from I2C data register and return data byte
uint8_t data = I2C_ReceiveData(I2Cx);
return data;
}

uint8_t I2C_read_nack(I2C_TypeDef* I2Cx)


{
// disabe acknowledge of received data
// nack also generates stop condition after last byte received
// see reference manual for more info
I2C_AcknowledgeConfig(I2Cx, DISABLE);
I2C_GenerateSTOP(I2Cx, ENABLE);
// wait until one byte has been received
while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED) );
// read data from I2C data register and return data byte
uint8_t data = I2C_ReceiveData(I2Cx);
return data;
}

void I2C_stop(I2C_TypeDef* I2Cx)


{
// Send I2C1 STOP Condition
I2C_GenerateSTOP(I2Cx, ENABLE);
}

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 32


RESULT

Thus 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.

EX: No: 5 INTERFACING KEYBOARD AND LCD

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 33


AIM

To develop a C-Language program for displaying the Key pressed in the Keypad in the LCD
module.

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.


2. IAR IDE software.
3. Flash Loader Demonstrator.

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

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 34


Fig (a): KeyBoard

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.

CHARACTER BASED LCD

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…

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 35


The Character LCD communicates with the microcontroller via 8 bit data bus. The pin
description for character LCD is given below.
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 LCD’s 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.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 36


Fig (b) LCD Display

PROCEDURE

1. Double click IAR Embedded Workbench in the Desktop.


2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the program, select new from file menu and save it with the name
( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
6. Change the mode of the program into downloading mode by using Flash loader
software.
7. To view the output, after downloading your program change the board to execution
mode in cortex M4 development board and reset it.
8. The switches SW2, SW3, SW5 and SW6 are interfaced as keypad.
9. Each switch is programmed to have a defined function. SW2 is to clear the display,
SW3 is to get the user data, SW5 and SW6 is to shift the cursor to the left and right
respectively.
10. 32 data’s can be typed up with these keys.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 37


PROGRAM
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
unsigned char d1[] = {" WELCOME "};
unsigned char d2[] = {" Press any Key"};
unsigned char i;

/*ptototype functions */
void delay(int a);
void mx_pinout_config(void);
void busy_check();
void command_write(int comm);
void lcd_init();
void lcd_out(unsigned char a);
void lcd_stringout(unsigned char *gk);
void mx_pinout_config(void);
void Row1_check();
void Row2_check();
void Row3_check();
void Row4_check();
int val;

void main(void)
{
mx_pinout_config();
lcd_init(); //send initial commands
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 */
GPIOD->BSRRH = 0x0001; //high PD0

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 38


GPIOD->BSRRL = 0x000E; //low PD1 to PD3
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>C");
delay(100);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>D");
delay(100);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>E");
delay(100);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>F");
delay(100);
}
}
void Row2_check()
{
/*2nd row */
GPIOD->BSRRH = 0x0002; //low PD0
GPIOD->BSRRL = 0x000D; //low PD0

val = (GPIOD->IDR)&0xF0; //status of D4 to D7


if(val == 0xE0) //1st column
{

command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>8");
delay(100);
}
else if(val== 0xD0) //2nd column
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 39
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>9");
delay(100);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>A");
delay(100);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>B");
delay(100);
}
// GPIOD->BSRRH = 0x000E; //low PD0
}

void Row3_check()
{
/*3rd row */
GPIOD->BSRRH = 0x0004; //low PD0
GPIOD->BSRRL = 0x000B; //low PD0

val = (GPIOD->IDR)&0xF0; //status of D4 to D7


if(val == 0xE0) //1st column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>4");
delay(100);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>5");
delay(100);
}
else if(val== 0xB0) //3rd column
{

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 40


command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>6");
delay(100);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>7");
delay(100);
}
}

void Row4_check()
{
/*4th row*/
GPIOD->BSRRH = 0x0008; //low PD0
GPIOD->BSRRL = 0x0007; //low PD0
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>0");
delay(100);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>1");
delay(100);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>2");
delay(100);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>3");

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 41


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);
GPIOE->BSRRH = 0x0020; //low the RS pin
GPIOE->BSRRH = 0x0040; //low RW pin

void command_write(int comm)


{
busy_check();
GPIOE->BSRRH = 0x0020; //low RS pin

GPIOE->ODR = (comm<<8)|(0<<5); //write the data from 8th bit.(i.E) PG8 to PG15
GPIOE->BSRRL = 0x0080; //enable pin high
delay(200);
GPIOE->BSRRH = 0x0080; //enable pin low
}

/*LCD initial commands */


void lcd_init()
{
command_write(0x38);
command_write(0x01);
command_write(0x0f);
command_write(0xC0);
command_write(0x06);
}

void lcd_out(unsigned char a)


{
busy_check();

GPIOE->BSRRL = 0x0020; //high RS pin


GPIOE->ODR = (a<<8)|(1<<5); //write the data from 8th bit.(i.E) PG8 to PG15
GPIOE->BSRRL = 0x0080;//enable pin high
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 42
delay(200);
GPIOE->BSRRH = 0x0080;//enable pin low
}
void lcd_stringout(unsigned char *gk)
{
int i;
busy_check();
GPIOE->BSRRL = 0x0020; //high RS pin
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
GPIOE->BSRRL = 0x0080;//enable pin high
delay(200);
GPIOE->BSRRH = 0x0080;//enable pin low
}
}

void mx_pinout_config(void)
{
// GPIO_InitTypeDef GPIO_InitStruct;
/*Enable or disable the AHB1 peripheral clock */
RCC->AHB1ENR |= 1<<3; // enable the clock to portF
RCC->AHB1ENR |= 1<<4; //enable clock to portB,C,G
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;
/*Enable pin */
GPIOE->MODER = 0X55555555; // lcd_pins OUTPUT MODE SELECT
GPIOE->OTYPER = 0x00000000;
GPIOE->PUPDR = 0x00000000;
GPIOE->OSPEEDR = 0xAAAAAAAA;
GPIOE->ODR = 0x00000000;

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 43


RESULT
Thus 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.
EX: No: 6 INTERFACING EEPROM AND INTERRUPT

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 44


AIM
To develop a C-Language program to write and read a data in EEPROM and also to
analyze its performance with the interrupt.

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.


2. IAR IDE software.
3. Flash Loader Demonstrator.

THEORY

Serial-interface EEPROM’s are used in a broad spectrum of consumer, automotive,


telecommunication, medical, industrial and PC related markets. Primarily used to store personal
preference data and configuration/setup data, Serial EEPROM’s are the most flexible type of
nonvolatile memory utilized today. Compared to other NVM solutions, Serial EEPROM devices
offer a lower pin count, smaller packages, lower voltages, as well as lower power consumption.

Fig(a): Circuit Diagram of EEPROM

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 45


PROCEDURE
1. Double click IAR Embedded Workbench in the Desktop.
2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the program, select new from file menu and save it with the name (anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
6. Change the mode of the program into downloading mode by using Flash loader
software.
7. To view the output, after downloading your program change the board to execution
mode in cortex M4 development board and reset it.
8. In first step, some data will be written in EEPROM at the starting address 0x01.
9. Then read the data from that memory location. The read data will be displayed in the
terminal window.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 46


PROGRAM (TO WRITE DATA)
#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"

#define SLAVE_ADDRESS1 0xA6 // the slave address (example)


#define SLAVE_ADDRESS2 0xA7 // the slave address (example)

/* prototype functions */
void I2C_stop(I2C_TypeDef* I2Cx);
void I2C_write(I2C_TypeDef* I2Cx, uint8_t data);
void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction);
void init_I2C1();
void Delay(int t);
void USART2_config();

int main(void)
{

USART2_config();

printf("\n welcome to EEPROM");


init_I2C1();

int i;

I2C_start(I2C1, SLAVE_ADDRESS1, I2C_Direction_Transmitter); // start a


transmission in Master transmitter mode

I2C_write(I2C1,0x00); //send EEPROM MSB address

I2C_write(I2C1,0x00); //send EEPROM LSB address

/*write data upto 63 */


for(i=10;i<74;i++) //modify your data here.here data is 10 to 73
{
I2C_write(I2C1,i);
Delay(200);
}
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 47
I2C_stop(I2C1); //stop write operation
Delay(2000);
}

void Delay(int t)
{
int y,u;
for(y=0;y<t;y++)
for(u=0;u<t;u++);
}

void USART2_config()
{
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1 <<17;

GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;

USART2->BRR = 0x16D;//115200 baud rate


USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;

int putchar(int data)


{
USART2->DR = (data & 0x01FF);
/* Loop until the end of transmission */
while((USART2->SR & 0x40) ==0)
{}
return data;
}
void init_I2C1()
{
GPIO_InitTypeDef GPIO_InitStruct;
I2C_InitTypeDef I2C_InitStruct;

// enable APB1 peripheral clock for I2C1


RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

// enable clock for SCL and SDA pins


RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 48


/* setup SCL and SDA pins
* You can connect I2C1 to two different
* pairs of pins:
* 1. SCL on PB6 and SDA on PB9
*/

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9; // we are going to use PB6 and


PB7
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; // set pins to alternate
function
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; // set GPIO speed
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD; // set output to open drain
--> the line has to be only pulled low, not driven high
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; // enable pull up resistors
GPIO_Init(GPIOB, &GPIO_InitStruct); // init GPIOB

// Connect I2C1 pins to AF

GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1); // SCL


GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_I2C1); // SDA

// configure I2C1

I2C_InitStruct.I2C_ClockSpeed = 100000; // 100kHz


I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; // I2C mode
I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2; // 50% duty cycle --> standard
I2C_InitStruct.I2C_OwnAddress1 = 0x00; // own address, not relevant in master
mode
I2C_InitStruct.I2C_Ack = I2C_Ack_Disable; // disable acknowledge when reading
(can be changed later on)
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; // set address
length to 7 bit addresses
I2C_Init(I2C1, &I2C_InitStruct); // init I2C1

// enable I2C1
I2C_Cmd(I2C1, ENABLE);
}

void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)


{

// wait until I2C1 is not busy anymore


while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));

// Send I2C1 START condition


I2C_GenerateSTART(I2Cx, ENABLE);

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 49


// wait for I2C1 EV5 --> Slave has acknowledged start condition
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));

// Send slave Address for write


I2C_Send7bitAddress(I2Cx, address, direction);

/* wait for I2C1 EV6, check if


* either Slave has acknowledged Master transmitter or
* Master receiver mode, depending on the transmission
* direction
*/
if(direction == I2C_Direction_Transmitter)
{

while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
}

else if(direction == I2C_Direction_Receiver)


{
while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
}
}

void I2C_write(I2C_TypeDef* I2Cx, uint8_t data)


{
I2C_SendData(I2Cx, data);
// wait for I2C1 EV8_2 --> byte has been transmitted
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
}

uint8_t I2C_read_ack(I2C_TypeDef* I2Cx)


{
// enable acknowledge of recieved data
I2C_AcknowledgeConfig(I2Cx, ENABLE);
// wait until one byte has been received
while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED) );
// read data from I2C data register and return data byte
uint8_t data = I2C_ReceiveData(I2Cx);
return data;
}

void I2C_stop(I2C_TypeDef* I2Cx)

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 50


{
// Send I2C1 STOP Condition
I2C_GenerateSTOP(I2Cx, ENABLE);
}

int I2C_read(I2C_TypeDef* I2Cx,uint8_t MSB_addr,uint8_t LSB_addr)


{
int j;
I2C_start(I2Cx, SLAVE_ADDRESS1, I2C_Direction_Transmitter); // start a transmission in
Master transmitter mode
Delay(200);

I2C_write(I2C1,MSB_addr);

I2C_write(I2C1,LSB_addr);

I2C_stop(I2C1);
Delay(200);

I2C_start(I2Cx, SLAVE_ADDRESS2, I2C_Direction_Receiver); // start a transmission in


Master transmitter mode
Delay(200);
j = I2C_ReceiveData(I2C1);
//printf("\n %d",j);
I2C_stop(I2C1);
Delay(200);
return(j);

PROGRAM (TO READ DATA)

#include "stm32f4xx.h"
#include "stm32f4xx_i2c.h"

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 51


#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
#include "misc.h"
#include "stdio.h"

//uint8_t GK[64] = "ABCD";

#define SLAVE_ADDRESS1 0xA6 // the slave address (example)


#define SLAVE_ADDRESS2 0xA7 // the slave address (example)

/* prototype functions */
void I2C_stop(I2C_TypeDef* I2Cx);
void I2C_write(I2C_TypeDef* I2Cx, uint8_t data);
void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction);
int I2C_read(I2C_TypeDef* I2Cx,uint8_t MSB_addr,uint8_t LSB_addr);
void init_I2C1();
void Delay(int t);
void USART2_config();

int main(void)
{

USART2_config();

printf("\n welcome to EEPROM");


init_I2C1();

int i,gk;

/*EEPROM read operation */

printf("\n\n EEPROM EEPROM ");


printf("\nAddress Data ");
for(i=0;i<64;i++)
{
gk = I2C_read(I2C1,0x00,i);
printf("\n 0x%x------->%d ",0x00+i,gk);
}

void Delay(int t)

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 52


{
int y,u;
for(y=0;y<t;y++)
for(u=0;u<t;u++);
}

void USART2_config()
{
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1 <<17;

GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;

USART2->BRR = 0x16D;//115200 baud rate


USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;

int putchar(int data)


{
USART2->DR = (data & 0x01FF);
/* Loop until the end of transmission */
while((USART2->SR & 0x40) ==0)
{}
return data;
}
void init_I2C1()
{
GPIO_InitTypeDef GPIO_InitStruct;
I2C_InitTypeDef I2C_InitStruct;

// enable APB1 peripheral clock for I2C1


RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

// enable clock for SCL and SDA pins


RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

/* setup SCL and SDA pins


* You can connect I2C1 to two different
* pairs of pins:
* 1. SCL on PB6 and SDA on PB9
*/

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 53


GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9; // we are going to use PB6 and
PB7
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; // set pins to alternate
function
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; // set GPIO speed
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD; // set output to open drain
--> the line has to be only pulled low, not driven high
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; // enable pull up resistors
GPIO_Init(GPIOB, &GPIO_InitStruct); // init GPIOB

// Connect I2C1 pins to AF

GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1); // SCL


GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_I2C1); // SDA

// configure I2C1

I2C_InitStruct.I2C_ClockSpeed = 100000; // 100kHz


I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; // I2C mode
I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2; // 50% duty cycle --> standard
I2C_InitStruct.I2C_OwnAddress1 = 0x00; // own address, not relevant in master
mode
I2C_InitStruct.I2C_Ack = I2C_Ack_Disable; // disable acknowledge when reading
(can be changed later on)
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; // set address
length to 7 bit addresses
I2C_Init(I2C1, &I2C_InitStruct); // init I2C1

// enable I2C1
I2C_Cmd(I2C1, ENABLE);
}

void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)


{

// wait until I2C1 is not busy anymore


while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));

// Send I2C1 START condition


I2C_GenerateSTART(I2Cx, ENABLE);

// wait for I2C1 EV5 --> Slave has acknowledged start condition
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));

// Send slave Address for write


I2C_Send7bitAddress(I2Cx, address, direction);

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 54


/* wait for I2C1 EV6, check if
* either Slave has acknowledged Master transmitter or
* Master receiver mode, depending on the transmission
* direction
*/
if(direction == I2C_Direction_Transmitter)
{

while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
}

else if(direction == I2C_Direction_Receiver)


{
while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
}
}

void I2C_write(I2C_TypeDef* I2Cx, uint8_t data)


{
I2C_SendData(I2Cx, data);
// wait for I2C1 EV8_2 --> byte has been transmitted
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
}

uint8_t I2C_read_ack(I2C_TypeDef* I2Cx)


{
// enable acknowledge of recieved data
I2C_AcknowledgeConfig(I2Cx, ENABLE);
// wait until one byte has been received
while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED) );
// read data from I2C data register and return data byte
uint8_t data = I2C_ReceiveData(I2Cx);
return data;
}
uint8_t I2C_read_nack(I2C_TypeDef* I2Cx)
{
// disabe acknowledge of received data
// nack also generates stop condition after last byte received
// see reference manual for more info
I2C_AcknowledgeConfig(I2Cx, DISABLE);
I2C_GenerateSTOP(I2Cx, ENABLE);
// wait until one byte has been received
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 55
while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED) );
// read data from I2C data register and return data byte
uint8_t data = I2C_ReceiveData(I2Cx);
return data;
}

void I2C_stop(I2C_TypeDef* I2Cx)


{
// Send I2C1 STOP Condition
I2C_GenerateSTOP(I2Cx, ENABLE);
}

int I2C_read(I2C_TypeDef* I2Cx,uint8_t MSB_addr,uint8_t LSB_addr)


{
int j;
I2C_start(I2Cx, SLAVE_ADDRESS1, I2C_Direction_Transmitter); // start a transmission in
Master transmitter mode
Delay(200);

I2C_write(I2C1,MSB_addr);

I2C_write(I2C1,LSB_addr);

I2C_stop(I2C1);
Delay(200);

I2C_start(I2Cx, SLAVE_ADDRESS2, I2C_Direction_Receiver); // start a transmission in


Master transmitter mode
Delay(200);
j = I2C_ReceiveData(I2C1);
//printf("\n %d",j);
I2C_stop(I2C1);
Delay(200);
return(j);
}

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 56


RESULT
Thus 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.

EX: No: 9 MAILBOX

AIM

To develop a ‘C’ code to create a mailbox and to understand the RTOS functions.

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.


2. IAR IDE software.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 57


3. Flash Loader Demonstrator.

THEORY

Real-time and embedded systems operate in constrained environments in which computer


memory and processing power are limited. They often need to provide their services within strict
time deadlines to their users and to the surrounding world. It is these memory, speed and timing
constraints that dictate the use of real-time operating systems in embedded software.

The "kernel" of a real-time operating system ("RTOS") provides an "abstraction layer" that hides
from application software the hardware details of the processor (or set of processors) upon which
the application software will run.

Fig(a): Kernel of Real-Time Operating System

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.

The second category of kernel services is Intertask Communication and Synchronization.


These services make it possible for tasks to pass information from one to another, without danger

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 58


of that information ever being damaged. They also make it possible for tasks to coordinate, so
that they can productively cooperate with one another. Without the help of these RTOS services,
tasks might well communicate corrupted information or otherwise interfere with each other.
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.

PROCEDURE
1. Double click IAR Embedded Workbench in the Desktop.
2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the program, select new from file menu and save it with the name
( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 59


6. Change the mode of the program into downloading mode by using Flash loader
software.
7. To view the output, after downloading your program change the board to execution
mode in cortex M4 development board and reset it.
8. The data that is transmitted from the task 1 is received by the task 2 and is displayed.

PROGRAM
#include "ucos_ii.h"
#include "bsp.h"

#define TASK_STK_SIZE 128


OS_STK AppStk_send[TASK_STK_SIZE];
OS_STK AppStk_recv[TASK_STK_SIZE];
static void Mailbox_App_Tx(void *p_arg);
static void Mailbox_App_Rx(void *p_arg);

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 60


OS_EVENT *pmailbox;

int main(void)
{
BSP_IntDisAll();

/* Disable all interrupts until we are ready to accept them */


RCC_ClocksTypeDef rcc_clocks;
RCC_GetClocksFreq(&rcc_clocks);
SysTick_Config(rcc_clocks.HCLK_Frequency/OS_TICKS_PER_SEC);
OSInit(); //ucosii initialization
BSP_Init(); //board support package initialization
OSStatInit(); /*DetermineCPUcapacity.*/
/*TODO:create application tasks here*/
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
OSStart(); //start os here
printf("\n\r Never Arrives here");
return 0;
}

/* post data to mailbox */


void Mailbox_App_Tx(void *p_arg)
{
INT8U i,err, *buffer[5];
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);

for (i=0;i<=5;)
{
if((err=OSMboxPost(pmailbox,buffer[i]))==NO_ERROR_GK) //if success
{
printf("\n\rThis is sender \n\t post data to Mailbox,data is-->%s",buffer[i]);
i++;
}
else if(err== MAILBOX_FULL_GK) //if mailbox full
printf("\n\rThis is sender \n\t the Mailbox has data,data is-->%s",pmailbox-
>OSEventPtr);
else //other errors occured
printf("\n\r Other err");
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 61
OSTimeDlyHMSM(0, 0, 5, 0);
}
OSTimeDlyHMSM(0, 0, 5, 0);
OSMboxDel (pmailbox,OS_DEL_NO_PEND, &err);
if(err==OS_ERR_TASK_WAITING_GK) //another task waiting error
printf("\n\rSome task wait for this Mailbox");
}

/*Get data from mailbox */


void Mailbox_App_Rx(void *p_arg)
{
INT8U err;
INT16U timeout=100;
INT8U *buffer;
p_arg = p_arg;

for (;;)
{
buffer=OSMboxPend(pmailbox,timeout,&err);
OSTimeDly(200);

if(err==OS_ERR_NONE) //if no error


printf("\n\rThis is receiver \n\t get data from Mailbox data is->%s",buffer);
else if(err==TIMEOUT_ERROR_GK) //if timeout error occured
printf("\n\rTimeout");
else if(err==EVENT_TYPE_ERROR_GK)//if unmatched event occured
{
printf("\n\rThis is receiver \n\t err is OS_ERR_EVENT_TYPE");
break;
}
else
break;
OSTimeDlyHMSM(0,0,6, 0);
}
}

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 62


RESULT
Thus the C-Language program to create a mailbox and to understand the about the RTOS
functions is developed and is verified.

EX: No: 8 INTERRUPT PERFORMANCE CHARACTERISTICS OF

ARM AND FPGA

AIM
To study about the Interrupt performance characteristics between ARM and FPGA.

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.


2. IAR IDE software.
3. Flash Loader Demonstrator.
4. Xilinx FPGA Spartan 6.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 63


5. Xilinx ISE Design suite.
6. ModelSim SE.
7. JTAG 5.5.
8. CRO.

THEORY

EMBEDDED SYSTEM CHARACTERISTICS:

A common array of n configuration for very-high-volume embedded systems is the system on


a chip (SoC) which contains a complete system consisting of multiple processors, multipliers,
caches and interfaces on a single chip. SoCs can be implemented as an application-specific
integrated circuit (ASIC) or using a field-programmable gate array (FPGA).

EMBEDDED SOFTWARE ARCHITECTURE:

Interrupt-controlled system

Some embedded systems are predominantly controlled by interrupts. This means that tasks
performed by the system are triggered by different kinds of events; an interrupt could be
generated, for example, by a timer in a predefined frequency, or by a serial port controller
receiving a byte.

These kinds of systems are used if event handlers need low latency, and the event handlers
are short and simple. Usually, these kinds of systems run a simple task in a main loop also, but
this task is not very sensitive to unexpected delays.

Sometimes the interrupt handler will add longer tasks to a queue structure. Later, after the
interrupt handler has finished, these tasks are executed by the main loop. This method brings the
system close to a multitasking kernel with discrete processes.

TYPES OF INTERRUPTS:

There are two types of interrupts: Hardware and Software.


Software interrupts are called from software, using a specified command. Hardware
interrupts are triggered by peripheral devices outside the microcontroller. For instance,
embedded system may contain a timer that sends a pulse to the controller every second.
Microcontroller would wait until this pulse is received, and when the pulse comes, an interrupt
would be triggered that would handle the signal.

INTERRUPT SERVICE ROUTINE:

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 64


Interrupt Service Routines (ISR) are the portions of the program code that handle the
interrupt requests. When an Interrupt is triggered (either a hardware or software interrupt), the
processor breaks away from the current task, moves the instruction pointer to the ISR, and then
continues operation. When the ISR has completed, the processor returns execution to the
previous location.

Many embedded systems are called interrupt driven systems, because most of the processing
occurs in ISRs, and the embedded system spends most of its time in a low-power mode.

PROCEDURE (ARM)

1. Double click IAR Embedded Workbench in the Desktop.


2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the program, select new from file menu and save it with the name
( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 65


6. Change the mode of the program into downloading mode by using Flash loader
software.
7. To view the output, after downloading your program change the board to execution
mode in cortex M4 development board and reset it.

PROGRAM ( Interrupt behavior of ARM)

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_gpio.h"
#include "misc.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 66


#include "stm32f4xx_exti.h"
#include "stm32f4xx_syscfg.h"

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
static void EXTILine4_Config(void);
static void EXTILine2_Config(void);

__IO uint16_t CCR1_Val = 1000;


__IO uint16_t CCR2_Val = 1000;
__IO uint16_t CCR3_Val = 6000;
__IO uint16_t CCR4_Val = 8000;
uint16_t PrescalerValue = 0;
uint16_t capture = 0;
/* Private function prototypes -----------------------------------------------*/
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;
}
int main(void)
{

/* TIM Configuration */
TIM_Config();
usart2_init();
EXTILine2_Config();
EXTILine4_Config();

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 67


printf("\n welcome to interrupt");

while (1);

int putchar(int data)


{
USART2->DR = (data & 0x01FF);
/* Loop until the end of transmission */
while((USART2->SR & 0x40) ==0)
{}
return data;
}

static void EXTILine2_Config(void)


{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

/* Enable GPIOE clock */

RCC->AHB1ENR |= 0x00000010;
/* Enable SYSCFG clock */

RCC->APB2ENR |= 0x00004000;

/* Configure PE2 pin as input floating */


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);
/* Connect EXTI Line0 to PA0 pin */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource2);

/* Configure EXTI Line0 */


EXTI_InitStructure.EXTI_Line = EXTI_Line2;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);

/* Enable and set EXTI Line0 Interrupt to the lowest priority */


NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 68
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**
* @brief Configures EXTI Line15 (connected to PG15 pin) in interrupt mode
* @param None
* @retval None
*/
static void EXTILine4_Config(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC->AHB1ENR |= 0x00000010;
/* Enable SYSCFG clock */
RCC->APB2ENR |= 0x00004000;

/* Configure PE4 pin as input floating */


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);

/* Connect EXTI Line15 to PG15 pin */


SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource4);

/* Configure EXTI Line15 */


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);
/* Enable and set EXTI15_10 Interrupt to the lowest priority */
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);
}
/**
* @brief Configure the TIM IRQ Handler.
* @param None
* @retval None
*/
void TIM_Config(void)

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 69


{
NVIC_InitTypeDef NVIC_InitStructure;

/* TIM3 clock enable */


RCC->APB1ENR |= 0x00000002;
RCC->APB1ENR |= 0x00000004;

/* Enable the TIM3 gloabal Interrupt */


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);
/* Enable the TIM3 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

/* Initialize Leds mounted on STM324xG-EVAL board */


RCC->AHB1ENR |= 1<<3;

GPIOD->MODER = 0x00550000;
GPIOD->OTYPER = 0x00000000;
GPIOD->OSPEEDR = 0xAAAAAAAA;
GPIOD->PUPDR = 0x00000000;

/* Compute the prescaler value */


PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 1000) - 1;
/* Time base configuration */
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);
/* Prescaler configuration */
TIM_PrescalerConfig(TIM3, PrescalerValue, TIM_PSCReloadMode_Immediate);

/* Output Compare Timing Mode configuration: Channel1 */


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;
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 70
TIM_OC1Init(TIM3, &TIM_OCInitStructure);

TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);

/* Time base configuration */


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 */
TIM_PrescalerConfig(TIM4, PrescalerValue, TIM_PSCReloadMode_Immediate);
/* Output Compare Timing Mode configuration: Channel1 */
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 Interrupts enable */


TIM_ITConfig(TIM3, TIM_IT_CC1,ENABLE);
TIM_ITConfig(TIM4, TIM_IT_CC1,ENABLE);

/* TIM3 enable counter */


TIM_Cmd(TIM4, ENABLE);
TIM_Cmd(TIM3, ENABLE);

}
void EXTI2_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line2) != RESET)
{
/* Toggle LED1 */

GPIOD->ODR = 0x00000200;
printf("\n I am External-->2 interrupt");
delay(1000);
/* Clear the EXTI line 0 pending bit */
EXTI_ClearITPendingBit(EXTI_Line2);
}
}
void EXTI4_IRQHandler(void)
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 71
{
if(EXTI_GetITStatus(EXTI_Line4) != RESET)
{
GPIOD->ODR = 0x00000400;
/* Toggle LED2 */
printf("\n I am External-->1 interrupt");
delay(1000);
/* Clear the EXTI line 15 pending bit */
EXTI_ClearITPendingBit(EXTI_Line4);
}
}
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);
/* LED1 toggling with frequency = 73.24 Hz */
GPIOD->ODR = 0x00000100;
capture = TIM_GetCapture1(TIM3);
printf("\n I am Timer-->2 interrupt");
delay(1000);

TIM_SetCompare1(TIM3, capture + CCR1_Val);


}
}
void TIM4_IRQHandler(void)
{
if (TIM_GetITStatus(TIM4, TIM_IT_CC1) != RESET)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC1);

/* LED1 toggling with frequency = 73.24 Hz */


GPIOD->ODR = 0x00000800;
printf("\n I am Timer-->1 interrupt");
capture = TIM_GetCapture1(TIM4);
delay(0000);
TIM_SetCompare1(TIM4, capture + CCR2_Val);
}
}

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 72


PROCEDURE (FPGA)

Step 1: Create a “New project” in Xilinx ISE Project Navigator from File
Button.

Step 2: Assign a “Name” of the project and click “Next”

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.)

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 73


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 8: Click “Finish” the Summary window pane.

Step 9: 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”.
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. (The .bit file has been generated for the project)

Step 14: Connect the FPGA hardware kit with the CPU by using serial cable and
Switch “ON”.

Step 15: Open the JTAG 5.5 software from Start menu in computer and
initialize the FPGA device for dumping the program into it.

Step 16: While initializing please “Assign” the “.bit file” and “Program” FPGA
by in the JTAG 5.5 application.

(The coded instructions have been loaded in the FPGA hardware kit.

PROCEDURE TO VIEW RESULT IN FPGA

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 74


Connect the probes of CRO/MSO/DSO to the Desired Input and Output pins of the I/O
connectors to view the result of the Interrupt performance of FPGA device.

PROCEDURE TO VIEW RESULT IN SIMULATION

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: The Input and output result in the Simulator can be observed.

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;

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 75


RISING_INTERRUPT2: OUT STD_LOGIC
);
END TOP_MODULE;

ARCHITECTURE BEHAVIORAL OF TOP_MODULE IS


-- DECLARATION OF THE PORT DETAILS IN INPUT SIGNAL MODULE--
COMPONENT CLK_GEN IS PORT ( CLK : IN STD_LOGIC;
GEN_CLK1 :
OUT STD_LOGIC;
GEN_CLK2 :
OUT STD_LOGIC;
GEN_CLK3 :
OUT STD_LOGIC
);
END COMPONENT;

-- DECLARATION OF THE PORT DETAILS IN INTERRUPT ROUTINE MODULE--


COMPONENT INTERRUPT IS PORT ( CLK : IN 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 COMPONENT;
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_INT
ERRUPT2);

END BEHAVIORAL;

CLK_GEN

LIBRARY IEEE;

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 76


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

SIGNAL FREQ :INTEGER :=0; -- SIGNAL DECLARATION OF FREQ


BEGIN
PROCESS(CLK) -- INPUT CLOCK SIGNAL FOR GENERATING 3 INPUT SIGNALS
BEGIN
IF RISING_EDGE (CLK) THEN -- ROUTINE FOLLOWS WITH REFERENCE TO THE
CLOCK SIGNAL
FREQ <= FREQ +1; -- GENGERATING THE COUNTER FOR THE SIGNAL
FREQ
IF(FREQ >0 AND FREQ <= 10000)THEN -- FOR GETTING 1KHZ SIGNAL WE
ARE EQUALLY SPLITTING UP THE TIMING VALUES '0' FOR 10000 COUNTS AND '1'
FOR 10000 COUNTS
GEN_CLK1 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK2 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK3 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZ
ELSIF (FREQ >10000 AND FREQ <= 20000)THEN
GEN_CLK1 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK2 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK3 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZ

ELSIF (FREQ > 20000)THEN


FREQ <= 0; -- COUNTER RESETS TO '0' IT IT EXCEEDS 20000 COUNTS
END IF;
END IF; -- PROCESS ENDS BY GENERATING THE 3 INPUT SIGNALS
END PROCESS;
END BEHAVIORAL;

INTERRUPT

-------------------------------------------------------------------------
-- LIBRARY PART --
-------------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-------------------------------------------------------------------------
-- PORT DECLARATION PART --

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 77


-------------------------------------------------------------------------
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 --
-------------------------------------------------------------------------
ARCHITECTURE BEHAVIORAL OF INTERRUPT IS
SIGNAL C1,C2,C3 : INTEGER :=0 ;
--INTERNAL INTEGER SIGNAL DECLARATION FOR GLOBAL PURPOSE
SIGNAL RISING,RISING1,RISING2,X,Y,Z: STD_LOGIC:='0'; --INTERNAL BINARY OR
SINGLE BIT SIGNAL FOR GLOBAL USE
BEGIN

--------------------------------------------------------------------------
-- FIRST INTERRUT DESIGN --
--------------------------------------------------------------------------
PROCESS(CLK,INPUT1) --SENSITIVITY LIST FOR INPUT USE
VARIABLE A,B,C,D,E,F,G,H,I,J,K,L,M,N : INTEGER :=0 ; --INTERNAL VARIABLE'S
DECLARATION FOR INTERNAL PROCESS
BEGIN
IF RISING_EDGE(CLK) THEN --CLOCK SIGNAL
RISING_INTERRUPT<= RISING;
-- ASSIGNING RISING_INTERRUPT AS RISING VALUE
CASE X IS
-- SUBJECTING X VALUE WITH THE STANDARD LOGIC
FUNCTION '0' AND '1'
WHEN '0' =>
IF INPUT1='1' THEN--ROUTINE WILL CONINUE IF INPUT1 IN ON
CONDITION
RISING<='1'; -- RISING VALUE SHOULD BE ON & X
VALUE SHOULD BE ON
X<='1';
END IF;
WHEN '1'=>
IF INPUT1='0' THEN--ROUTINE WILL CONTINUE IF INPUT 1 IN
OFF CONDITION
X<='0'; -- VALUE OF X TENDS TO '0'
END IF;

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 78


WHEN OTHERS=> -- IF ANY CONDITION OTHER
THAN '0' AND '1' THEN THE SUBJECT SHOULD BE ENDED.
END CASE;
IF RISING='1' THEN -- IF THE SIGNAL FOUND AS RISING EDGE THEN
THE BELOW OPERATION SHOULD BE FOLLOWED BY THE PROCESSOR

A := 30000+300000; -- ADDITION OPERATION


B:= 5669*6587; --MULTIPLICATION OPERATION
C:= 5456496/564; --DIVISION OPERATION
E:=684986-546657; --SUBTRACTION OPERATION
F:=4858*555; --MULTIPLICATION
OPERATION
G:=45587486/6484; --DIVISION OPERATION
H:=5847962-45134; --SUBTRACTION OPERATION
I:=6872678+2587; -- ADDITION OPERATION
J:=245231+5454; -- ADDITION OPERATION
K:=86748/654; --DIVISION OPERATION
L:=816784*864; --MULTIPLICATION OPERATION
M:=54341/64112; --DIVISION OPERATION
N:=46845*4816; --MULTIPLICATION OPERATION
C1<=C1+1; -- HERE THE COUNTER STARTS TO SUPPORT THE DELAY
IF C1>= 9000 THEN -- WE CAN MANUALLY SET THE LIMIT AS OUR
CONVENIENCE
RISING<='0'; -- ONCE THE COUNTER
EXCEEDS THE VALUE OF 9000 THEN THE STATE OF RISING SHOULD BE '0'. THEN
THE ROUTINE WILL END UP.
C1<=0; --ONCE THE COUNTER
EXCEEDS OUR GIVEN LIMIT THEN THE COUNTER VALUE RESETS TO 0.
END IF; -- RISING = '1' CONDITION ENDS
HERE.
END IF;

END IF; -- ENTIRE PROCESS ENDS


UP ONCE THE COUNTER EXCEEDS THE GIVEN LIMIT ALOND WITH THE GIVEN
ARITHMETIC OPERATIONS..
END PROCESS; -- THESE ABOVE CONDITIONS
PROVIDE US THE INTERRUPT PERFORMANCE OFTHE GIVEN INPUT SIGNAL THRU
RISING_INTERRUPT SIGNAL.
--------------------------------------------------------------------------
-- SECOND INTERRUPT DESIGN --
--------------------------------------------------------------------------
PROCESS(CLK,INPUT2) --SENSITIVITY LIST FOR INPUT USE
VARIABLE A,B,C,D,E,F,G,H,I,J,K,L,M,N:INTEGER :=0; --INTERNAL VARIABLE'S
DECLARATION FOR INTERNAL PROCESS
BEGIN
IF RISING_EDGE(CLK) THEN --CLOCK SIGNAL

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 79


RISING_INTERRUPT1<= RISING1; -- ASSIGNING RISING_INTERRUPT AS
RISING VALUE

CASE Y IS WHEN '0' => -- SUBJECTING Y VALUE WITH THE


STANDARD LOGIC FUNCTION '0' AND '1'
IF INPUT2='1' THEN --ROUTINE WILL CONINUE IF INPUT1
IN ON CONDITION

RISING1<='1'; -- RISING VALUE SHOULD BE '1' & X


VALUE SHOULD BE ON

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;

WHEN OTHERS=> -- IF ANY CONDITION OTHER


THAN '0' AND '1' THEN THE SUBJECT SHOULD BE ENDED.

END CASE;

IF RISING1 ='1' THEN -- IF THE SIGNAL FOUND AS


RISING EDGE THEN THE BELOW OPERATION SHOULD BE FOLLOWED BY THE
PROCESSOR

A := 30000+300000; -- ADDITION OPERATION


B:= 5669*6587; --MULTIPLICATION
OPERATION
C:= 5456496/564; --DIVISION OPERATION
E:=684986-546657; --SUBTRACTION OPERATION
F:=4858*555; --MULTIPLICATION
OPERATION
G:=45587486/6484; --DIVISION OPERATION
H:=5847962-45134; --SUBTRACTION OPERATION
I:=6872678+2587; -- ADDITION OPERATION
J:=245231+5454; -- ADDITION OPERATION
K:=86748/654; --DIVISION OPERATION
L:=816784*864; --MULTIPLICATION
OPERATION
M:=54341/64112; --DIVISION OPERATION

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 80


N:=46845*4816; --MULTIPLICATION
OPERATION

C2<=C2+1; -- HERE THE COUNTER


STARTS TO SUPPORT THE DELAY OF THE SIGNAL

IF C2>= 6000 THEN -- WE CAN MANUALLY SET THE LIMIT AS OUR


CONVENIENCE
RISING1<='0'; -- ONCE THE COUNTER
EXCEEDS THE VALUE OF 6000 THEN THE STATE OF RISING SHOULD BE '0'. THEN
THE ROUTINE WILL END UP.

C2<=0; --ONCE THE


COUNTER EXCEEDS OUR GIVEN LIMIT THEN THE COUNTER VALUE RESETS TO 0.

END IF; --THE RISING = '1'


CONDITION ENDS HERE.

END IF; -- ENTIRE


PROCESS ENDS UP ONCE THE COUNTER EXCEEDS THE GIVEN LIMIT ALOND WITH
THE GIVEN ARITHMETIC OPERATIONS..

END IF; -- THESE ABOVE


CONDITIONS PROVIDE US THE INTERRUPT PERFORMANCE OF THE GIVEN INPUT
SIGNAL THRU RISING_INTERRUPT SIGNAL.

END PROCESS;
END BEHAVIORAL;

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 81


RESULT

Thus the performance of interrupt in ARM and FPGA was studied.

EX: No: 9 FLASHING OF LEDS

AIM

To develop a ‘C’ program to make the LED blink (including delay routine).

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.


2. IAR IDE software.
3. Flash Loader Demonstrator.

THEORY

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 82


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.

Fig (a): Schematic arrangement of LED

PROCEDURE
1. Double click IAR Embedded Workbench in the Desktop.
2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the program, select new from file menu and save it with the name
( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
6. Change the mode of the program into downloading mode by using Flash loader
software.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 83


7. To view the output, after downloading your program change the board to execution
mode in cortex M4 development board and reset it.
8. The four LEDs on the board will toggle with a delay.

PROGRAM
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_rcc.h"

void LED_init();

/* delay function */

void delay(long int a)


{

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 84


long int b,c;
for(b=0;b<a;b++)
for(c=0;c<a;c++);
}

/*main function starts here */

void main()
{
LED_init(); //LED initialization
while(1)
{
GPIOD->ODR =0x00000F00; //leds turns ON
delay(3000); //delay

GPIOD->ODR =0x00000000; //leds turns OFF


delay(3000); //delay
}
}
void LED_init()
{
RCC->AHB1ENR = 1 <<3; //enable the clock to port D
GPIOD->MODER = 0x55555555; //select all pins as output mode
GPIOD->OTYPER =0x00000000; //push-pull type
GPIOD->OSPEEDR =0xAAAAAAAA; //50MHz speed
GPIOD->PUPDR =0x00000000; //no pull-up no pull down
}

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 85


RESULT

Thus the C-Language program to make the LED blink was developed and output was
verified. The speed variation was verified by changing the delay function.

EX: No: 10 INTERFACING STEPPER MOTOR AND TEMPERATURE

SENSOR

AIM
To write C Program for running stepper motor either in clock-wise or counter-clock-wise
and the direction of the rotation of the stepper motor depends on the variation in the temperature
sensor.

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 86


2. IAR IDE software.
3. Flash Loader Demonstrator.
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.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 87


Fig(a): Schematic Arrangement of Stepper Motor Driver

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 88


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.

Fig(b): Schematic Arrangement of Temperature Sensor

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 89


PROCEDURE
1. Double click IAR Embedded Workbench in the Desktop.
2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the program, select new from file menu and save it with the name (anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
6. Change the mode of the program into downloading mode by using Flash loader
software.
7. To view the output, after downloading your program change the board to execution
mode in cortex M4 development board and reset it.
8. Stepper Motor Output :-> The stepper motor will start rotating.
9. Temperature Sensor Output :-> The room Temperature will be displayed on the
Terminal Window.
10. Place a soldering iron or any substance that will dissipate some amount of heat near
U12 IC, to have a variation in the temperature readings.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 90


PROGRAM (STEPPER MOTOR & TEMPERATURE SENSOR)
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_adc.h"
#include "stm32f4xx_gpio.h"

static int i=0;

/* private prototype functions*/


void anticlock_wise();
void clock_wise();
void USART2_config();
void adc_configure();
int adc_convert();
uint32_t temp;
static float gk;

void delay()
{
for(int i=0;i<0xFF;i++)
for(int j=0;j<0xFF;j++);
}

__IO uint32_t uhADCxConvertedValue = 0;

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()
{

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 91


//Clock configuration
RCC->APB2ENR |= 1<<10; //The ADC1 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 ;)

//Analog pin configuration


GPIOA->MODER |=0x0000000F;
GPIOA->OSPEEDR = 0xFFFFFFFF;
GPIOA->PUPDR = 0x00000000;

/* ADC configuration */

ADC3->CR1 = 0x00000000; //scan mode disable,12-bit resolution.


ADC3->CR2 = 0x00000002; //data right alignment,continuous conversion mode.
ADC3->SQR1 = 0x00000000; //single mode conversion

ADC3->CR2 |= 0x00000001; //ADC enable

ADC3->SMPR2 = 0x00000030; //ADC3 channel-1 with 144 cycles


ADC3->SQR3 = 0x00000001;//rank1 to ADC3 channel-1

int adc_convert()
{
ADC_SoftwareStartConv(ADC3);//Start the conversion
while(!ADC_GetFlagStatus(ADC3, ADC_FLAG_EOC));//Processing the conversion
return ADC_GetConversionValue(ADC3); //Return the converted data
}

int putchar(int data)


{
USART2->DR = (data & 0x01FF);
/* Loop until the end of transmission */
while((USART2->SR & 0x40) ==0)
{}
return data;
}

void motor_PIN_config(void)
{
RCC->AHB1ENR |= 1<<1;

GPIOB->MODER = 0x55555555;
GPIOB->OTYPER =0x00000000;
GPIOB->PUPDR = 0x00000000;

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 92


GPIOB->OSPEEDR = 0xFFFFFFFF;
}

void main(void)
{
static int ConvertedValue;
motor_PIN_config();
USART2_config();
adc_configure();//ADC configuration

while(1)
{

ConvertedValue = adc_convert();//Read the ADC converted value

temp =ConvertedValue;
gk =temp*3.3;
gk /=4095;
gk *=100;
printf("\n Temperature = %3.2f°C",gk);

if(gk >40) //if temperature > 40


{
anticlock_wise();
delay();
}
else if(gk <40)//if temperature < 40
{
clock_wise();
delay();
}

}
}

void anticlock_wise()
{
for(i=0;i<52;i++)
{
GPIOB->ODR = 0xA000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x6000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x5000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x9000;

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 93


delay(); delay(); delay();delay(); delay();
}
}

void clock_wise()
{
for(i=0;i<52;i++)
{
GPIOB->ODR = 0x9000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x5000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x6000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0xA000;
delay(); delay(); delay();delay(); delay();
}
}

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 94


RESULT
Thus the C Program to make the stepper motor to rotate either in clock-wise or counter-clock-
wise direction was developed and the output was verified and also variation in the temperature is
noted.

EX: No: 11 IMPLEMENTING ZIGBEE PROTOCOL WITH ARM

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 95


AIM
To transmit the data via Xbee and view the output data in the PC.

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.


2. IAR IDE software.
3. Flash Loader Demonstrator.
4. Xbee modules 2 Nos.

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.

Some of its features are:


 ZigBee is targeted at radio-frequency (RF) applications.
 Low data rate, long battery life, and secure networking.
 Transmission range is between 10 and 75 meters (33~246 feet).
 The addressing space allows of extreme node density—up to
18,450,000,000,000,000,000 devices (64 bit IEEE address).
 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.
 To ensure reliable data transmission.
 Binary phase shift keying (BPSK) in the 868/915 MHz.
 Offset quadrature phase shift keying (O-QPSK) at 2.4 GHz.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 96


Fig (a): Xbee interfacing with PC

Fig (b): Xbee interfacing with Microcontroller

PROCEDURE (GENERAL STEPS)

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 97


1. Double click IAR Embedded Workbench in the Desktop.
2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the program, select new from file menu and save it with the name
( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.

STEPS: TO VIEW OUTPUT


 Compile, Debug & Simulate the above code in IAR.
 Connect the RS232 cable / USB cable provided to the PC / Laptop and the VSK – STM4
Boards, and Power on the Board.
 For seeing the output in real-time, select the PROG mode, reset the board and download
the code in the board using Flash Loader Demonstrator through UART0.
 Connect 1 Xbee module with VSK-STM4 board and the other module to the PC.
 Open Win X Talk with a baud rate of 115200.
 Now change the Mode-Selection-Switch to EXEC position and reset the board.
 The data that is transmitted from the controller can be viewed in PC.

PROGRAM

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 98


#include "stm32f4xx.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx_syscfg.h"
#include "stm32f4xx_gpio.h"
#include "misc.h"
#include <stdio.h>

unsigned char d1[] = {" WELCOME "};


unsigned char d2[] = {" Press any Key"};
int i,val,valsw;

enum { high =1,low = !high };


uint32_t tmp;
unsigned char r1_char[];
void USART2_config()
{
NVIC_InitTypeDef NVIC_InitStructure;
RCC->AHB1ENR |= high << 0;
RCC->APB1ENR |= high <<17;

GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;

//USART2->BRR = 0x16D; //115200


USART2->BRR = 0x1117; //9600 XBEE ONLY
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;

USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);


NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; // to configure the
USART3 interrupts
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // this sets the priority group
of the USART3 interrupts
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // this sets the subpriority inside
the group
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //the USART3 interrupts
are globally enabled
NVIC_Init(&NVIC_InitStructure); // the properties are passed to
the NVIC_Init function which takes care of the low level stuff
}

void delay(int a)
{
int i,j;
for(i=0;i<a;i++)

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 99


for(j=0;j<a;j++);
}

void busy_check()
{
delay(200);
GPIOE->BSRRH = 0x0020; //low the RS pin
GPIOE->BSRRH = 0x0040; //low RW pin

void command_write(int comm)


{
busy_check();
GPIOE->BSRRH = 0x0020; //low RS pin

GPIOE->ODR = (comm<<8)|(0<<5); //write the data from 8th bit.(i.E) PG8 to PG15
GPIOE->BSRRL = 0x0080; //enable pin high
delay(200);
GPIOE->BSRRH = 0x0080; //enable pin low
}

/*LCD initial commands */

void lcd_init()
{
command_write(0x38);
command_write(0x01);
command_write(0x0f);
command_write(0xC0);
command_write(0x06);
}

void lcd_out(unsigned char a)


{
busy_check();

GPIOE->BSRRL = 0x0020; //high RS pin


GPIOE->ODR = (a<<8)|(1<<5); //write the data from 8th bit.(i.E) PG8 to PG15
GPIOE->BSRRL = 0x0080;//enable pin high
delay(200);
GPIOE->BSRRH = 0x0080;//enable pin low
}

void lcd_stringout(unsigned char *gk)


{
int i;
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 100
busy_check();

GPIOE->BSRRL = 0x0020; //high RS pin


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
GPIOE->BSRRL = 0x0080;//enable pin high

delay(200);

GPIOE->BSRRH = 0x0080;//enable pin low


}
}
void mx_pinout_config(void)
{

/*Enable or disable the AHB1 peripheral clock */


RCC->AHB1ENR |= 1<<3; // enable the clock to port D
RCC->AHB1ENR |= 1<<4; //enable clock to port E
RCC->AHB1ENR |= 1<<2; //enable clock to port C
RCC->AHB1ENR |= 1<<1; //Enable clock to port B

GPIOD->MODER |=0x00550055; //set port D0-D3 as o/p mode,other pins are input moode
GPIOD->OTYPER =0x00000000;
GPIOD->PUPDR = 0x00000000;
GPIOD->OSPEEDR =0xAAAAAAAA;

GPIOB->MODER = 0x55555555;
GPIOB->OSPEEDR = 0xFFFFFFFF;

GPIOC->MODER = 0x55555555; //PC0 as o/p mode

/*Enable pin */
GPIOE->MODER = 0X55555445; // lcd_pins OUTPUT MODE SELECT
GPIOE->OTYPER = 0x00000000;
GPIOE->PUPDR = 0x00000880;
GPIOE->OSPEEDR = 0xAAAAAAAA;
// GPIOE->ODR = 0x00000000;

}
void xbee_tx()
{
/////////////////////////// 1st Row \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

GPIOD->BSRRH = 0x0001; //high PD0

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 101


GPIOD->BSRRL = 0x000E; //low PD1 to PD3
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
valsw = (GPIOE->IDR)&0x14;

if(valsw == 0x0B)
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("PE2_SW12 PRESSED");
USART2->DR = 0x43;
delay(4000);
while((USART2->SR & 0x40)==0);
}
else if(val== 0xE0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("PE4_SW11 PRESSED");
USART2->DR = 0x44;
while((USART2->SR & 0x40)==0);
}

if(val == 0xE0) //1st column


{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("C");
USART2->DR = 0x43;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 102


command_write(0xc8);
lcd_stringout("D");
USART2->DR = 0x44;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("E");
USART2->DR = 0x45;
while((USART2->SR & 0x40)==0);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("F");
USART2->DR = 0x46;
while((USART2->SR & 0x40)==0);
}
/////////////////////////// 2nd Row \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

GPIOD->BSRRH = 0x0002; //low PD0


GPIOD->BSRRL = 0x000D; //low PD0
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("8");
USART2->DR = 0x38;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xD0) //2nd column
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 103
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("9");
USART2->DR = 0x39;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("A");
USART2->DR = 0x41;
while((USART2->SR & 0x40)==0);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("B");
USART2->DR = 0x42;
while((USART2->SR & 0x40)==0);
}
/////////////////////////// 3rd Row \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

GPIOD->BSRRH = 0x0004; //low PD0


GPIOD->BSRRL = 0x000B; //low PD0

val = (GPIOD->IDR)&0xF0; //status of D4 to D7

if(val == 0xE0) //1st column


{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 104
delay(4000);

command_write(0xc8);
lcd_stringout("4");
USART2->DR = 0x34;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("5");
USART2->DR = 0x35;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("6");
USART2->DR = 0x36;
while((USART2->SR & 0x40)==0);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("7");
USART2->DR = 0x37;
while((USART2->SR & 0x40)==0);
}
/////////////////////////// 4th Row \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

GPIOD->BSRRH = 0x0008; //low PD0


GPIOD->BSRRL = 0x0007; //low PD0
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 105
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("0");
USART2->DR = 0x30;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("1");
USART2->DR = 0x31;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("2");
USART2->DR = 0x32;
while((USART2->SR & 0x40)==0);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);

command_write(0xc8);
lcd_stringout("3");
USART2->DR = 0x33;
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 106
while((USART2->SR & 0x40)==0);
}
}
////////////////////// MAIN \\\\\\\\\\\\\\\\\\\\\\\\\\

void main()
{

USART2_config();
mx_pinout_config();
lcd_init(); //send initial commands
command_write(0x80);
lcd_stringout(d1);
command_write(0xC0);
lcd_stringout(d2);

delay(100);

while(1)
{
GPIOC->ODR = 0x0001;
xbee_tx();
GPIOD->ODR = 0x0<<8;

}
}

//////////////////////// Interrupt \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

void USART2_IRQHandler(void)
{
/* receiver interrupt
check if the USART2 receive interrupt flag was set*/

if(USART_GetITStatus(USART2, USART_IT_RXNE) )
{
char k = USART2->DR; // the character from the USART2 data register is saved in t
GPIOD->ODR = k<<8;
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Reciver");
command_write(0xc8);

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 107


GPIOC->ODR = 0x0001;

if(k == 0x30)
{
command_write(0xc3);
lcd_stringout("Relay");
GPIOC->ODR = 0x0201; //relay on
delay(10000);
GPIOC->ODR = 0x0001; //relay off
delay(10000);
}
else if(k == 0x31)
{
command_write(0xc0);
lcd_stringout("Steeper_M_ck");
for(i=0;i<56;i++)
{
GPIOB->ODR = 0x9000;
delay(500);
GPIOB->ODR = 0x5000;
delay(500);
GPIOB->ODR = 0x6000;
delay(500);
GPIOB->ODR = 0xA000;
delay(500);
}
}
else if(k == 0x32)
{
command_write(0xc0);
lcd_stringout("Steeper_M_A-ck");
for(i=0;i<56;i++)
{
GPIOB->ODR = 0xA000;
delay(500);
GPIOB->ODR = 0x6000;
delay(500);
GPIOB->ODR = 0x5000;
delay(500);
GPIOB->ODR = 0x9000;
delay(500);
}
}
else if(k == 0x33)
{
lcd_stringout("3");

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 108


}
else if(k == 0x34)
{
lcd_stringout("4");
}
else if(k == 0x35)
{
command_write(0xc4);
lcd_stringout("BUZZER_ON");
GPIOC->ODR = 0x0000; //BUZ on
delay(10000);
GPIOC->ODR = 0x0001;//BUZ off
command_write(0xc4);
lcd_stringout("BUZZER_OFF");
delay(3000);

}
else if(k == 0x36)
{
lcd_stringout("6");
}
else if(k == 0x37)
{
lcd_stringout("7");
}
else if(k == 0x38)
{
lcd_stringout("8");
}
else if(k == 0x39)
{
lcd_stringout("9");
}
else if(k == 0x41)
{
lcd_stringout("A");
}
else if(k == 0x42)
{
lcd_stringout("B");
}
else if(k == 0x43)
{
lcd_stringout("C");
}
else if(k == 0x44)

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 109


{
lcd_stringout("D");
}
else if(k == 0x45)
{
lcd_stringout("E");
}
else if(k == 0x46)
{
lcd_stringout("F");
}
delay(1000);
}
}

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 110


RESULT

Thus the output data is viewed in the Personal computer by transmitting data via Xbee.

Prepared By: N.JEEVA, AP (Dept Of ECE) Page 111

You might also like