Interrupt help anyone?...[stm32]
Hi all,
I'm just trying to get TIM3 to call my IRQ handler every one second...Was wondering if anyone could point out the issues etc...
I know I need to adjust my PSC and ARR values...
Thoughts? Pointers?
Thanks in advance!
~Kam (^8*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include "stdint.h"
#include "targets/STM32F10x.h"
// LED1 is on PC12
// The button is on PA0
#define SET_BIT(REG, BIT) ((REG) |= (BIT))
#define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))
#define READ_BIT(REG, BIT) ((REG) & (BIT))
#define CLEAR_REG(REG) ((REG) = (0x0))
#define WRITE_REG(REG, VAL) ((REG) = (VAL))
#define READ_REG(REG) ((REG))
#define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
volatile uint32_t flag=1;
// init's the LED on RA12
void initLED(void)
{
// configure LED ports
RCC_APB2ENR |= RCC_APB2ENR_IOPCEN;
uint32_t pin = 4;
uint32_t mode = (uint32_t)0x05 << (pin * 4);
uint32_t mask = (uint32_t)0x0f << (pin * 4);
uint32_t temp = GPIOC_CRH & ~mask;
GPIOC_CRH = temp | mode;
}
// crossworks handler name
void TIM3_IRQHandler(void)
{
if(flag==1)
{
GPIOC_BSRR = (1<<12); // turn on LED
flag=0;
}
else
{
GPIOC_BRR = (1<<12); // turn off LED
flag=1;
}
CLEAR_BIT(TIM3_SR, TIM3_SR_UIF_MASK);
SET_BIT(Irq_0_to_31_Clear_Pending, 1 << 29);
}
// I'm running at 72MHz
// I want a one second "beat"
void initTim3()
{
SET_BIT(RCC_APB1ENR, RCC_APB1ENR_TIM3EN);
CLEAR_BIT(TIM3_CR1, TIM3_CR1_CEN_MASK);
SET_BIT(TIM3_CR1, TIM3_CR1_ARPE);
WRITE_REG(TIM3_PSC, 1000);
WRITE_REG(TIM3_ARR, 70);
WRITE_REG(TIM3_CNT, 0);
SET_BIT(TIM3_DIER, TIM3_DIER_UIE);
SET_BIT(Irq_0_to_31_Clear_Pending, 1 << 29);
SET_BIT(Irq_0_to_31_Set_Enable, 1 << 29);
}
void main(void)
{
initLED();
initTim3();
while(1)
{
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
ooops, forgot to enable timer! Still does not work...boooo...
#include "stdint.h"
#include "targets/STM32F10x.h"
// LED1 is on PC12
// The button is on PA0
#define SET_BIT(REG, BIT) ((REG) |= (BIT))
#define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))
#define READ_BIT(REG, BIT) ((REG) & (BIT))
#define CLEAR_REG(REG) ((REG) = (0x0))
#define WRITE_REG(REG, VAL) ((REG) = (VAL))
#define READ_REG(REG) ((REG))
#define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
volatile uint32_t flag=1;
// init's the LED on RA12
void initLED(void)
{
// configure LED ports
RCC_APB2ENR |= RCC_APB2ENR_IOPCEN;
uint32_t pin = 4;
uint32_t mode = (uint32_t)0x05 << (pin * 4);
uint32_t mask = (uint32_t)0x0f << (pin * 4);
uint32_t temp = GPIOC_CRH & ~mask;
GPIOC_CRH = temp | mode;
}
// crossworks handler name
void TIM3_IRQHandler(void)
{
if(flag==1)
{
GPIOC_BSRR = (1<<12); // turn on LED
flag=0;
}
else
{
GPIOC_BRR = (1<<12); // turn off LED
flag=1;
}
CLEAR_BIT(TIM3_SR, TIM3_SR_UIF_MASK);
SET_BIT(Irq_0_to_31_Clear_Pending, 1 << 29);
}
// I'm running at 72MHz
// I want a one second "beat"
void initTim3()
{
SET_BIT(RCC_APB1ENR, RCC_APB1ENR_TIM3EN); // enable clock to timer
CLEAR_BIT(TIM3_CR1, TIM3_CR1_CEN_MASK); // disable tim3
SET_BIT(TIM3_CR1, TIM3_CR1_ARPE); // auto reload counter value
WRITE_REG(TIM3_PSC, 1000); // set PSC
WRITE_REG(TIM3_ARR, 70); // set ARR
WRITE_REG(TIM3_CNT, 0); // clear counter value
SET_BIT(TIM3_DIER, TIM3_DIER_UIE); // enable int on overflow
SET_BIT(Irq_0_to_31_Clear_Pending, 1 << 29); // clear pending int
SET_BIT(Irq_0_to_31_Set_Enable, 1 << 29); // enable int
SET_BIT(TIM3_CR1, TIM3_CR1_CEN); // enable tim3
}
void main(void)
{
initLED();
initTim3();
while(1)
{
}
}
Please sign in to leave a comment.
Comments
1 comment