2013-09-20 06:40 PM
TIM2->
EGR
|= TIM_EGR_UG
) is meant to be updating the flag every time the Counter reaches ARR value. I really don't seems to see why it isn't working can someone help me? Many Thanks again Regards Entropy/*
Timer ISR running on STM32F407VG with COIDE Please ignore the comments were meant for other development code. Thanks*/
#include<stdint.h>
#include<stdlib.h>
#include <stdbool.h>
#include''stm32f4xx.h''
#include''stm32f4xx_rcc.h''
#include''stm32f4xx_tim.h''
#include''stm32f4xx_gpio.h''
#include''core_cm4.h''
volatile bool Process_Task = false;
void _delay_us(uint32_t us);
void _delay_ms(uint32_t ms);
void
TIM2_IRQHandler(
void
);int main()
{
SystemInit();
GPIO_InitTypeDef
GPIO_InitStructure; GPIO_InitStructure;RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,
ENABLE
);RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3,
ENABLE
);GPIO_InitStructure.
GPIO_Pin
= GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;GPIO_InitStructure.
GPIO_Mode
=
GPIO_Mode_OUT
;GPIO_InitStructure.
GPIO_OType
=
GPIO_OType_PP
;GPIO_InitStructure.
GPIO_Speed
=
GPIO_Speed_100MHz
;GPIO_InitStructure.
GPIO_PuPd
=
GPIO_PuPd_NOPULL
;GPIO_Init(GPIOD, &GPIO_InitStructure);
NVIC_InitTypeDef
NVIC_InitStructure;/* Enable the TIM2
gloabal
Interrupt */ NVIC_InitStructure.NVIC_IRQChannel
=
TIM2_IRQn
;NVIC_InitStructure.
NVIC_IRQChannelPreemptionPriority
= 0;NVIC_InitStructure.
NVIC_IRQChannelSubPriority
= 1;NVIC_InitStructure.
NVIC_IRQChannelCmd
=
ENABLE
;NVIC_Init(&NVIC_InitStructure);
/* TIM2 clock enable */
TIM2->
PSC
= 41999;TIM2->
ARR
= 3999;TIM2->
CNT
= 0;TIM2->
EGR
|= TIM_EGR_UG;TIM2->
SR
&= ~ TIM_SR_UIF;TIM2->
CR1
|= (TIM_CR1_OPM);
// Clear the update flagTIM2->
DIER
|= TIM_DIER_UIE;
// Enable interrupt on update eventNVIC_EnableIRQ(
TIM2_IRQn
);
// Enable TIM6 IRQTIM2->
CR1
|= TIM_CR1_CEN; // Enable TIM6 counter//while (!(TIM2->SR & TIM_SR_UIF));
while
(1){
GPIOD->
ODR
^= 1<<13; _delay_ms(100);}
}
void
TIM2_IRQHandler(
void
){
if
(TIM2->
SR
& (TIM_SR_UIF))// If update flag is set
{ {
GPIOD->
ODR
^= 1<<15; TIM2->SR
&= ~TIM_SR_UIF;
//Clear it. //Process_Task = true; // Set D15 high// GPIOD->ODR |= 1<<15; // Interrupt has been handled
//_delay_ms(15);
}
//delay_ms(15);
}
void _delay_us(uint32_t us)
{
TIM3->
PSC
= 83 ;
TIM3->
ARR
= us -1TIM3->
CNT
= 0;TIM3->
EGR
|= TIM_EGR_UG;TIM3->
SR
&= ~ TIM_SR_UIF;TIM3->
CR1
|= (TIM_CR1_OPM);
// Clear the update flagTIM3->
CR1
|= TIM_CR1_CEN;while
(!(TIM3->
SR
& TIM_SR_UIF));}
void _delay_ms(uint32_t ms)
{
while
( ms -- > 0) {_delay_us(1000);
}
}
2013-09-20 08:26 PM
I'm not interest in debugging register level code however
http://www.catb.org/esr/faqs/smart-questions.html#urgent
it may be. You mustn't RMW the TIM SR registers : TIM2->SR &= ~TIM_SR_UIF; //Clear it. but rather TIM2->SR = ~TIM_SR_UIF; // etc Implement what you want to do with library code, if that works then you can get creative. If you want to spin for time, then just use a fast free running timer and compute a delta for CNT over the period you wish to dwell. Don't faff about with OPM2013-09-22 03:26 AM
2013-09-23 09:10 AM
2013-09-23 09:39 AM
The 5V typically comes from the USB supply, the current budget is limited. Probably sufficient for an LCD, but check the specs.
There are also displays that run from 3.3V, although the Discovery boards run a 3V, and I'm not sure of the current budget on that regulator.http://www.keil.com/mcbstm32/mcbstm32-schematics.pdf
Should definitely order parts you might fry in Qty >22013-09-24 04:07 AM
2013-09-24 09:04 AM
That's a mess, edit the post and use the ''Format Code Block'' icon (Paintbrush [<>])
2013-09-25 10:18 AM
void Check_if_LCD_is_Busy()
{ DDRB = 0x00; PORTD |= 1<<RW; PORTD &= ~1<<RS;while(PORTB >= 0x80)
{ Set_LCD_up(); } DDRB = 0xFF; } As I understand on Cortex we can directly also change the whole Port Data via ''MODER'' Register but I am unsure! Could you please translate the above ''void Check_if_LCD_is_Busy(void)'' Function to suit the stm32f407? Many Thanks.That's a mess, edit the post and use the ''Format Code Block'' icon (Paintbrush [<>])
2013-09-25 06:19 PM
The MODER bits for each pin need to be ''01'' for the output, and ''00'' for the input.
2013-09-30 02:53 AM
while
((GPIOA->
IDR
& (0x000000FF)) >= 0x00000080)
{
. . . . . .
}
?
if not can you help me to generate the correct Syntax?
// Because ARM GPIOs are 32 bits I have masked it to only allow the last 8 bits to be read (Data)
However the code still isn't working there seems to be many Bugs that I have to fix
Thanks again.
Cheers
However the code still isn't working there seems to be many Bugs that I have to fixThanks again.Cheersclive1Thursday, September 26, 2013 3:19 AMHi All I needed an urgent help on Timer Interrupt. Thanksc {STM32F407VG}
The MODER bits for each pin need to be ''01'' for the output, and ''00'' for the input.