Merhaba stm32f103rb harici kesmeyi öğrenmeye çalışıyorum.Çalışan kodda harici kesme RA0 ile yapılmış.Ben bunu RA1 ile yapmayı denedim ama işin içinden çıkamadım.
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_usart.h"
#include "stm32f10x_exti.h"
#include "misc.h"
#include "hardware.h"
#include "usart.h"
#include <stdio.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
const char menu[] =
"\n\r"
"*********************** MINI-STM32***********************\n\r"
"*-------------------------------------------------------*\n\r";
/* Private function prototypes -----------------------------------------------*/
void GPIO_Configuration(void);
void NVIC_Configuration(void);
uint8_t KEY_Scan(void);
void Delay(uint16_t time);
/* Private functions ---------------------------------------------------------*/
EXTI_InitTypeDef EXTI_InitStructure;
/*****************************************************************************
** º¯ÊıÃû³Æ: main
** ¹¦ÄÜÃèÊö: Ö÷º¯ÊıÈë¿Ú
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
*****************************************************************************/
int main(void)
{
// uint8_t key; //¶¨ÒåÒ»¸ö¼üÖµ
SystemInit(); //ÅäÖÃϵͳʱÖÓ72M(°üÀ¨clock, PLL and Flash configuration)
GPIO_Configuration(); // Òı½ÅÅäÖÃ
NVIC_Configuration(); //ϵͳÖжÏÅäÖÃ
USART_Configuration(); //Ò첽ͨĞųõʼ»¯
USART_Send_Str(menu);
/* Connect Key Button EXTI Line to Key Button GPIO Pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource1);
/* Configure Key Button EXTI Line to generate an interrupt on falling edge */
EXTI_InitStructure.EXTI_Line = EXTI_Line1; //ÍⲿÖжÏ0
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //ÖжÏģʽ
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //ϽµÑزúÉúÖжÏ
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //ʹÄÜÖжÏÏß0ÉÏÖжÏ
EXTI_Init(&EXTI_InitStructure);
while (1)
{
LED2 =!LED2;
Delay(5000);
}
}
/*****************************************************************************
** º¯ÊıÃû³Æ: GPIO_Configuration
** ¹¦ÄÜÃèÊö: ÅäÖÃIO¿Ú
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
*****************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1
, ENABLE); // ʹÄܶ˿ÚʱÖÓ£¬ÖØÒª£¡£¡£¡
/* ÅäÖà LED1¡¢LED2Òı½ÅµÄ¹¦ÄÜ *********************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ͨÓÃÍÆÍìÊä³öģʽ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //Êä³ö×î´óƵÂÊΪ50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //³õʼ»¯PA2¡¢PA3
/* ÅäÖà KEY1¡¢KEY2Òı½ÅµÄ¹¦ÄÜ *********************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //ÉÏÀÊäÈëģʽ
GPIO_Init(GPIOA, &GPIO_InitStructure); //³õʼ»¯PA0¡¢PA1
/* ÅäÖÃ USART1 Tx (PA9) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸´ÓÿªÂ©Êä³öģʽ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //Êä³ö×î´óƵÂÊΪ50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* ÅäÖÃ USART1 Rx (PA10) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸¡¿ÕÊäÈëģʽ
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/*****************************************************************************
** º¯ÊıÃû³Æ: KEY_Scan
** ¹¦ÄÜÃèÊö: °´¼ü´¦Àíº¯Êı
0£¬Ã»ÓĞÈκΰ´¼ü°´Ï 1£¬KEY1°´ÏÂ
2£¬KEY2°´ÏÂ
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
*****************************************************************************/
uint8_t KEY_Scan(void)
{
static uint8_t KEY_UP=1; //°´¼ü°´ËÉ¿ª±êÖ¾
if(KEY_UP&&(KEY1==0||KEY2==0))
{
Delay(10); //È¥¶¶¶¯
KEY_UP=0;
if(KEY1==0)return 1;
else if(KEY2==0)return 2;
}else if(KEY1==1&&KEY2==1)KEY_UP=1;
return 0; //ÎŞ°´¼ü°´ÏÂ
}
/*****************************************************************************
** º¯ÊıÃû³Æ: Delay
** ¹¦ÄÜÃèÊö: ÑÓʱһ¶Îʱ¼ä
time <65536;
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
*****************************************************************************/
void Delay(uint16_t time)
{
uint16_t i,j;
for(i=time;i>0;i--)
{
for(j=500;j>0;j--);
}
}
/*****************************************************************************
** º¯ÊıÃû³Æ: NVIC_Configuration
** ¹¦ÄÜÃèÊö: ϵͳÖжϹÜÀí
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
*****************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*****************************************************************************
** º¯ÊıÃû³Æ: EXTI0_IRQHandler
** ¹¦ÄÜÃèÊö: ÍⲿÖжÏ0½øÈë¿Ú
´¦ÀíÖжϺ¯Êı
** ×÷ ¡¡Õß: Dream
** ÈÕ¡¡ ÆÚ: 2010Äê12ÔÂ17ÈÕ
*****************************************************************************/
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line1) != RESET)
{
Delay(50); //ÑÓʱȡÏû¶¶
LED1 =!LED1; //LED1·×ª
EXTI_ClearITPendingBit(EXTI_Line1); //Çå³ıLINE13ÉϵÄÖжϱê־λ
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval : None
*/
void assert_failed(uint8_t* file, uint32_t 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)
{
}
}
#endif
/*******************************************************************************
** End of File
********************************************************************************/
Örnek kodda yaptığım değişiklikler
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0); -> GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource1);
EXTI_InitStructure.EXTI_Line = EXTI_Line0; -> EXTI_InitStructure.EXTI_Line = EXTI_Line1; yaptım.
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; -> NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
ve kesmedeki EXTI_Line0 ' ları EXTI_Line1 yaptım.Ama bi türlü çalışmıyor.
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
AFIO clock'u enable ettin mi ? kodlarda göremedim
http://muhittinkaplan.com/2013/01/stm32f103rb-ile-exti10_15-kesmesi/ (http://muhittinkaplan.com/2013/01/stm32f103rb-ile-exti10_15-kesmesi/)
mesaj birleştirme:: 20 Aralık 2013, 18:09:23
http://muhittinkaplan.com/2012/11/external-interrupt-on-stm32vl-discovery/ (http://muhittinkaplan.com/2012/11/external-interrupt-on-stm32vl-discovery/)
@magnetron Baktığım örnekler AFIO kullanmamış.Ama bi değişiklik olmadı.
@muhittin hocam bu konuyu bakarkan ilk önce sizin örneklerle karşılaştırarak yapmaya çalıştım.Ama sizin örneğinizde de PA0 kullanılmıştı.
Sorunu çözdüm sıkıntı kesme fonksiyon adından kaynaklanıyormuş.
void EXTI0_IRQHandler(void) -> void EXTI1_IRQHandler(void)
sorunu düzeltti.