Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
48 views81 pages

Embedded & IOMT Lab Manual

The BM3562 Embedded Systems and IoMT Laboratory syllabus outlines the course objectives, which include understanding embedded system design, IoT architecture, and IoMT infrastructure for healthcare applications. It lists various experiments focusing on programming with Embedded C, interfacing with IoT devices, and developing applications using platforms like Arduino and Raspberry Pi. The course aims to equip students with practical skills and knowledge in embedded systems and IoT technologies, culminating in a mini project.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views81 pages

Embedded & IOMT Lab Manual

The BM3562 Embedded Systems and IoMT Laboratory syllabus outlines the course objectives, which include understanding embedded system design, IoT architecture, and IoMT infrastructure for healthcare applications. It lists various experiments focusing on programming with Embedded C, interfacing with IoT devices, and developing applications using platforms like Arduino and Raspberry Pi. The course aims to equip students with practical skills and knowledge in embedded systems and IoT technologies, culminating in a mini project.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 81

| BM3562 EMBEDDED SYSTEMS AND

IOMT LABORATORY

BM3562 EMBEDDED SYSTEMS AND IOMT LABORATORY


(R2021)

SYLLABUS

COURSE OBJECTIVES:
 Acquire knowledge and understand the hardware architecture and programming aspects of
embedded system design.
 Understand IoT architecture and Build simple IoT Systems using embedded target 89 boards.
 Understand IoMT infrastructure for healthcare applications.

LIST OF EXPERIMENTS
1. Explore AVR/ARM based controllers using Embedded C.
2. Write Basic and arithmetic Programs Using Embedded C.
3. Write Embedded C program to test interrupt and timers.
4. Develop Real time applications – clock generation, waveform generation, counter using
embedded C.
5. Explore different communication methods with IoT devices.
6. To interface LED/Buzzer with platform/ Aurdino /Raspberry Pi. and write an embedded C
program to turn on / off LED/Buzzer with specified delay.
7. To interface DC/stepper motor using relay with open platform/ Aurdino /Raspberry Pi. and
write an embedded C program to turn on motor if push button is pressed.
8. Develop simple application – testing infrared sensor – IoT Applications – using open
platform/Raspberry Pi.
9. Develop simple application to interface DHT11 sensor with and write a program to display
temperature humidity readings in LCD.
10. Develop IoMT Application using open platform/ Aurdino. /Raspberry Pi. and sensors such
as temperature, ECG, Pulse etc.
11. Deploy IoMT applications using platforms.
12. Mini Project.

TOTAL: 45 PERIODS

COURSE OUTCOMES:
At the end of the course, the students will be able to:
CO1: Explain hardware architecture of embedded systems and use of software design tools
CO2: Describe IoT Architectures and Build simple IoT Systems using embedded target boards.
CO3: Exhibit understanding of IoMT infrastructure for healthcare with simple applications.

GRT Institute of Engineering and Technology, Tiruttani


Page |1
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

CO-PO Mapping Matrix:


P P P P P P
P P P P P P P P P
Course O O O S S S
O O O O O O O O O
Outcome 1 1 1 O O O
1 2 3 4 5 6 7 8 9
0 1 2 1 2 3
CO1 3 3 1 1 1 - - - 1 1 - - 1 - -
CO2 3 3 1 1 1 - - - 1 1 - - 1 - -
CO3 3 3 1 1 1 - - - 1 1 1 - 1 - -
CO4 3 3 1 1 1 - - - 1 1 1 - 1 - -
CO5 3 3 1 1 1 - - - 1 1 1 - 1 - -
AVG. 3 3 1 1 1 - - - 1 1 1 - 1 - -

EVALUATION OF LAB REPORT:

Marks Marks
Evaluation Parameters
Allotted Awarded
Aim & Hardware / Software Required: 10
Design & Circuit Diagram / Algorithm &
30
Flowchart:
Observation & Calculation / Program: 30
Graph / Output & Result: 20
Viva Voce: 10
Total: 100

GRT Institute of Engineering and Technology, Tiruttani


Page |2
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

BM3562 EMBEDDED SYSTEMS AND IOMT LABORATORY


Exp. Pg.
INDEX
No. No.
1 Explore AVR/ARM based controllers using Embedded C 6
2 Write Basic and arithmetic Programs Using Embedded C. 9
3 Write Embedded C program to test interrupt and timers. 12
4 Develop Real time applications – clock generation, waveform generation,
15
counter using embedded C.
5 Explore different communication methods with IoT devices. 22
6 To interface LED/Buzzer with platform/ Aurdino /Raspberry Pi. and write
24
an embedded C program to turn on / off LED/Buzzer with specified delay.
7 To interface DC/stepper motor using relay with open platform/ Aurdino
/Raspberry Pi. and write an embedded C program to turn on motor if push 29
button is pressed.
8 Develop simple application – testing infrared sensor – IoT Applications –
33
using open platform/Raspberry Pi.
Develop simple application to interface DHT11 sensor with and write a
9 35
program to display temperature humidity readings in LCD.
Develop IoMT Application using open platform/ Aurdino. /Raspberry Pi.
10 41
and sensors such as temperature, ECG, Pulse etc.
CONTENT BEYOND SYLLBUS
11 Interfacing ADC and DAC 50
12 Interfacing PWM and LED 53
13 Interfacing Keypad and LCD 58

GRT Institute of Engineering and Technology, Tiruttani


Page |3
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Exp. Explore AVR/ARM based controllers using Embedded C


1
No.:
Da
te:
AIM

To study the procedure for complication and debugging of program using IAR work bench.

APPARATUS&SOFTWARE REQUIRED

1. VSK-SCM4 Development board.


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

PROCEDURE

1) Write the c program for the given task and execute using IAR
2) Follow the steps 1 of How to create a New project

HOW TO CREATE A NEW PROJECT

1. CREATING A NEW PROJECT:


IAR Embedded Workbench Installation is completed; Shortcut ICON is placed at
your desktop. Just make a double click on that ICON.

New Window is open as given below.

GRT Institute of Engineering and Technology, Tiruttani


Page |4
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

1. To create a new project, choose Project>Create New Project. The Create New Project
Dialog box appears, which lets you base your new project on a project template.

2. Make sure the Tool chain is set to ARM, and click OK.
3. Select the project template Empty project, and click ok button. This simply creates
an empty project that uses default project setting.
4. In the standard Save As dialog box that appears, specify where you want to place
your project file, that is, in your newly created projects directory. Type your
project name in the File name box, and click Save to create the new project.

E.g. LED.

GRT Institute of Engineering and Technology, Tiruttani


Page |5
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

The project will appear in the Workspace window

To Creating your Application ‘C’ file, Choose FILE menu and select NEW>File

GRT Institute of Engineering and Technology, Tiruttani


Page |6
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Edit the application code in C Language. E.g. Led_1.c. To Save your ‘C’ file,
ChooseFile>Save As. In the standard Save As dialog box that appears, specify where you
wantto place your project file, that is, in your project directory. Type your filename in the
Filename box, and click Save to create the new project. E.g. Led_1.c

GRT Institute of Engineering and Technology, Tiruttani


Page |7
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

2. ADDING FILES TO THE PROJECT

1. In the Workspace window, select the destination to which you want to add a source
file; a group or, as in this case, directly to the project.
2. Choose Project>Add Files to open a standard browse dialog box. Locate the files
LED_1.c
Select them in the file selection list, and click Open to add them to the project.

GRT Institute of Engineering and Technology, Tiruttani


Page |8
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

To save your work space, Choose File>Save Workspace and specify where you want to
place your workspace file. In this tutorial, you should place it in your newly created
project directory. Type LED in the File name box, and click save button.

GRT Institute of Engineering and Technology, Tiruttani


Page |9
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

3. SETTING PROJECT OPTIONS

Now you will set the project options. For application projects, options can be set on all
levels of nodes. First you will set the general options to suit the processor configuration in
this tutorial. Because these options must be the same for the whole build configuration,
they must be set on the project node.

1. Select the project folder icon LED_OUT - Debug in the Workspace window and choose
Project>Options. Then select General Options to select your Controller.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 10
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

2. In general options browse your device by following manner. ST  STM32F407


STM32F407VG.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 11
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

3. The Output options are used for specifying details about the output format and the level
of debugging information included in the output file. Select output format as “Intel
Extended”, output file in the format of .hex format.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 12
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

4. Select the linker file menu, linker configuration file available at project directory.
To Compile your Project, Choose Project>Rebuild ALL

5. Now click ok. Now your project is configured for your specified controller (i.e.)
STM32F407ZG.

4. ADDING LIBRARY FILES


1. Copy the library file “STM_lib_gk.a” and paste it into your project folder.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 13
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Then right click on your project file and click add  add files.

After that select your library file and click open.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 14
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Now library file added into your project.


2. Define “USE_STDPERIPH_DRIVER”:
Go to options by selecting project  options
Then select C/C++ compiler and select preprocessor label.
Type the below symbol in defined symbol box.
“USE_STDPERIPH_DRIVER”

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 15
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

5. ADD INCLUDE FILES


1. Copy the include folder (INC) and paste that into your project location.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 16
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

2. Go to options window (project  options) and select C/C++ compiler. then


select preprocessor tab.
3. In this tab you should add your “INC” file location with INC folder name.
(Ex :C:\Users\user\Desktop\LED_FLASHING\INC )

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 17
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Then click ok.

6. BUILD THE PROJECT


1. To compile your project select Project  rebuild all.

2. If your project has no error, then it will show Building successfully and the Hex file
will be generated.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 18
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

RESULT:

Thus the study of the procedure for compilation and debugging is studied.

Exp. Write Basic and arithmetic Programs Using Embedded C.


2
No.:
Da
te:

AIM:
To develop a Embedded C program for arithmetic operation

EQUIPMENTS:
1. VSK-SCM4 Development board.
2. IAR IDE software.
3. Flash Loader Demonstrator. .

THEORY:
The Arithmetic operators are some of the C Programming Operator, which are used to
perform arithmetic operations includes operators like Addition, Subtraction, Multiplication,
Division and Modulus.All these Arithmetic operators in C are binary operators which means they
operate on two operands.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 19
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

PROCEDURE:
1) Write the c program for the given task and execute using IAR
2) Follow the steps 1 of How to create a New project
3) Type the below code and save it with the name (anyname.c)
4) Follow the steps 2 to 6 of How to create a New Project to add the necessary file,
compile and build the program
5) Follow the procedures in How to Download a Code to Our Controller to
download your code.

PROGRAM CODING:
#include<stdio.h>
int main()
{
int a,b,c;
float x;
printf("\nEnter 2 Nos : ");
scanf("%d%d",&a,&b);
c=a+b;
printf("\nTotal : %d",c);
c=a-b;
printf("\nDifference : %d",c);
c=a*b;
printf("\nMul : %d",c);
x=(float)a/(float)b;
printf("\nDiv : %0.2f",x);
c=a%b;
printf("\nMod : %d",c);
return 0;
}

PROCEDURE TO VIEW THE RESULT

1. Follow the steps of How to view the result in Win X Talk.


2. Set your board to the execution mode and reset it.
3. The time will be executed in PC.
4. To change the time i.e. hours and minutes press the switches SW5 and SW2
respectively

OUTPUT

Enter 2 Nos : 25 10
Total : 35
Difference : 15

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 20
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Mul : 250
Div : 2.50
Mod : 5

RESULT:
The C-Language program for arithmetic operation was written & output is verified
with
runnin Exp. Write Embedded C program to test interrupt and timers. g the
3
RTC No.: from a
Da
default te: /specif
ied time .

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.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 21
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 22
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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 EPROM
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. Follow the procedures in How to Download a Code to Our Controller to download
your code.

PROGRAM: READ
#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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 23
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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=20;i<84;i++) //modify your data here.here data is 10 to 73
{ I2C_write(I2C1,i); Delay(200);
}
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;

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 24
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 25
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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)
{
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)
{
// Send I2C1 STOP Condition

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 26
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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

READ
#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 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();

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 27
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 28
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 29
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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)


{
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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 30
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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);
}
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);
}
Procedure to View the Result

1. Follow the steps of How to view the result in Win X Talk.


2. Set your board to the execution mode and reset it.
3. In first step, some data will be written in EEPROM at the starting address 0x01.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 31
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

4. Then read the data from that memory location. The read data will be displayed in the
terminal window.

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.

Exp. Develop Real time applications – clock generation, waveform


4
AIM: No.: generation, counter using embedded C.
Da
te:
To
conduct an suitable experiment for interfacing real time clock and serial port using ARM
processor.

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.


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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 32
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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 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) Write the c program for the given task and execute using IAR
2) Follow the steps 1 of How to create a New project
3) Type the below code and save it with the name (anyname.c)

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 33
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

4) Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile
and build the program
5) Follow the procedures in How to Download a Code to Our Controller to
download your code.

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

while(1)
{

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 34
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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

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;

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 35
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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 I2C1I2C_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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 36
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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)


{
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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 37
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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

PROCEDURE TO VIEW THE RESULT

1. Follow the steps of How to view the result in Win X Talk.


2. Set your board to the execution mode and reset it.
3. The time will be executed in PC.
4. To change the time i.e. hours and minutes press the switches SW5 and SW2
respectively

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 38
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

OUTPUT:

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 .

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 39
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Exp. Explore different communication methods with IoT devices.


5
No.:
Da
te:
AIM:
To write a program to connect with the available Wi-Fi using Arduino

EQUIPMENTS:
 ESP 8266 module or Wi-Fi module
 Connecting cables or USB cables Software

THEORY:

PROCEDURE:
1. STEP1: Start the process.
2. STEP2: Start Arduino IDE 1.8.8.
3. STEP3: Include the file directory ESP 8266 in Arduino.
4. STEP4: Then enter the coding to Wi-Fi module or ESP 8266 module.
5. STEP5: Then enter the coding in Arduino software.
6. STEP6: Connect the USB cable to the Wi-Fi module and the
7. Arduino connected system with available network.
8. STEP7: Select toolsSelect boardNode MCU 0.9C ESP-12 module
9. and then SelectPort.
10. STEP8: Upload the coding to ESP 8266 module and open serial
11. monitor to View the available network connects IP address.
12. STEP9: Stop the process.

PROGRAM CODING:
#include <ESP8266WiFi.h> // Include the Wi-Fi library
const char* ssid = "Error"; // The SSID (name) of the Wi-Fi network
you want to connect to
const char* password = "networkerror"; // The password of the WiFi network

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 40
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

void setup() {
Serial.begin(115200); // Start the Serial communication to send
messages to the computer
delay(10);
Serial.println('\n');
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.print(“...")
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to
connect
delay(1000);
Serial.print(++i); Serial.print(' ');
}
void loop() {
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266
to the computer
}
}

OUTPUT

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 41
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

RESULT:
Thus the output for connecting with the available Wi-Fi using Arduino has been successfully

Exp. To interface LED/Buzzer with platform/ Aurdino /Raspberry Pi. and


6
No.: write an embedded C program to turn on / off LED/Buzzer with
Da
te:
specified delay.
executed.

AIM:
To control LED Using Arduino Uno board

EQUIPMENTS:
 Universal Board
 Arduino board Led
 12V Adaptor
 Power jack
 USB Cable

HARDWARE PROCEDURE:
• LED pin is Connected to Arduino Uno pin of 2.
• Power jack is connected to the Arduino Uno.
• USB connector is connected to Arduino Uno to monitor.
• Connect the 12V power supply to development board.
• Check the output from the development board

SOFTWARE PROCEDURE:
 Click on Arduino IDE
 Click on file
 Click on New
 Write a Program as per circuit Pin connections
 Click on Save
 Click on Verify
 Click on Upload the code into Arduino Uno by using USB cable

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 42
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Program:
const int led = 2;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 43
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Result:
Thus the control of LED Using Arduino Uno board is done.

Exp. To interface DC/stepper motor using relay with open platform/


7
No.: Aurdino /Raspberry Pi. and write an embedded C program to
Da AIM
te:
turn on motor if push button is pressed.
To write C Programs for running stepper motor either in clock-wise or counter-
clockwise 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.


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.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 44
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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:
STEPPER MOTOR:
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
static int i=0;
/* private prototype functions*/
void anticlock_wise();
void clock_wise(); void
delay()
{
for(int i=0;i<0xFF;i++)
for(int j=0;j<0xFF;j++);
}
void motor_PIN_config(void)
{
RCC->AHB1ENR |= 1<<1;

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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 45
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

GPIOB->PUPDR = 0x00000000;
GPIOB->OSPEEDR = 0xFFFFFFFF;
}

void main(void)
{
motor_PIN_config();
while(1)
{ anticlock_wise();
delay(); clock_wise();
delay();
}
}
void anticlock_wise()
{
for(i=0;i<56;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<56;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();
}
}

TEMPERATURE SENSOR

#include "stm32f4xx.h"

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 46
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

#include <stdio.h>
#include "stm32f4xx_adc.h"
IO uint32_t uhADCxConvertedValue = 0;

extern void delay() ;


extern void busy_check() ;
extern void command_write(int comm);
extern void lcd_init();
extern void lcd_out(unsigned char a); extern
void mx_pinout_config(void); void
lcd_sep_data(int a);
void USART2_config();
static void ADC_Config(uint32_t channel);
uint32_t temp;
static float gk;
enum {low = 0,high = !low};
void main()
{
mx_pinout_config();//lcd pins configuration lcd_init(); //send initialcommands

command_write(0x80); //FIRST LINE lcd_out('G'); //write data

ADC_Config(ADC_Channel_1);
//ADC_Config(ADC_Channel_1); USART2_config();
ADC3->CR2 |=0x40000000;
while(1)
{
temp =uhADCxConvertedValue;
gk =temp*3.3; gk /=4095; gk *=100;
printf("\n Temperature = %3.2f°C",gk);
// printf("\n ADC3 channel_0 value = %d ",uhADCxConvertedValue);
}
}

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

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

//USART3->BRR = 0x8A; //115200 baud rate


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

static void ADC_Config(uint32_t channel)


{

/* Enable ADCx, DMA and GPIO clocks ****************************************/ RCC-


>AHB1ENR |= (high <<22)|(high <<0)|(high <<5);

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 47
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

RCC->APB2ENR |= (high<<10);
DMA2_Stream0 ->CR = (low<<6 |low<<7 |high<<8 | //p to m,circular
low<<9 |low<<10 |high<<11 |low<<12 |high<<13 |low<<14| //p-fixed,m-fixed,p-

16,m-16

p,m transfer

low<<16 |high<<17 |low<<21 |low<<22 |low<<23 |low<<24| //high priority,single low <<25 |high<<26 |
low<<27); //channel 2
DMA2_Stream0 ->FCR =(high <<0 |low <<1 |low<<2); //FIFO disable,1\2 fifo
DMA2_Stream0 ->NDTR =1; //buffer size
DMA2_Stream0 ->PAR = 0x4001224C; //p-base address
DMA2_Stream0 ->M0AR =(uint32_t)&uhADCxConvertedValue; //memory address
DMA2_Stream0 ->CR |= high <<0; //steam enable

/* Configure ADC3 Channel0 pin as analog input ******************************/


GPIOA->MODER |= (high<<2)|(high<<3);
// GPIOF->MODER |= (high<<14)|(high<<15);
// GPIOF->MODER |= (high <<18) | (high <<19);
/* ADC Common Init **********************************************************/ ADC-
>CCR = (low <<0|low<<1|low <<2|low<<3|low<<4| //independent mode
low <<8|low <<9|low <<10|low <<11 | //5 cycles sam delay low
<<14|low <<15| //DMA access disable low<<16 |low
<<17); //pclk2/2

/* ADC3 Init ****************************************************************/


ADC3->CR1 =(low << 8| //scan mode disable
low <<24 |low << 25); // resolution 12 bit

ADC3->CR2 =(high <<0 |high <<1 |low <<11 | //ADC enable,continuous conv mode,right align
low <<24 |low<<25 |low<<26 |low<<27| //TI_cc1 external trigger
low<<28 |low <<29); //ext_conversion edge none

ADC3->SQR1 =(low <<20 |low<<21 |low<<22 |low<<23); //sequence conversion length =1

/* ADC3 regular channel0 configuration *************************************/


ADC_RegularChannelConfig(ADC3,channel, 1, ADC_SampleTime_28Cycles);

/* Enable DMA request after last transfer (Single-ADC mode) */ /* Enable ADC3 DMA */

ADC3->CR2 |= (high <<9)|(high <<8);

}
int putchar(int data)
{
USART2->DR = (data & 0x01FF);
/* Loop until the end of transmission */

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 48
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

while((USART2->SR & 0x40) ==0)


{}
return data;
}

void lcd_sep_data(int a)
{
int d1,d2,d3,d4,d5,d6;
d1 = a/1000;

d2 = a%1000; d3
=d2/100; d4 =
d2%100; d5 = d4/10;
d6 = d4%10;
lcd_out(d1+0x30);
lcd_out(d3+0x30);
lcd_out(d5+0x30);
lcd_out(d6+0x30);
delay(1000);}
PROCEDURE TO VIEW THE RESULT

1. Follow the steps of How to view the result in Win X Talk.


2. Set your board to the execution mode and reset it.
3. The room Temperature will be displayed on the Terminal Window
4. 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.

OUTPUT

STEPPER MOTOR

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 49
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

TEMPERATURE SENSOR

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 50
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

RESULT:

Thus the c program is written and executed by verifying the output using ARM
processor.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 51
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Exp. Develop simple application – testing infrared sensor – IoT


8
No.: Applications – using open platform/Raspberry Pi.
AIM: Da
te:
To Interface Potentiometer and IR Sensor Using Arduino Uno board

EQUIPMENTS:
 Universal Board
 Arduino board
 POT sensor
 IR Sensor
 12V Adaptor
 Power jack USB Cable
 Jumper Wires

HARDWARE PROCEDURE:
 LED pin is Connected to Arduino Uno pin of 11 & 12.
 POT pin is connected to the Arduino pin A1.
 IR Sensor Pin is connected to the Arduino Pin 4.
 Power jack is connected to the Arduino.
 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Check the output from the development board.

SOFTWARE PROCEDURE:
 Click on Arduino IDE
 Click on file
 Click on New
 Write a Program as per circuit Pin connections
 Click on Save
 Click on Verify
 Click on Upload the code into Arduino Uno by using USB cable.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 52
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Program:
#define LED_PIN 11
#define POTENTIOMETER_PIN A1
void setup() {
// put your setup code here, to run once:
pinMode(4,INPUT);
pinMode(12,OUTPUT);//LED
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:potentiometer loop
int potentiometerValue = analogRead(POTENTIOMETER_PIN);
int brightness = potentiometerValue / 4;
analogWrite(LED_PIN, brightness);
//ir loop
if(digitalRead(4)==LOW){
digitalWrite(12,HIGH);
}
else {
digitalWrite(12,LOW);
}
}

RESULT:
Infrared Sensor is successfully tested by Arduino microcontroller Board

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 53
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Exp. Develop simple application to interface DHT11 sensor with and


9.
No.: write a program to display temperature humidity readings in
Da
te:
LCD.

AIM:
To Interface DHT11 Using Arduino Uno board and upload sensor data to Cloud.

EQUIPMENTS:
 Universal Board
 Arduino board
 DHT11 sensor
 WIFI Module
 LCD
 WIFI Module
 12V Adaptor
 Power jack
 USB Cable
 Jumper Wires

HARDWARE PROCEDURE:
 LCD pins connected to Arduino Uno pin 2,3, 4, 5, 6, and 7.
 DHT11 pin connected to the 10 pin of Arduino board.
 Wifi module pins RX & TX are connected to 8 and 9 pin of Arduino ( RX = 8, TX = 9).
 USB connector is connected to Arduino Uno to monitor.
 Place Wifi Module in IOT development Board.
 Connect the 12V power supply to development board.
 Power jack is connected to the Arduino Uno.
 Check the output from the development board.

SOFTWARE PROCEDURE:
 Click on Arduino IDE
 Click on file
 Click on New
 Write a Program as per circuit Pin connections
 Click on Save
 Create an Account in Things Speak, then create a channel.
 Go to API keys in that Channel and then copy “Write API key”.
 Go to Arduino code and paste Write API key.
 Give your mobile hotspot name and password in Arduino code.
 Click on save & Click on Verify.
 Click on Upload the code into Arduino Uno by using USB cable.
 After that open things Speak account and click on private view

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 54
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

 DHT11 Sensor data will be uploaded and it will be shown as graph in Private view on
Things Speak account.

PROGRAM CODING:
#include <dht.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
LiquidCrystallcd(2,3, 4, 5, 6, 7);
SoftwareSerialwifi(8, 9); // TX, RX
String apiKey = "TRNIC1L9BXBXT322"; /// Write API Key
dhtDHT;
#define DHT11_PIN 10
const int buzzer = 13;
void setup(){
lcd.begin(16, 2);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer, 0);
project_Name();
Serial.begin(9600);
Serial.println("AT");
delay(1000);
Serial.println("AT+CMGF=1");
delay(1000);
Serial.println("AT+CNMI=2,2,0,0,0");
delay(1000);
lcd.setCursor(0,0);
lcd.print("WiFi module ");
lcd.setCursor(0,1);
lcd.print("Initilizing.... ");
wifi.begin(115200);
wifi.println("AT+RST");
delay(4000);

wifi.println("AT+CWMODE=3");
delay(4000);
wifi.print("AT+CWJAP=");
wifi.write('"');
wifi.print("STTMANI");
wifi.write('"');
wifi.write(',');
wifi.write('"');
wifi.print("hailucky123,./");
wifi.write('"');
wifi.println();
delay(1000);
lcd.setCursor(0,0);
lcd.print("WiFi module ");
lcd.setCursor(0,1);
lcd.print("Initilized..... ");

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 55
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

delay(1000);
lcd.clear();
}
void loop()
{
int chk = DHT.read11(DHT11_PIN);
//SendWiFi_Data();
//delay(1000);
lcd.setCursor(0,0);
lcd.print("Temperature: ");
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.setCursor(12,0);
lcd.print(DHT.temperature);
lcd.setCursor(9,1);
lcd.print(DHT.humidity);
delay(500);
/* Tempurature Data Process*/
if(DHT.temperature> 45)
{
buzzer_sound();
}
/* Humidity Data Process*/
if(DHT.humidity< 30)
{
buzzer_sound();
}
lcd.setCursor(15,1);
lcd.write(0x20);
SendWiFi_Data();
delay(1000);
}

void SendWiFi_Data(){
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += "184.106.153.149"; // api.thingspeak.com
cmd += "\",80";
wifi.println(cmd);
delay(1500);
String getStr ="GET /update?api_key=";
getStr += apiKey;
getStr +="&field1=";
getStr += String(DHT.temperature);
getStr +="&field2=";
getStr += String(DHT.humidity);
getStr += "\r\n\r\n";
// send data length
cmd = "AT+CIPSEND=";
cmd += String(getStr.length());
wifi.println(cmd);
delay(1500);

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 56
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

wifi.println(getStr);
delay(1000);
}
void buzzer_sound()
{
digitalWrite(buzzer, HIGH);
delay(600);
digitalWrite(buzzer, LOW);
delay(400);
digitalWrite(buzzer, HIGH);
delay(600);
digitalWrite(buzzer, LOW);
delay(400);
}
void project_Name(){
lcd.setCursor(0,0);
lcd.print(" ESP8266 ");
lcd.setCursor(0,1);
lcd.print(" Interfacing ");
delay(3000);
lcd.clear();
}

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 57
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

RESULT
DHT11 sense the surrounding temperature and measure humidity in surrounding air
that temperature and humidity shown by LCD display and Sensor data will be successfully

Exp. Develop IoMT Application using open platform/ Aurdino.


10
No.: /Raspberry Pi. and sensors such as temperature, ECG, Pulse etc.
Da
te:
uploaded on Things Speak account.

AIM:
To write a program to get temperature notification using Arduino.

EQUIPMENTS:
 Temperature and humidity sensor.
 2. Jumper wires
 3. Connectivity cable or USB cable.

ALGORITHM:
STEP 1: Start the process.
STEP 2: Start Arduino 1.8.8
STEP 3: Include the DHT library to the Arduino software.
STEP 4: Then enter the coding in Arduino software.
STEP 5: Complete the coding in Arduino.
STEP 6: In Arduino board connect VCC to the power supply 5V and
connect SIG to digital signal DT and connect SND to ground GND
using jumper wires.
STEP 7: Connect the arduino board with USB cable to the system.
STEP 8: Select tools  Selected.
STEP 9: Upload the coding to arduino board. Then the output will
be displayed in the serial monitor.
STEP 10: Stop the process.

BLOCK DIAGRAM:

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 58
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

PROGRAM CODING:
#include <dht.h>
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;
void setup()
{
pinMode(A0,INPUT);
Serial.begin(9600);
delay(500);
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);
}
void loop()
{
DHT.read11(dht_apin);
Serial.print("THS:th01:None:");
Serial.print(DHT.humidity);
Serial.print("%,");
IoT Applications
Department of Information Technology 23
//Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("degC");
delay(2000);//Wait 5 seconds before accessing sensor again.
}

OUTPUT:

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 59
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

RESULT
Thus the output to get temperature notification using Arduino has successfully executed

CONTENT BEYOND SYLLABUS


Exp. Interfacing ADC and DAC
11
No.:
Dat
e:
GRT Institute of Engineering and Technology, Tiruttani
P a g e | 60
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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.

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

PROCEDURE

1) Write the c program for the given task and execute using IAR
2) Follow the steps 1 of How to create a New project
3) Type the below code and save it with the name (anyname.c)
4) Follow the steps 2 to 6 of How to create a New Project to add the necessary file,
compile and build the program
5) Follow the procedures in How to Download a Code to Our Controller to download
your code.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 61
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

PROGRAM:
ADC
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_adc.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; //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;

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 62
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

USART2->CR1 = 0x200C;
}
int main(void)
{
USART2_config();
adc_configure();//Start configuration while(1)
{
ConvertedValue = adc_convert();//Read the ADC converted value printf("\n ADC
value => %d",ConvertedValue); //print the ADC value

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

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.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 63
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

PROGRAM
#include "stm32f4xx.h"
#include "stm32f4xx_dac.h"
#include "stm32f4xx_gpio.h"

#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_syscfg.h"
#define sine_wave_gk
//#define triangular_wave_gk
//#define square_wave_gk
//#define sawtooth_wave_gk unsigned
int sine_wave[200]=
{2048,2112,2176,2240,2304,2368,2431,2494,2557,2619,2680,2741,2801,2860,2919,2977,3034,
3090,3144,3198,3251,3302,3352,3401,3449,3495,3540,3583,3625,3665,3704,3741,3776,3809,
3841,3871,3900,3926,3951,3973,3994,4013,4030,4045,4058,4069,4078,4085,4090,4093,4095,
4093,4090,4085,4078,4069,4058,4045,4030,4013,3994,3973,3951,3926,3900,3871,3841,3809,
3776,3741,3704,3665,3625,3583,3540,3495,3449,3401,3352,3302,3251,3198,3144,3090,3034,
2977,2919,2860,2801,2741,2680,2619,2557,2494,2431,2368,2304,2240,2176,2112,2048,1984,
1920,1856,1792,1728,1665,1602,1539,1477,1416,1355,1295,1236,1177,1119,1062,1006,952,898,
845,794,744,695,647,601,556,513,471,431,392,355,320,287,255,225,196,170,145,123,102,83,66,
51,38,27,18,11,6,3,1,3,6,11,18,27,38,51,66,83,102,123,145,170,196,225,255,287,320,355,392,431,
471,513,556,601,647,695,744,794,845,898,952,1006,1062,1119,1177,1236,1295,1355,1416,1477,
1539,1602,1665,1728,1792,1856,1920,1984};

int main(void)
{
static int i;
int j;
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;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 64
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

GPIO_Init(GPIOA, &GPIO_InitStructure);

//TIM6_Config();
while (1)

{
j=0;
#if defined sine_wave_gk
for(i=0;i<200;i++)
{
DAC->DHR12R2 = sine_wave[i];
DAC_Cmd(DAC_Channel_2, ENABLE);
}
#elif defined triangular_wave_gk
for(i=0;i<=4095;i++)
{
DAC->DHR12R2 = i; DAC_Cmd(DAC_Channel_2,
ENABLE);
}
for(i=4095;i>=0;i--)
{
DAC->DHR12R2 = i; DAC_Cmd(DAC_Channel_2,
ENABLE);
}

#else if defined square_wave_gk


while((j++) < 100000)
DAC->DHR12R2 = 0xFFF;
while((j--) > 0)
DAC->DHR12R2 = 0x000;
DAC_Cmd(DAC_Channel_2, ENABLE);

#else if defined sawtooth_wave_gk


for(i=0;i<4095;i++)
{
DAC->DHR12R2 = i; DAC_Cmd(DAC_Channel_2,
ENABLE);
}
#endif
//DAC_Ch2_TriangleConfig();
}
}

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 65
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

OUTPUT
ADC:

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 66
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

Procedure to View the output DAC

1. Set your board to the execution mode and reset it.


2. Make use of a CRO or DSO to view the DAC output by connecting the +ve terminal to pin
and the –ve terminal to GND.
3. The waveforms can be viewed in either the CRO or DSO based on the choice.

RESULT:
Thus the C program is written and executed by verifying the output using ARM processor.

Exp. Interfacing PWM and LED


No.: 12.
Da
te:

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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 67
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

4. CRO
THEORY
The PWM is based on the standard timer block and inherits all of its features.
The timer is designed to count cycles of the peripheral clock (PCLK) and optionally
generate interrupts or perform other actions when specified timer values occur, based
on seven match registers. The PWM function is also based on match register events

PROCEDURE

1) Write the c program for the given task and execute using IAR
2) Follow the steps 1 of How to create a New project
3) Type the below code and save it with the name (anyname.c)
4) Follow the steps 2 to 6 of How to create a New Project to add the necessary file,
compile and build the program
5) Follow the procedures in How to Download a Code to Our Controller to
downloadyour code.

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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 68
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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;
}
int switch_read()
{
int val;
mx_pinout_config();
val = ((GPIOE->IDR)&0x14);

if(val == 0x04)
{
if(duty_cycle <= 0)
{
duty_cycle =1;

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 69
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

}
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 moode
GPIOE->OTYPER =0x00000000; GPIOE-
>PUPDR = 0x00000000; GPIOE->OSPEEDR
=0xAAAAAAAA;
}

void USART2_config()
{
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;

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 70
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

void delay(int delay)


{
int d1,d2; for(d1=0;d1<delay;d1+
+) for(d2=0;d2<delay;d2++);
}

PROCEDURE TO SEE OUTPUT:

1. Set your board to the execution mode and reset it.


2. Connect the +ve terminal of the LED board to the connector and –ve terminal to GND.
3. On varying the duty cycle of the PWM, the intensity of the LEDs will vary.
4. To increase the duty cycle press SW2 and to decrease, press SW5.

OUTPUT

RESULT:
The C program to vary the intensity of the LED depending on the duty cycle of the PWM
has
been Exp.
13 Interfacing Keypad and LCD
develo No.: ped
Da
and is
te:
verifie d.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 71
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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/Olines
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.

CHARACTER BASED LCD

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 72
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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

PROCEDURE

1) Write the c program for the given task and execute using IAR
2) Follow the steps 1 of How to create a New project
3) Type the below code and save it with the name (anyname.c)
4) Follow the steps 2 to 6 of How to create a New Project to add the necessary file,
compile and build the program
5) Follow the procedures in How to Download a Code to Our Controller to
download your code.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 73
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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


GPIOD->BSRRL = 0x000E; //low PD1 to PD3 val =

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 74
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

(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

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 75
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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
{

command_write(0x01);
command_write(0x80); lcd_stringout("You

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 76
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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

}
}

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 77
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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)


{

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 78
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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

GPIOD->MODER |=0x00000055; //set port D0-D3 as o/p mode,other pins are input moode
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;
}

PROCEDURE TO VIEW THE RESULT

1. Set your board to the execution mode and reset it.


2. The switches SW2, SW3, SW5 and SW6 are interfaced as keypad.
3. 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.
4. We can type up to 32 data’s with these keys.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 79
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

OUTPUT

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 80
| BM3562 EMBEDDED SYSTEMS AND
IOMT LABORATORY

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.

GRT Institute of Engineering and Technology, Tiruttani


P a g e | 81

You might also like