0% found this document useful (0 votes)
43 views8 pages

DSD Lab 10

This document contains details of an embedded systems lab experiment conducted by students. It includes 3 tasks related to toggling an LED using interrupts from a button press and implementing a stopwatch functionality using timers and interrupts on an ARM controller board. Code snippets are provided for interrupt service routines and the main function to initialize peripherals like GPIO, EXTI lines and timers. Output videos demonstrating the tasks are also referenced.

Uploaded by

Shayan Amjad
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)
43 views8 pages

DSD Lab 10

This document contains details of an embedded systems lab experiment conducted by students. It includes 3 tasks related to toggling an LED using interrupts from a button press and implementing a stopwatch functionality using timers and interrupts on an ARM controller board. Code snippets are provided for interrupt service routines and the main function to initialize peripherals like GPIO, EXTI lines and timers. Output videos demonstrating the tasks are also referenced.

Uploaded by

Shayan Amjad
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/ 8

Department of Electrical Engineering

Faculty Member: Dr. Usman Zabit Dated: 27-09-2022

Group: 1 Semester: 7TH

Embedded System Design

Lab2: Introduction to Development with ARM Controller


Name Reg. No Viva / Quiz Analysis Modern Ethics and Individual
/ Lab of data in Tool Safety and Team
Performan Lab Usage Work
ce Report

5 Marks 5 Marks 5 Marks 5 Marks 5 Marks


Muhammad Shayan Khan 310591
Manj

Muhammad Ibrahim 291898

Ali Ashraf 292926

Abdullah Numair 288147


Task 1:
Code:
/* Button Interrupting
* ___________________
* This program toggles on-board LED of STM32F429 Discovery Kit
* through external interrupt of on-board user button.
*/

/* includes */
#include "stm32f4xx.h"

/* function declarations */
void EXTI0_IRQHandler(void);
int main(void);

/* external interrupt handler */


void EXTI0_IRQHandler(void)
{
// Check if the interrupt came from EXTI0
if (EXTI->PR & (1 << 0)){
GPIOG->ODR ^= (1 << 13);

/* wait little bit */


for(uint32_t j=0; j<1000000; j++);

// Clear pending bit


EXTI->PR = (1 << 0);
}
}

/* main code */
int main(void)
{
/* set up LED */
RCC->AHB1ENR |= (1 << 6);
GPIOG->MODER &= !(0x11 << 2*13);
GPIOG->MODER |= 0x01 << 2*13;
/* set up button */
RCC->AHB1ENR |= (1 << 0);
GPIOA->MODER &= 0xFFFFFFFC;
GPIOA->MODER |= 0x00000000;

// enable SYSCFG clock (APB2ENR: bit 14)


RCC->APB2ENR |= (1 << 14);

/* tie push button at PA0 to EXTI0 */


SYSCFG->EXTICR[0] |= 0x00000000; // Write 0000 to map PA0 to EXTI0
EXTI->RTSR |= 0x00001; // Enable rising edge trigger on EXTI0
EXTI->IMR |= 0x00001; // Mask EXTI0

// Set Priority for each interrupt request


NVIC->IP[EXTI0_IRQn] = 0x1; // Priority level 1

// enable EXT0 IRQ from NVIC


NVIC->ISER[0] = 1 << EXTI0_IRQn;

while(1);

Output:
Task 2:

Code:
/* Button Interrupting
* ___________________
* This program toggles on-board LED of STM32F429 Discovery Kit
* through external interrupt of on-board user button.
*/

/* includes */
#include "stm32f4xx.h"

/* function declarations */
void TIM2_IRQHandler(void);
void EXTI0_IRQHandler(void);
int main(void);

/* timer interrupt handler */


void TIM2_IRQHandler(void)
{
// Clear pending bit first
TIM2->SR = (uint16_t)(~(1 << 0));

GPIOG->ODR ^= (1 << 13);


}
/* external interrupt handler */
void EXTI0_IRQHandler(void)
{
// Check if the interrupt came from EXTI0
if (EXTI->PR & (1 << 0)){
TIM2->CR1 ^= 1 << 0;

/* wait little bit */


for(uint32_t j=0; j<1000000; j++);

// Clear pending bit


EXTI->PR = (1 << 0);
}
}

/* main code */
int main(void)
{

// enable GPIOG clock


RCC->AHB1ENR |= (1 << 6);
GPIOG->MODER &= !(0x11 << 2*13);
GPIOG->MODER |= 0x01 << 2*13;

// enable SYSCFG clock


RCC->APB2ENR |= (1 << 14);
SYSCFG->EXTICR[0] |= 0x00000000; // Write 0000 to map PA0 to EXTI0
EXTI->RTSR |= 0x00001; // Enable rising edge trigger on EXTI0
EXTI->IMR |= 0x00001; // Mask EXTI0

// Set Priority for each interrupt request


NVIC->IP[EXTI0_IRQn] = 0x10; // Priority level 1

// enable EXT0 IRQ from NVIC


NVIC->ISER[0] = 1 << EXTI0_IRQn;

// enable TIM2 clock


RCC->APB1ENR |= (1 << 0);

// set prescalar and autoreload value


TIM2->PSC = 8399;
TIM2->ARR = 10000;
// Update Interrupt Enable
TIM2->DIER |= (1 << 0);

// enable TIM2 IRQ from NVIC


NVIC->ISER[0] |= 1 << TIM2_IRQn;

// Enable Timer 2 module (CEN, bit0)


TIM2->CR1 |= (1 << 0);

while (1);

Outputs:
The Output video is attached in the zip file.

Task 3:
Code:
/* includes */
#include "stm32f4xx.h"

/* function declarations */
void TIM2_IRQHandler(void);
void EXTI0_IRQHandler(void);
int main(void);
int seconds = 0;
int minutes = 0;
int state = 0;

/* timer interrupt handler */


void TIM2_IRQHandler(void)
{
// Clear pending bit first
TIM2->SR = (uint16_t)(~(1 << 0));

++seconds;
if (seconds > 59)
{
seconds = 0;
minutes = minutes + 1;
}

GPIOB->ODR = (((seconds/10)<<4) | (seconds%10)) ;


GPIOG->ODR ^= (1<<13);
}

/* external interrupt handler */


void EXTI0_IRQHandler(void)
{
// Check if the interrupt came from EXTI0
if (EXTI->PR & (1 << 0)){
//TIM2->CR1 ^= 1 << 0;
++state;
if (state == 1)
TIM2->CR1 |= ( 1 << 0 ) ;
else if (state == 2)
{
TIM2->CR1 ^= ( 1 << 0 ) ;

}
else if (state == 3)
GPIOB->ODR = (((minutes/10)<<4) | (minutes%10));
else if (state == 4)
{
minutes = 0;
seconds = 0;
state = 0;
GPIOB->ODR = 0;
}

/* wait little bit */


//for(uint32_t j=0; j<1000000; j++);

// Clear pending bit


EXTI->PR = (1 << 0);
}
}

/* main code */
int main(void)
{

// enable GPIOG clock


RCC->AHB1ENR |= (1 << 6);
GPIOG->MODER &= 0x00000000;
GPIOG->MODER |= 0x55555555;

RCC->AHB1ENR |= (1 << 1);


GPIOB->MODER &= 0x00000000;
GPIOB->MODER |= 0x55555555;

// enable SYSCFG clock


RCC->APB2ENR |= (1 << 14);
SYSCFG->EXTICR[0] |= 0x00000000; // Write 0000 to map PA0 to EXTI0
EXTI->RTSR |= 0x00001; // Enable rising edge trigger on EXTI0
EXTI->IMR |= 0x00001; // Mask EXTI0

// Set Priority for each interrupt request


NVIC->IP[EXTI0_IRQn] = 0x10; // Priority level 1

// enable EXT0 IRQ from NVIC


NVIC->ISER[0] = 1 << EXTI0_IRQn;

// enable TIM2 clock


RCC->APB1ENR |= (1 << 0);

// set prescalar and autoreload value


TIM2->PSC = 8399;
TIM2->ARR = 10000;

// Update Interrupt Enable


TIM2->DIER |= (1 << 0);

// enable TIM2 IRQ from NVIC


NVIC->ISER[0] |= 1 << TIM2_IRQn;

// Enable Timer 2 module (CEN, bit0)


//TIM2->CR1 |= (1 << 0);

while (1);

Output:
The Output Video is attached in the zip file.

You might also like