Nt1310 Unit 5 Assignment 1

Words: 873
Pages: 4

Question 1
You are given a STM32F407VGT6 Microcontroller chip mounted on a STM32 F4 Series Discovery Kit. A C application will be complied as a hex image and burned onto the chip. The application is highly time depended and needs the time to be accurate to the second. This is because at certain times during the day, the application needs to perform a certain task. The same initially compiled hex image will be used to burn more chips in the future as well.
1. With the given information, please suggest a real world implementation for the time mechanism that will ensure accurate time readings throughout the life time of the application. Keep in mind that there is no OS on the chip, just the application. List any C libraries that you may use for your implementation
…show more content…
#include "stm32f4xx.h"
#include "stm32f4_discovery.h"

//Time base configuration void InitializeTimer(){
//enable TIM2 clock
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

//// 1 MHz down to 10 KHz (0.1 ms)
TIM_TimeBaseStructure.TIM_Period = 100 - 1;

// Down to 1 MHz (adjust per your clock)
TIM_TimeBaseStructure.TIM_Prescaler = 84 - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);

//Update/interupt enable
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
}

//Enable the TIM2 global interrupt void EnableTIM2Interrupt(){
NVIC_InitTypeDef nvicStructure; nvicStructure.NVIC_IRQChannel = TIM2_IRQn; nvicStructure.NVIC_IRQChannelPreemptionPriority = 0; nvicStructure.NVIC_IRQChannelSubPriority = 1; nvicStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicStructure);
}

//interrupt controller configuration void TIM2_IRQHandler()
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
}