Witam,
Zacząłem niedawno zabawę z STM32 i mam problem z przerwaniami oraz timerami.
Chciałem uruchomić przerwanie zewnętrzne, a dalej przerwanie od timera co np 1sek. Jednak nie działa ani jedno ani drugie, czy ktoś mógłby nakierować mnie na dobrą drogę i powiedzieć co robię źle? Przeglądałem przykładowe aplikacje jednak dalej nie potrafię tego uruchomić. Układ na jakim się bawię to STM32 Primer I.
Przykładowy kod do uruchomienia przerwania zewnętrznego:
Podprogram obsługi przerwania:
Gdy próbuje uruchomić przerwanie od jakiegoś timera również nie ma reakcji, rejestry ustawiają się poprawnie jednak licznik timera nic nie zlicza - kodu dotyczącego timera narazie nie podaje bo może sprawa się wyjaśni kiedy uruchomie przerwanie od zdarzenia zewnętrznego.
W czym tkwi problem?
Dzięki z góry za pomoc!
Pozdrawiam
Marcin
Zacząłem niedawno zabawę z STM32 i mam problem z przerwaniami oraz timerami.
Chciałem uruchomić przerwanie zewnętrzne, a dalej przerwanie od timera co np 1sek. Jednak nie działa ani jedno ani drugie, czy ktoś mógłby nakierować mnie na dobrą drogę i powiedzieć co robię źle? Przeglądałem przykładowe aplikacje jednak dalej nie potrafię tego uruchomić. Układ na jakim się bawię to STM32 Primer I.
Przykładowy kod do uruchomienia przerwania zewnętrznego:
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_conf.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
/* System Clocks Configuration */
RCC_Configuration();
/* NVIC Configuration */
NVIC_Configuration();
/* Enable GPIOB clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/* Configure PE.12, PE.11, PE.10 and PE.09 i PE.08 as INPUT FLOATING */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_8 | GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* Configure PE.14, PE.15 as output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
EXTI_InitStruct.EXTI_Line = EXTI_Line0;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
while(1)
{
}
}
/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RCC_Configuration(void)
{
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET)
{;}
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK */
RCC_PCLK1Config(RCC_HCLK_Div1);
/* Select HSE as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
/* Wait till HSE is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x04)
{;}
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
}
/*******************************************************************************
* Function Name : assert_failed
* Description : Reports the name of the source file and the source line number
* where the assert error has occurred.
* Input : - file: pointer to the source file name
* - line: assert error line source number
* Output : None
* Return : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
Podprogram obsługi przerwania:
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
GPIO_WriteBit(GPIOB, GPIO_Pin_8, (BitAction) ((1- GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_0))));
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
Gdy próbuje uruchomić przerwanie od jakiegoś timera również nie ma reakcji, rejestry ustawiają się poprawnie jednak licznik timera nic nie zlicza - kodu dotyczącego timera narazie nie podaje bo może sprawa się wyjaśni kiedy uruchomie przerwanie od zdarzenia zewnętrznego.
W czym tkwi problem?
Dzięki z góry za pomoc!
Pozdrawiam
Marcin