Professional Documents
Culture Documents
SALEM CAMPUS
MINNAMPALLI, SALEM – 636 106.
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____
Date:
Submitted for the Practical Examination conducted during __________at ________
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
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;
/*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
}
}
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;
/* 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
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;
/*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();
RESULT:
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();
}
}
void delay(int a)
{
int i,j;
for(i=0;i<a;i++)
for(j=0;j<a;j++);
}
RESULT:
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);
/*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++);
}
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;
}
RESULT:
Thus the program has been build and implemented in ARM processor kit
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);
/*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
}
RESULT:
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++);
}
/*Main Routine*/
void main()
{
led_init();
while(1)
{
GPIOD->ODR = 0X0F00;
delay();
GPIOD->ODR = 0X0000;
delay();
}
}
RESULT:
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>
/*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();
}
}
}
.
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>
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
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
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
}
void lcd_init()
{
command_write(0x38);
command_write(0x01);
command_write(0x0f);
command_write(0xC0);
command_write(0x06);
}
delay(200);
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;
/*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 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
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 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
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 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
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 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
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;
}
}
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:
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"
/*Prototype Declarations*/
static void Mailbox_App_Tx(void *p_arg);
static void Mailbox_App_Rx(void *p_arg);
OS_EVENT *pmailbox;
/*Main Routine*/
int main(void)
{
BSP_IntDisAll();
SysTick_Config(rcc_clocks.HCLK_Frequency/OS_TICKS_PER_SEC);
OSStatInit(); //DetermineCPUcapacity.
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");
}
RESULT: