Embedded Lab Record Edited
Embedded Lab Record Edited
Embedded Lab Record Edited
Experiment 1
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 32bit 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)
Memories
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,
Low-power operation
VBAT supply for RTC, 2032 bit backup registers + optional 4 KB backup
SRAM
312-bit, 2.4 MSPS A/D converters: up to 24 channels and 7.2 MSPS in triple interleaved
mode
212-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
Up to 15 communication interfaces
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
SDIO interface
Advanced connectivity
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
96-bit unique ID
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:
Seven slaves:
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
4
04
Result
The evolution, core features, general characteristics and the applications of ARM
processors has been studied and is evaluated.
Experiment 2
Interfacing ADC and DAC
Aim
To develop a C-Language program for reading an on-chip ADC, convert into decimal and to
display it in PC and to generate a square wave depending on this ADC reading. The ADC input is
connected to any analog sensor/ on board potentiometer.
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and build
the program
4.
Program
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_adc.h"
int ConvertedValue = 0;
void adc_configure()
{
/* Clock configuration */
RCC->APB2ENR |= 1<<10;
will use its clock source */
RCC->AHB1ENR |= 1<<0;
/* Clock for the ADC port!! Do not forget about this one ;) */
0xFFFFFFFF;
GPIOA->PUPDR = 0x00000000;
/* ADC configuration */
ADC3->CR1 = 0x00000000;
ADC3->CR2 = 0x00000002;
ADC3->SQR1 = 0x00000000;
ADC3->CR2 |= 0x00000001;
/* ADC enable */
ADC3->SMPR2 = 0x00000030;
= 0x00000001;
int adc_convert()
{
ADC_SoftwareStartConv(ADC3);
ADC_GetFlagStatus(ADC3, ADC_FLAG_EOC));
ADC_GetConversionValue(ADC3);
}
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0;
/* clock to USART2 */
GPIOA->MODER |= 0x000000A0;
>AFR[0] |= 0x00007700;
USART2->BRR = 0x16D;
int main(void)
{
USART2_config();
adc_configure();
/*Start configuration */
while(1)
{
ConvertedValue = adc_convert();
}
}
DAC
The two 12-bit buffered DAC channels can be used to convert two digital signals into two analog
voltage signal outputs.
This dual digital Interface supports the following features:
two DAC converters: one for each output channel
8-bit or 12-bit monotonic output
left or right data alignment in 12-bit mode
synchronized update capability
noise-wave generation
triangular-wave generation
dual DAC channel independent or simultaneous conversions
DMA capability for each channel
external triggers for conversion
input voltage reference VREF+
Eight DAC trigger inputs are used in the device. The DAC channels are triggered through the timer
update outputs that are also connected to different DMA streams.
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the above code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and build
the program
4.
PROGRAM
#include "stm32f4xx.h"
#include "stm32f4xx_dac.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_syscfg.h"
TIM_TimeBaseStructure;
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);
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
5
05
TIM6_Config();
while (1)
{
DAC_Ch2_TriangleConfig();
}
}
Experiment 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
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and build
the program
4.
Program
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include <stdio.h>
uint16_t PrescalerValue = 0;
static int duty_cycle =1 ;
int duty;
/* 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();
TIM3->ARR =0x348;
/* 21MHZ timer/counter
TIM3->CR1 = 0<<8|0<<9;
TIM3->CCMR1 = 1<<4|1<<5|1<<6;
TIM3->CCER |= 1<<0|1<<1;
duty;
TIM3->CCMR1 = 1<<3;
>CCMR1 = 1<<12|1<<13|1<<14;
TIM3->CCER |= 1<<4|1<<5;
= duty;
TIM3->CCMR1 = 1<<11;
duty_cycle--;
/* variable decrement */
delay(250);
}
else if(val == 0x10)
{
duty_cycle++;
/* variable increment */
delay(250);
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;
1<<4;
GPIOE->MODER |=0x00000000;
GPIOE->OTYPER =0x00000000;
GPIOE->PUPDR = 0x00000000; GPIOE->OSPEEDR =0xAAAAAAAA;
}
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0;
/* AF mode */
Result
The C program to vary the intensity of the LED depending on the duty cycle of the
PWM has been developed and is verified.
5
95
Experiment 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.
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 e very
36 hours
Serial Communication
Serial communication takes a byte of data and transmits the 8 bits in the byte one at a time. The
advantage is that a serial port needs only one wire to transmit the 8 bits (while a parallel port needs
8). The disadvantage is that it takes 8 times longer to transmit the data than it would if there were 8
wires. Serial ports lower cable costs and make cables smaller.
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and build
the program
4.
Program
#include "stm32f4xx.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
#include "misc.h"
#include "stdio.h"
/* prototype functions */
void 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();
I2C_write(I2C1,0x00);
I2C_write(I2C1,0x00);
/*
Delay(500);
while(1)
{
gk_sec = RTC_read(I2C1,0x00);
I2C_write(I2Cx,address);
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);
GPIOB->MODER = 0x00082000;
GPIOB->AFR[0] = 0x04000000;
GPIOB->AFR[1] = 0x00000040;
GPIOB->OTYPER = 0xFFFFFFFF;
=0xAAAAAAAA;
/* pull up */
/* configure I2C1 */
I2C_InitStruct.I2C_ClockSpeed = 100000;
I2C_Mode_I2C;
/* 100kHz */ I2C_InitStruct.I2C_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 */
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));
Result
The C-Language program for reading RTC and displaying it in PC was written &
output is verified with running the RTC from a default/specified time.
Experiment 5
Interfacing Keyboard and LCD
Aim
To develop a C-Language program for displaying the Key pressed in the Keypad in the
LCD module. The display should come in the desired line and column.
Apparatus & Software Required
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
LCD
Liquid crystals are a phase of matter whose order is intermediate between that of a liquid and that of
a crystal. The molecules are typically rod-shaped organic matters about 25
Angstroms in length and their ordering is a function of temperature. The molecular orientation
can be controlled with applied electric fields.
A standard character LCD is probably the most widely used data Visualization component.
Character LCDs are available in various kinds of models.
1. No. Of characters x Lines: 8x1, 16x1, 16x2, 16x4, 20x4, 40x4
2. Color: Yellow, Green, Gray, Blue
The Character LCD communicates with the microcontroller via 8 bit data bus. The pin description
for character LCD is given below.
VCC, GND AND V0 - While VCC and VSS provide +5V and ground, respectively; V0 is used for
controlling LCD contrast.
RS (Register Select) - If RS = 0, the instruction command code register is selected, allowing the user
to send a command such as clear display, cursor at home, etc.
If RS = 1, the data register is selected, allowing the user to send data to be displayed on the LCD.
RW (Read/Write) - RW allows the user to write information to the LCD or read information
from it. RW=1 when reading; RW=0 when writing.
EN (Enable) - The LCD to latch information presented to its data pins uses the enable pin. When
data is supplied to data pins, a high to low pulse must be applied to this pin in order for the LCD to
latch in the data present at the data pins.
D0 D7 - The 8-bit data pins, are used to send information to the LCD or read the contents of the
LCDs internal registers. To display letters and numbers, we send ASCII codes for the letters A-Z, a-z,
and numbers 0-9 to these pins while making RS = 1
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and build
the program
4.
Program
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
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();
}
void Row1_check()
{
/*1 st row */
GPIOD->BSRRH = 0x0001;
= 0x000E;
8
08
val = (GPIOD->IDR)&0xF0;
if(val == 0xE0)
/* status of D4 to D7 */
/* 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);
}
/*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 */
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);
}
/* 2nd column */
{
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;
val = (GPIOD->IDR)&0xF0;
/* status of D4 to D7 */
if(val == 0xE0)
/*1st column */
/* 2nd column */
{
command_write(0x01); command_write(0x80); lcd_stringout("You Pressed =>5"); delay(100);
}
/* 3rd column */
{
/* 4th column */
{
/* 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)
{
command_write(0x01);
/*4th column */
command_write(0x80);
lcd_stringout("You Pressed =>3");
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 RW pin */
}
void command_write(int comm)
{
busy_check();
GPIOE->BSRRH = 0x0020;
GPIOE->ODR = (comm<<8)|(0<<5);
PG15*/
/* low RS pin */
/*write the data from 8th bit.(i.E) PG8 to
GPIOE->BSRRL = 0x0080;
delay(200);
GPIOE->BSRRH = 0x0080;
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);
GPIOE->BSRRL = 0x0080;
delay(200);
GPIOE->BSRRH = 0x0080;
}
GPIOE->BSRRL = 0x0020;
/* high RS pin */
for(i=0;gk[i] !='\0';i++)
{
GPIOE->ODR =( gk[i]<<8)|(1<<5);
GPIOE->BSRRL = 0x0080;
delay(200);
GPIOE->BSRRH = 0x0080;
}
}
void mx_pinout_config(void)
{
/* GPIO_InitTypeDef GPIO_InitStruct; */
/*Enable or disable the AHB1 peripheral clock */
RCC->AHB1ENR |= 1<<3;
1<<4;
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;
>OTYPER = 0x00000000;
GPIOE->PUPDR = 0x00000000; GPIOE->OSPEEDR = 0xAAAAAAAA; GPIOE->ODR
0x00000000;
9
09
Result
The C-Language program for displaying the Key pressed in the Keyboard is displayed in the LCD
module and the output was verified on the LCD on the desires line and column/address.
Experiment 6
Interfacing EEPROM and Interrupt
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 EEPROMs are
used in
broad spectrum of
consumer, automotive,
telecommunication, medical, industrial and PC related markets. Primarily used to store personal
preference data and configuration/setup data, Serial EEPROMs 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
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 5 of How to create a New Project to add the necessary file, compile and build
the program
4. Copy the INC_EEPROM and SRC_EEPROM folders from the existing
EEPROM project and paste it in the current working.
5. Add that folders path into your preprocessor directory.
6. Then add all files from SRC_EEPROM folder
7. Now build the project.
8.
Program
#include "stm32f4xx.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
#include "misc.h"
#include "stdio.h"
/* prototype functions */
int main(void)
{
USART2_config();
printf("\n welcome to EEPROM");
init_I2C1();
int i,gk;
/*EEPROM read operation */
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0; RCC->APB1ENR |= 1 <<17;
USART2->BRR = 0x16D;
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
*/
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
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;
GPIO_Init(GPIOB, &GPIO_InitStruct);
/* init GPIOB */
/* SCL*/
/* configure I2C1 */
I2C_InitStruct.I2C_ClockSpeed = 100000;
I2C_Mode_I2C;
/* 100kHz */ I2C_InitStruct.I2C_Mode =
Disable;
/* init I2C1 */
10
01
/* 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);
{ I2C_write(I2C1,i); Delay(200);
}
I2C_stop(I2C1);
}
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;
0x0000;
USART2->CR2 = 0x000; USART2->CR1 = 0x200C;
}
void init_I2C1()
{
GPIO_InitTypeDef GPIO_InitStruct; I2C_InitTypeDef I2C_InitStruct;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
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;
GPIO_Init(GPIOB, &GPIO_InitStruct);
/* init GPIOB */
/* SCL */
/* SDA */
/* configure I2C1 */
I2C_InitStruct.I2C_ClockSpeed = 100000;
I2C_Mode_I2C;
/* 100kHz */ I2C_InitStruct.I2C_Mode =
/* own address,
Disable;
/* 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));
Result
The C-Language program to write and read a data in EEPROM and also to analyze its performance
with the interrupt is developed and is verified.
11
01
Experiment 7
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.
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.
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 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. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and build
the program.
4. Follow the procedures in How to Download a Code to Our Controller to download your code
Program
#include "ucos_ii.h"
#include "bsp.h"
#define TASK_STK_SIZE
128
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();
/*DetermineCPUcapacity.*/
OSStart();
/*start os here */
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 */
INT8U *buffer;
p_arg = p_arg;
for (;;)
{
buffer=OSMboxPend(pmailbox,timeout,&err); OSTimeDly(200);
else if(err==TIMEOUT_ERROR_GK)
printf("\n\rTimeout");
else if(err==EVENT_TYPE_ERROR_GK)
{
printf("\n\rThis is receiver \n\t err is OS_ERR_EVENT_TYPE");
break;
} else break;
OSTimeDlyHMSM(0,0,6, 0);
}
}
Result
The C-Language program to create a mailbox and to understand the about the RTOS
functions is developed and is verified.
Experiment 9
Flashing of LEDS
Aim
To develop a C program to make the LED blink (including delay routine). Upon change in the delay
program the speed should vary.
Apparatus & Software Required
1. VSK-SCM4 Development board.
2. IAR IDE software.
3. Flash Loader Demonstrator. .
Theory
LEDs are based on the semiconductor diode. When the diode is forward biased (switched on),
electrons are able to recombine with holes and energy is released in the form of light. This effect is
called electroluminescence and the color of the light is determined by the energy gap of the
semiconductor
11
91
Procedure
5. Follow the steps 1 of How to create a New project
6. Type the below code and save it with the name (anyname.c)
7. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and build
the program
8.
Program
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_rcc.h" void LED_init();
/* delay function */
void delay(long int a)
{
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;
/*
delay(3000);
/*
delay */
}
}
void LED_init()
{
RCC->AHB1ENR = 1 <<3;
GPIOD->MODER = 0x55555555;
>OTYPER =0x00000000;
/* push-pull type */
GPIOD->OSPEEDR =0xAAAAAAAA;
=0x00000000;
}
Result:
The C-Language program to make the LED blink was developed and output was verified. Upon
change in the delay program the speed variation was verified.
Experiment 10
Interfacing Stepper Motor and Temperature Sensor
Aim
To write C Programs 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.
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and build
the program
4.
Programs
#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h" static int i=0;
148
int main(void)
{
mx_pinout_config();
while (1)
{
}
}
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;
14
91
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();
}
}
15
01
Temperature Sensor
The temperature sensor has to generate a voltage that varies linearly with temperature. The
conversion range is between 1.8 V and 3.6 V. The temperature sensor is internally connected to the
ADC1_IN16 input channel which is used to convert the sensor output voltage into a digital value.
As the offset of the temperature sensor varies from chip to chip due to process variation, the internal
temperature sensor is mainly suitable for applications that detect temperature changes instead of
absolute temperatures. If an accurate temperature reading is needed, then an external temperature
sensor part should be used.
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and build
the program
4.
Program
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_adc.h"
#include "stm32f4xx_gpio.h" static int i=0;
IO uint32_t uhADCxConvertedValue = 0;
void USART2_config()
{
RCC->AHB1ENR |= 0x01; RCC->APB1ENR |= 0x20000;
}
void adc_configure()
{
//Clock configuration
/*The ADC1 is connected the APB2 peripheral bus thus we will use its clock source */
/*Clock for the ADC port!! Do not forget about this one ;) */
/* ADC configuration */
ADC3->CR1 = 0x00000000;
ADC3->CR2 = 0x00000002;
conversion mode. */
ADC3->SQR1 = 0x00000000;
0x00000001;
ADC3->SMPR2 = 0x00000030;
>SQR3 = 0x00000001;
/*ADC enable */
}
int adc_convert()
{
ADC_SoftwareStartConv(ADC3);
/* ADC configuration */
while(1)
{
ConvertedValue = adc_convert();
temp =ConvertedValue;
gk =temp*3.3; gk /=4095; gk *=100;
printf("\n Temperature = %3.2fC",gk);
if(gk >40)
/* if temperature > 40 */
{ anticlock_wise(); delay();
}
else if(gk <40)
{ clock_wise(); delay();
}
}
}
/* if temperature < 40 */
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;
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();
}
}
16
01
Experiment 11
Implementing Zigbee Protocol with ARM
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
densityup
to
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and build
the program.
4. Follow the procedures in How to Download a Code to Our Controller to download your code
Program
#include "stm32f4xx.h"
#include <stdio.h>
void USART2_config(); void send_data(char data); char gk[8] = "VSK-SCM4"; void delay(int j)
{
int g,k; for(g=0;g<j;g++) for(k=0;k<j;k++);
}
void main()
{
int i; USART2_config(); while(1)
{
for(i=0;gk[i] != '\0';i++)
{
164
send_data(gk[i]);
} send_data(0x0d); send_data(0x0A);
}
}
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0; RCC->APB1ENR |= 1 <<17;
165
16
61