You are on page 1of 49

MAHENDRACOLLEGE OF ENGINEERING

SALEM CAMPUS
MINNAMPALLI, SALEM – 636 106.

DEPARTMENT OF ELECTRONICS ANDCOMMUNICATION


ENGINEERING

EC8711 – EMBEDDED LABORATORY


(2017-Regulation)

RECORD
IV YEAR / VII SEMESTER
Name :

Roll No :

Reg. No :
MAHENDRA
COLLEGE OF ENGINEERING
Attur main Road, Minnampalli(Po)
Salem-636 106.

Department of
--------------------------------------------------------------------------
--------------------------------------------------------------------
Laboratory Record
Certified to be the bonafide record of work done by
____________________________________________________________ at
________________________________________________ Laboratory
during 20____ 20____

His/Her University Register Number is _______________________

Head of the Department Staff-In-Charge

Date:
Submitted for the Practical Examination conducted during __________at ________

Internal Examiner External Examiner


INDEX
EXP. PAGE SIGNATURE OF
NAME OF THE EXPERIMENTS MARKS
NO NO. THE STAFF

SIGNATURE OF THE STAFF MARKS (OUT OF _________)


Exp.No: Study of ARM Evaluation System

Aim

To learn about the evolution, core features, general characteristics and applications of
ARM processors.

Theory
The VSK – STM4 syllabus board is a demonstration and development platform for the
STM32F4 series and includes an embedded STM32F407VG high-performance ARM
Cortex-M4 32-bit microcontroller. The full range of hardware features on the board is
provided to help you evaluate all peripherals (Ethernet, motor control, CAN, USART
etc.) and develop your own applications. Extension headers make it possible to easily
connect a daughterboard or wrapping board for your specific application.

Features
Core: ARM® 32-bit Cortex®-M4 CPU with FPU, Adaptive real-time accelerator
(ART Accelerator™) allowing 0-wait state execution from Flash memory,
frequency up to 168 MHz, memory protection unit, 210 DMIPS/ 1.25
DMIPS/MHz (Dhrystone 2.1), and DSP instructions
Memories
– Up to 1 Mbyte of Flash memory
– Up to 192+4 Kbytes of SRAM including 64- Kbyte of CCM (core coupled
memory) data RAM
– Flexible static memory controller supporting Compact Flash, SRAM,
PSRAM, NOR and NAND memories
LCD parallel interface, 8080/6800 modes
Clock, reset and supply management
– 1.8 V to 3.6 V application supply and I/Os
– POR, PDR, PVD and BOR
– 4-to-26 MHz crystal oscillator
– Internal 16 MHz factory-trimmed RC (1% accuracy)
– 32 kHz oscillator for RTC with calibration
– Internal 32 kHz RC with calibration
Low-power operation
– Sleep, Stop and Standby modes
– VBAT supply for RTC, 20×32 bit backup registers + optional 4 KB backup
SRAM
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
Up to 17 timers: up to twelve 16-bit and two 32- bit timers up to 168 MHz, each
with up to 4 IC/OC/PWM or pulse counter and quadrature (incremental) encoder
input
Debug mode
– Serial wire debug (SWD) & JTAG interfaces
– Cortex-M4 Embedded Trace Macrocell™
Up to 140 I/O ports with interrupt capability
– Up to 136 fast I/Os up to 84 MHz
– Up to 138 5 V-tolerant I/Os
Up to 15 communication interfaces
– Up to 3 × I2C interfaces (SMBus/PMBus)
– Up to 4 USARTs/2 UARTs (10.5 Mbit/s, ISO 7816 interface, LIN, IrDA,
modem control)
– Up to 3 SPIs (42 Mbits/s), 2 with muxed full-duplex I2S to achieve audio
class accuracy via internal audio PLL or external clock
– 2 × CAN interfaces (2.0B Active)
– SDIO interface
Advanced connectivity
– USB 2.0 full-speed device/host/OTG controller with on-chip PHY
– USB 2.0 high-speed/full-speed device/host/OTG controller with dedicated
DMA, on-chip full-speed PHY and ULPI
– 10/100 Ethernet MAC with dedicated DMA: supports IEEE 1588v2
hardware, MII/RMII
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.

ARCHITECTURAL OVERVIEW

In STM32F405xx/07xx and STM32F415xx/17xx, the main system consists of 32-bit


multilayer AHB bus matrix that interconnects: The main system consists of 32-bit
multilayer AHB bus matrix that interconnects:
Eight masters:
– Cortex® -M4 with FPU core I-bus, D-bus and S-bus
– DMA1 memory bus
– DMA2 memory bus
– DMA2 peripheral bus
– Ethernet DMA bus
– USB OTG HS DMA bus
Seven slaves:
– Internal Flash memory ICode bus
– Internal Flash memory DCode bus
– Main internal SRAM1 (112 KB)
– Auxiliary internal SRAM2 (16 KB)
– AHB1 peripherals including AHB to APB bridges and APB peripherals
– AHB2 peripherals
– FSMC
The bus matrix provides access from a master to a slave, enabling concurrent access and
efficient operation even when several high-speed peripherals work simultaneously. The
64- Kbyte CCM (core coupled memory) data RAM is not part of the bus matrix and can
be accessed only through the CPU.
BLOCK DIAGRAM
Result

Exp.No: PROGRAM FOR ADC and DAC

AIM:
To write a Embedded C program to convert analog to digital and interface in ARM
processor

Software Used:
o IAR embedded workbench
o Win X Talk
o Stm Link Utility

Hardware Used:
 ARM Processor cortex M4
 Data cable
 Power cable

Program:

/*Header Files*/
#include "stm32f4xx.h"
#include <stdio.h>

/*Declarations*/
int ConvertedValue = 0;

/*Function to Configure ADC*/


void adc_configure()
{
RCC->APB2ENR |= 1<<10; //The ADC3 is connected the APB2 peripheral bus
RCC->AHB1ENR |= 1<<0; //ADC is connected with PORTA!
GPIOA->MODER |= 0x0000000F; //analog mode PA1,PA2
ADC3->CR2 = 0x00000003; //data right alignment, continuous conversion mode.
ADC3->SMPR2 = 0x00000030; //ADC3 channel-1 with 144 cycles
ADC3->SQR3 = 0x00000001; //rank1 to ADC3 channel-1
}

/*Function to configure DAC*/


void dac_configure()
{
RCC->APB1ENR |= 0x20000000; // Enable clock for DAC
DAC->CR |= 0x00000001; // DAC control reg, both channels ON
GPIOA->MODER |= 0x00000f00; // MODE Register PortA, PA4 & PA5 are analog!
}

/*Functoin to convert ADC*/


int adc_convert()
{
ADC3->CR2 |= 0x40000000; //Start of Conversion
while(! (ADC3->SR & 0x0002) ); //Wait for End Of Conversion
return ADC3->DR;
}

/*Function to Configure USART2*/


void USART2_config()
{
RCC->AHB1ENR |= 1 << 0; //clock to portA
RCC->APB1ENR |= 1 <<17; //clock to USART2
GPIOA->MODER |= 0x000000A0; //alternate function mode(PA2,PA3)
GPIOA->AFR[0] |= 0x00007700; //USART2 RX, TX
USART2->BRR = 0x16D; //115200 baud rate
USART2->CR1 = 0x200C; //Enable Transmission
}

/*Main Routine*/
int main(void)
{
USART2_config();
adc_configure();
dac_configure();
while(1)
{
ConvertedValue = adc_convert(); //Read the ADC converted value
printf("\n\r ADC value => %d",ConvertedValue); //print the ADC value
DAC->DHR12R1 =ConvertedValue; //Move the Digital value to DAC
}
}

int putchar(int data)


{
USART2->DR = (data & 0x01FF);
while((USART2->SR & 0x40) ==0)// Loop until the end of transmission
{}
return data;
}}RESULT:
Thus the program has been build and implemented in ARM processor kit

Exp.No: PROGRAM FOR PWM LED CONTROL

AIM:
To write a Embedded C program to control the LED using pulse width modulation
which interface in ARM processor

Software Used:
o IAR embedded workbench
o Win X Talk
o Stm Link Utility

Hardware Used:
 ARM Processor cortex M4
 Data cable
 Power cable

Program:

/*Header Files*/
#include "stm32f4xx.h"

/*Declarations*/
static int duty_cycle = 1 ;
int duty;

/*Fuction to configure increment and decrement switch*/


void switch_config(void)
{
RCC->AHB1ENR |= (1 << 4 ); // enable the clock to portE
GPIOE->MODER |= 0x00000000; //set portE as i/p mode
GPIOE->OSPEEDR = 0xAAAAAAAA; //Speed 50MHz
}

/*Function for delay*/


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

/*Function to configure Timer3*/


void TIM3_Config(void)
{
RCC->APB1ENR |= (1 << 1); // clock for TIM3
RCC->AHB1ENR |= (1 << 2); //Clock for PORTC, Timer3 Channel is connected with PORTC
GPIOC->MODER |= 0x0000A000;//Alternate fuction mode
GPIOC->AFR[0] |= 0x22000000;//TIM3 Fuction
}
/*Function to read the switch*/
int switch_read()
{
int val;
val = ((GPIOE->IDR)&0x14); //Read PORTE
if(val == 0x10) //if decrement switch is pressed
{
if(duty_cycle <= 0)
duty_cycle =1;
duty_cycle--; //variable decrement
delay(1000);
}
else if(val == 0x04) //If increment switch is pressed
{
duty_cycle++; //variable increment
delay(1000);
if(duty_cycle >= 1500)
duty_cycle =1500;
}
return(duty_cycle); //return the value of the duty cycle
}

/* main functions */
int main(void)
{
TIM3_Config(); //Timer3 Configurations
switch_config(); //switch configuration
TIM3->ARR = 0x348; //25khz, Auto reload register
TIM3->PSC = 0; //Prescale register
TIM3->CCMR1 = (1 << 3); //enable channel1 preload register
TIM3->CCMR1 = (1 << 11); //enable channel2 preload register
TIM3->CR1 = (0 << 8 )| (0 << 9 );//Clock Division, Internal Clock
TIM3->CCMR1 |=(1 << 4) | (1 << 5 ) | (1 << 6 ); //PWM Mode for Channel 1
TIM3->CCMR1 |= (1 << 12 )| (1 << 13 ) | (1 << 14 ); //PWM mode for Channel 2
while(1)
{
duty = switch_read(); //receive switch value
TIM3->CCR1 = duty; // apply duty cycle
TIM3->CCER |= ( 1 << 0 ) | ( 1 << 1 ); //enable channel 1
TIM3->CCR2 = duty; //apply duty cycle
TIM3->CCER |= (1 << 4 ) | (1 << 5 ); //enable channel 2

TIM3->CR1 |= ( 1 << 0 ); //Enable Counter


}
}
RESULT:

Exp.No: PROGRAM FOR REAL TIME CLOCK

AIM:
To write a Embedded C program for real time clock and interface in ARM
processor

Software Used:
o IAR embedded workbench
o Win X Talk
o Stm Link Utility

Hardware Used:
 ARM Processor cortex M4
 Data cable
 Power cable

Program:

/*Header Files*/
#include "stm32f4xx.h"
#include "stdio.h"

/*Prototype Declarations*/
void USART2_config();
void delay();
unsigned char *days[8]={"Sunday","Monday","Tuesday","wednesdat","Thursday","Friday","Saturday"};
unsigned int time, date, sec,min,hr,date,day,month,year,temp;

/*Fuction to Configure Serial Port*/


void USART2_config()
{
RCC->AHB1ENR |= 1 << 0; //Serial port is conncted in PortA
RCC->APB1ENR |= 1 <<17; //Clock for USART2

GPIOA->MODER |= 0x000000A0; //Alternate mode of PORTA


GPIOA->AFR[0] |= 0x00007700; //USART mode

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


USART2->CR1 = 0x200C; //Enable transmission and reception
}

/*Function to write a character in the serial port*/


int putchar(int data)
{
USART2->DR = (data & 0x01FF);
while((USART2->SR & 0x40) ==0)
{}
return data;
}

/*Function to Configure RTC*/


void RTC_config()
{
RCC->APB1ENR |= 1<<28;//Enable PWREN,Clock to Power
RCC->AHB1ENR |= 1<<18;//Enable BKPEN, Clock to Backup Access
PWR->CR |= 1<<8; //Enable Backup Access
RTC->WPR = 0xCA; //Write Protect Register, Key
RTC->WPR = 0x53;
RCC->CSR |=1<<0; //LSION bit, Internal Clock for RTC
while(((RCC->CSR)&0x00000002)==0x00000000); //Wait till LSI Ready
RCC->BDCR |= (1<<9)|(0<<8); //RTC Clock Selection, LSI
RCC->BDCR |= 1<<15; //RTC Enable
RTC->ISR |=1<<7; //INIT Bit ON,Enter Initialization Mode
while(((RTC->ISR)&0x00000040)==0x00000000); //Wait till INITF set
RTC->TR = 0x00092000; //Set the time, Time is 9:20:00
RTC->DR = 0x0016C820; //Set the date, Date is 20/8/16, Saturday
RTC->ISR |=0<<7; //INIT Bit Off,Exit Initialization Mode
RTC->WPR = 0xFF; //Enable Write Protection
}

/*Delay Routine*/
void delay()
{
for(int i=0;i<300;i++)
for(int j=0;j<100000;j++);
}

/*Main Routine*/
int main(void)
{
USART2_config();
printf("\n welcome to RTC");
RTC_config();

RCC->APB1RSTR |=1<<28; //Reset the Power


//RTC->DR = 0x0016B820; //Date is 20/8/16, Saturday
RTC->CR |=1<<5; //BYPSHAD Bit
while(1)
{
while(((RTC->ISR)&0x00000020)==0x00000000); //Wait till RSF flag is set
temp = RTC->DR;
date = temp & 0x0000003F; //Mask Date bits
month= (temp & 0x00001F00)>>8; //Mask Month Bits
day = (temp & 0x0000E000)>>13; //Mask Day Bits
year = (temp & 0x00FF0000)>>16; //Mask Year Bits
printf("\n\r Date %x:%x:%x",date,month,year);
printf(" %s ",days[day]);
time = RTC->TR;
sec = time & 0x0000007F; //Mask Seconds bits
min = (time & 0x00007F00)>>8; //Mask Minutes Bits
hr = (time & 0x001F0000)>>16; //Mask Hour Bits
printf(" Time is %x:%x:%x", hr,min,sec);
delay();
}
}

RESULT:

Exp.No: PROGRAM FOR KEYPAD AND LCD


AIM:
To write a Embedded C program to interface keypad and LCD in ARM processor
Software Used:
o IAR embedded workbench
o Win X Talk
o Stm Link Utility

Hardware Used:
 ARM Processor cortex M4
 Data cable
 Power cable

Program:
/*Header Files*/
#include "stm32f4xx.h"

/*ptototype functions */
void delay(int a);
void pinout_config(void);
void command_write(int comm);
void lcd_out(unsigned int a);
void Row1_check();
void Row2_check();
void Row3_check();
void Row4_check();

int val;

/*Main Routine*/
void main(void)
{
pinout_config(); //Pinout Configurations
command_write(0x38); //Function Set
command_write(0x01); //Clear Display
command_write(0x0C); //Cursor Off,0x0F for Cursor on
command_write(0x06); //Address auto increment
while (1)
{
command_write(0x87); //Choose Address 87
Row1_check(); //Check which key is pressed in the Rows
Row2_check();
Row3_check();
Row4_check();
}
}

/*Function to check the key in Row1*/


void Row1_check()
{
/*1 st row */
GPIOD->BSRRH = 0x0001; //low PD0
GPIOD->BSRRL = 0x000E; //high PD1 to PD3
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
lcd_out('C');
else if(val== 0xD0) //2nd column
lcd_out('D');
else if(val== 0xB0) //3rd column
lcd_out('E');
else if(val== 0x70) //4th column
lcd_out('F');
}

/*Function to check the key in Row2*/


void Row2_check()
{
/*2nd row */
GPIOD->BSRRH = 0x0002; //low PD1
GPIOD->BSRRL = 0x000D; //high PD0,PD2,PD3
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
lcd_out('8');
else if(val== 0xD0) //2nd column
lcd_out('9');
else if(val== 0xB0) //3rd column
lcd_out('A');
else if(val== 0x70) //4th column
lcd_out('B');
}

/*Function to check the key in Row3*/


void Row3_check()
{
/*3rd row */
GPIOD->BSRRH = 0x0004; //low PD2
GPIOD->BSRRL = 0x000B; //high PD0,PD1,PD3
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
lcd_out('4');
else if(val== 0xD0) //2nd column
lcd_out('5');
else if(val== 0xB0) //3rd column
lcd_out('6');
else if(val== 0x70) //4th column
lcd_out('7');
}

/*Function to check the key in Row4*/


void Row4_check()
{
/*4th row*/
GPIOD->BSRRH = 0x0008; //low PD3
GPIOD->BSRRL = 0x0007; //high PD0,PD1,PD2
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
lcd_out('0');
else if(val== 0xD0) //2nd column
lcd_out('1');
else if(val== 0xB0) //3rd column
lcd_out('2');
else if(val== 0x70) //4th column
lcd_out('3');
}

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

void command_write(int comm)


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

/*Function to write a data to be displayed in the LCD*/


void lcd_out(unsigned int a)
{
delay(200);
GPIOE->BSRRL = 0x0020; //high RS pin
GPIOE->ODR = (a<<8)|(1<<5); //write the data from 8th bit.(i.E) PD8 to PD15
GPIOE->BSRRL = 0x0080;//enable pin high
delay(200);
GPIOE->BSRRH = 0x0080;//enable pin low
}

/*Function to configure the GPIO*/


void pinout_config(void)
{
RCC->AHB1ENR |= 1<<3; // enable the clock to portD,
RCC->AHB1ENR |= 1<<4; //enable clock to portE
GPIOD->MODER |=0x00000055; //set port PD0-PD3 as o/p mode
GPIOE->MODER = 0X55555500; // lcd_pins PE4 to PE15 output pins
}

RESULT:

Exp.No: PROGRAM FOR EEPROM READ

AIM:
To write a Embedded C program to read the data in EEPROM and interface in
ARM processor

Software Used:
o IAR embedded workbench
o Win X Talk
o Stm Link Utility

Hardware Used:
 ARM Processor cortex M4
 Data cable
 Power cable

Program:
/*Header Files*/
#include "stm32f4xx.h"
#include "stdio.h"

/*Definitions*/
#define SLAVE_ADDRESS1 0xA6 // the EEPROM address for write
#define SLAVE_ADDRESS2 0xA7 // the EEPROM address for read

/* prototype functions */
void I2C_stop();
void I2C_write(uint8_t data);
void I2C_start(uint8_t address);
void init_I2C1();
void Delay(int t);
void USART2_config();
int EEPROM_read(uint16_t address);
void EEPROM_write(uint16_t address,uint8_t value);
void TIM2_Config(void);
void TIM2_IRQHandler();
void switch_config(void);

unsigned int address,count;

/*Main Routine*/
int main(void)
{
int val;
USART2_config();
printf("\n\rInterfacing EEPROM and Interrupt");
switch_config();
init_I2C1();
address=0x0000;
EEPROM_write(address,0);
TIM2_Config();
while(1)
{
val = ((GPIOE->IDR)&0x14); //Read PORTE
if(val == 0x10) //if decrement switch is pressed
{
if(count==0)
count=0;
else
count=count-1;
NVIC->ISER[0] |= (0<<28); //Interrupt Disable
EEPROM_write(address,count); //write the count value in the EEPROM
NVIC->ISER[0] |= (1<<28); //Interrupt Enable
while(((GPIOE->IDR)&0x04)==0x00); //wait till the key is released
}
else if(val == 0x04) //If increment switch is pressed
{
count=count+1;
if(count>=255)
{
count=0;
address=address+1;
}
NVIC->ISER[0] |= (0<<28); //Interrupt Disable
EEPROM_write(address,count);
NVIC->ISER[0] |= (1<<28); //Interrupt Enable
while(((GPIOE->IDR)&0x10)==0x00); //wait till the key is released
}
}
}

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

/*Function to read the EEPROM through I2C*/


int EEPROM_read(uint16_t address)
{
int value,LSB,MSB;
LSB=address&0x00FF; //Split the MSByte and LSByte of the Address
MSB=(address&0xFF00)>>8;
I2C_start(SLAVE_ADDRESS1); // I2C start to write
I2C_write(LSB); //Write EEPROM lSB address
I2C_write(MSB); //Write EEPROM MSB address
Delay(200);
I2C_stop(); //I2C Stop
Delay(200);
I2C_start(SLAVE_ADDRESS2); // I2C Start to read
Delay(200);
value = I2C1->DR; //read the data
I2C_stop();
Delay(500);
return(value);
}

/*Function to wrie the data into EEPROM through I2C*/


void EEPROM_write(uint16_t address,uint8_t value)
{
int LSB,MSB;
LSB=address&0x00FF;
MSB=(address&0xFF00)>>8;
I2C_start(SLAVE_ADDRESS1); // I2C start
I2C_write(LSB); //Write LSB address
I2C_write(MSB); //Write MSB address
I2C_write(value); //send data to the address
I2C_stop();
Delay(500);
}

/*Fuction to Configure Serial Port*/


void USART2_config()
{
RCC->AHB1ENR |= 1 << 0; //Serial port is conncted in PortA
RCC->APB1ENR |= 1 <<17; //Clock for USART2
GPIOA->MODER |= 0x000000A0; //Alternate mode of PORTA
GPIOA->AFR[0] |= 0x00007700; //USART mode
USART2->BRR = 0x16D; //115200 baud rate
USART2->CR1 = 0x200C; //Enable transmission and reception
}

/*Function to write a character in the serial port*/


int putchar(int data)
{
USART2->DR = (data & 0x01FF);
while((USART2->SR & 0x40) ==0)
{}
return data;
}

/*Function to Initialize I2C*/


void init_I2C1()
{
RCC->AHB1ENR |= 1<<1; //CLK to port B,SCL and SDA lines are connectedto portB
RCC->APB1ENR |= 1<<21; // CLK to I2C1
GPIOB->MODER = 0x00082000; //Alternate Function
GPIOB->AFR[0] = 0x04000000; //I2C Function PB6 & PB9 =>i2c pins (SDA,SCL)
GPIOB->AFR[1] = 0x00000040;
GPIOB->OTYPER = 0xFFFFFFFF; //open drain
GPIOB->OSPEEDR =0xAAAAAAAA; //50 MHZ
GPIOB->PUPDR = 0x55555555; //pull up

I2C1->OAR1 |=0x0000; //Own Address Register


I2C1->CR1 |=(0<<10)|(0<<0); //Disable I2C and acknowledgement
I2C1->CR2 |=0x08; //Standard Mode,100kHz
I2C1->CCR |=0x28; //Clock Control Reister
I2C1->TRISE = 0x09; //Rise Time
I2C1->CR1 |=0x0001; //Enable I2C Peripheral
}

/*Function to start and write the slave address*/


void I2C_start(uint8_t address)
{
while(((I2C1->SR2)&0x0002)==0x0002); //Check the bus is free or not
I2C1->CR1 |=(1<<8); //Generate START condition
while(((I2C1->SR1)&0x0001)==0x0000); //Wait for start condition to get over

I2C1->DR = address; //Write the slave address


while(((I2C1->SR1)&0x0002)==0x0000); //ADDR flag is reset
while(((I2C1->SR2)&0x0002)==0x0000); //BUSY flag is reset
}

/*Function to write the data to the slave device*/


void I2C_write(uint8_t data)
{
I2C1->DR = data; //Move the value to I2C data register
while(((I2C1->SR1)&0x0004)==0x0000); //Wait until the byte get transferred
}

/*Function for STOP condition*/


void I2C_stop()
{
I2C1->CR1 |=(1<<9); //Generate STOP condition
}

/*Function to configure Timer2*/


void TIM2_Config(void)
{
RCC->APB1ENR |= (1 << 0); // clock for TIM
TIM2->PSC = 0; //Timer prescalar

TIM2->CNT = 0xE6F4BE7C; //Load the value for 5 seconds


TIM2->DIER |=(1<<0); //Interrupt Enable Register
TIM2->EGR |=(1<<0); //Event Generation
TIM2->CR1 |=(1<<0); //Enable Timer for counting

NVIC->STIR = 28; //Interrupt number for TIM2


NVIC->ISER[0] |= (1<<28); //Interrupt Enable
NVIC->IP[7] = 0; //Interrupt Priority
}

void TIM2_IRQHandler()
{
int value;
TIM2->SR = 0x0000; //Clear the flag
value = EEPROM_read(address); //read EEPROM
printf("\n\rThe value at address %d is %x",address,value);
TIM2->CNT = 0xE6F4BE7C;
}

/*Fuction to configure increment and decrement switch*/


void switch_config(void)
{
RCC->AHB1ENR |= (1 << 4 ); // enable the clock to portE
GPIOE->MODER |= 0x00000000; //set portE as i/p mode
GPIOE->OSPEEDR = 0xAAAAAAAA; //Speed 50MHz
}

RESULT:
Thus the program has been build and implemented in ARM processor kit

INTERRUPT PERFORMANCE OF ARM AND FPGA

INTERRUPT PERFORMANCE IN ARM


AIM:
To write a Embedded C program check the performance of interrupt in ARM
processor

Software Used:
o IAR embedded workbench
o Win X Talk
o Stm Link Utility

Hardware Used:
 ARM Processor cortex M4
 Data cable
 Power cable

Program:

/*Header Files*/
#include "stm32f4xx.h"

/*Prototype Declarations*/
void PC7_Config(void);
void EXTI9_5_IRQHandler(void);

/*Function to configure LEDs*/


void LED_config()
{
RCC->AHB1ENR |= 1 <<3; //Clock to PORTD
GPIOD->MODER |= 0x55555555; //Input Mode
GPIOD->OSPEEDR = 0xFFFFFFFF; //Speed 100MHz
}

/*Delay Routine*/
void delay(long int a)
{
long int b,c;
for(b=0;b<a;b++)
for(c=0;c<a;c++);
}

/*Main Routine*/
int main(void)
{
LED_config();
PC7_Config();
while (1)
{
GPIOD->ODR =0x00000F00; //leds turns ON
}
}

void PC7_Config(void)
{
RCC->AHB1ENR |= (1<<2); //clock for PORTC
RCC->APB2ENR |=(1<<14); //clock for syscfg
GPIOC->MODER = 0X00000000; //PORTC input mode
GPIOC->PUPDR = 0X55555555; //PORTC pullup
SYSCFG->EXTICR[1]=0X00002000; //Enable EXTI7
EXTI->IMR |=1<<7; //Interrupt Mask
EXTI->FTSR |=1<<7; //Falling Edge Trigger
NVIC->IP[5] = 0X000000000; //Interrupt Priority
NVIC->ISER[0] |=1<<23; //Interrupt Service
}

/*Interrupt Service Routine for EXTI7*/


void EXTI9_5_IRQHandler(void)
{
GPIOD->ODR =0x00000000; //leds turns OFF
delay(1000); //delay
EXTI->PR |= (1<<7); //Clear pending bit
}

RESULT:

Exp.No: PROGRAM FOR LED


AIM:
To write a Embedded C program to flash the LED and interface in ARM processor
Software Used:
o IAR embedded workbench
o Win X Talk
o Stm Link Utility

Hardware Used:
 ARM Processor cortex M4
 Data cable
 Power cable

Program:

/*Header Files*/
/*Header Files*/
#include"stm32f4xx.h"

/*Delay Function*/
void delay()
{
long int i;
for(i=0;i<9000000;i++);
}

/*Function to Initialize LED*/


void led_init()
{
RCC->AHB1ENR = 1<<3; //enable clock for port D
GPIOD->MODER = 0X00550000; //enable pD8,pD9,pD10,pD11 as output mode
}

/*Main Routine*/
void main()
{
led_init();
while(1)
{
GPIOD->ODR = 0X0F00;
delay();
GPIOD->ODR = 0X0000;
delay();
}
}
RESULT:

PROGRAM FOR STEPPER MOTOR


AIM:
To write a Embedded C program for rotating stepper motor and interface in ARM
processor

Software Used:
o IAR embedded workbench
o Win X Talk
o Stm Link Utility

Hardware Used:
 ARM Processor cortex M4
 Data cable
 Power cable

Program:

/*Header Files*/
#include "stm32f4xx.h"
#include <stdio.h>

static int i=0;


__IO uint32_t uhADCxConvertedValue = 0;

/* private prototype functions*/


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

/*Delay Function for Stepper motor*/


void delay()
{
long int i;
for(i=0;i<300000;i++);
}

/*Function to configure USART2*/


void USART2_config()
{
RCC->AHB1ENR |= 1 << 0; //clock to portA
RCC->APB1ENR |= 1 <<17; //clock to USART2

GPIOA->MODER |= 0x000000A0; //alternate function mode(PA2,PA3)


GPIOA->AFR[0] |= 0x00007700; //USART2 AF
USART2->BRR = 0x16D; //115200 baud rate
USART2->CR1 = 0x200C;
}

/*Function to configure ADC*/


void adc_configure()
{
RCC->APB2ENR |= 1<<10; //The ADC3 is connected the APB2 peripheral bus
RCC->AHB1ENR |= 1<<0; //Clock for the ADC port!! Do not forget about this one ;)
GPIOA->MODER |= 0x0000000F; //analog mode PA1,PA2
ADC3->CR2 = 0x00000003; //data right alignment,continuous conversion mode.
ADC3->SMPR2 = 0x00000030; //ADC3 channel-1 with 144 cycles
ADC3->SQR3 = 0x00000001; //rank1 to ADC3 channel-1
}

/*Function to convert the ADC input to Digital*/


int adc_convert()
{
ADC3->CR2 |= 0x40000000;
while(! (ADC3->SR & 0x0002) ); //Check whether the conversion completed or not
return ADC3->DR;
}

/*Function to write a data to serial port*/


int putchar(int data)
{
USART2->DR = (data & 0x01FF);
while((USART2->SR & 0x40) ==0)
{}
return data;
}

/*Function to configure motor Pins*/


void motor_PIN_config(void)
{
RCC->AHB1ENR |= 1<<1; //Motor is connected to PORTB
GPIOB->MODER = 0x55000000; //PORTB as output
}

/*Nain Routine*/
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;
k =temp*3.3;
k /=4095;
k *=100;
printf("\n Temperature = %3.2f°C",k);
if(k >40) //if temperature > 40
{
anticlock_wise();
delay();
}
else if(k <40)//if temperature < 40
{
clock_wise();
delay();
}
}
}

/*Function to rotate the motor in the anto-clock wise direction*/


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

/*Function to rotate the motor in the clock wise direction*/


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

.
PROGRAM FOR XBEE TRANMISSION
AIM:
To write a Embedded C program to transmit the date in wireless medium by
interfacing with ARM processor

Software Used:
o IAR embedded workbench
o Win X Talk
o Stm Link Utility

Hardware Used:
 ARM Processor cortex M4
 Data cable
 Power cable

Program:

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

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; // we want 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++)
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;
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 portF
RCC->AHB1ENR |= 1<<4; //enable clock to portB,C,G
RCC->AHB1ENR |= 1<<2; //enable clock to portB,C,G
RCC->AHB1ENR |= 1<<1; //Enable clock to portB

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 = 0x00050000; //PC9 as o/p mode


GPIOC->PUPDR = 0xAAAAAAAA; //no pull-up,pull-down
GPIOC->OSPEEDR = 0xAAAAAAAA; //spedd is 50MHZ

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

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

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


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

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);
}
/////////////////////////// 2 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
{
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);
}
/////////////////////////// 3 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");
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);
}
/////////////////////////// 4 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("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;
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)
{
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);
if(k == 0x30)
{
command_write(0xc3);
lcd_stringout("Relay");
GPIOC->ODR = 0x0200; //relay on
delay(500);
GPIOC->ODR = 0x0000; //relay off
}
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");}
else if(k == 0x34){
lcd_stringout("4");}
else if(k == 0x35){
lcd_stringout("5");}
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){
lcd_stringout("D");}
else if(k == 0x45){
lcd_stringout("E");}
else if(k == 0x46){
lcd_stringout("F");}
delay(1000);
}
}

RESULT:

Exp.No: MAIL BOX


AIM:
To write a Embedded C program to transmit the date in wireless medium by
interfacing with ARM processor

Software Used:
o IAR embedded workbench
o Win X Talk
o Stm Link Utility

Hardware Used:
 ARM Processor cortex M4
 Data cable
 Power cable

PROGRAM:

/*Header Files*/
#include "ucos_ii.h"
#include "bsp.h"

/*Define the Stack Size*/


#define TASK_STK_SIZE 128

/*Define the Tasks*/


OS_STK AppStk_send[TASK_STK_SIZE];
OS_STK AppStk_recv[TASK_STK_SIZE];

/*Prototype Declarations*/
static void Mailbox_App_Tx(void *p_arg);
static void Mailbox_App_Rx(void *p_arg);

OS_EVENT *pmailbox;

/*Function to Configure USART2*/


void USART2_config()
{
RCC->AHB1ENR |= 1 << 0; //clock to portA
RCC->APB1ENR |= 1 <<17; //clock to USART2

GPIOA->MODER |= 0x000000A0; //alternate function mode(PA2,PA3)


GPIOA->AFR[0] |= 0x00007700; //USART2 AF

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


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

/*Function to write a character in the serial port*/


int putchar(int data)
{
USART2->DR = (data & 0x01FF);
while((USART2->SR & 0x40) ==0)
{}
return data;
}

/*Main Routine*/
int main(void)
{
BSP_IntDisAll();

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


RCC_ClocksTypeDef rcc_clocks;
RCC_GetClocksFreq(&rcc_clocks); //Configure Clocks

SysTick_Config(rcc_clocks.HCLK_Frequency/OS_TICKS_PER_SEC);

OSInit(); //ucosii initialization


USART2_config();
BSP_Init(); //board support package initialization

OSStatInit(); //DetermineCPUcapacity.

//TODO:create application tasks with Task Interval


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

p_arg = p_arg;
pmailbox=OSMboxCreate(NULL);

for (i=0;i<4;)
{
if((err=OSMboxPost(pmailbox,buffer[i]))==NO_ERROR) //if success
{
printf("\n\rThis is sender \n\t post data to Mailbox,data is-->%s",buffer[i]);
i++;
}
else if(err== MAILBOX_FULL) //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");
OSTimeDlyHMSM(0, 0, 5, 0);
}
OSTimeDlyHMSM(0, 0, 5, 0);
OSMboxDel (pmailbox,OS_DEL_NO_PEND, &err);
if(err==OS_ERR_TASK_WAITING) //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) //if timeout error occured


printf("\n\rTimeout");
else if(err==EVENT_TYPE_ERROR)//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);
}
}

RESULT:

You might also like