【MCU实战经验】基于STM32F103C8T6的hart总线调试器设计
求教STM32F103进入STOP模式后用外部中断唤醒的问题
基于STM32F103RCT6的无源蜂鸣器音乐播放(生日快乐歌)
STM32F103c8t6有没有DAC 功能?
STM32F103x中文数据手册
新手求教,为何在我电脑上找不到STM32F1Xx.h文件
金龙107例程汇总(STM32F107)
万利STM32F107VC 原理图
STM32F103 ADC多通道检测必须要DMA吗?
【官方例程】STM32F107以太网官方例程
RE:STM32F10x 的EXTI 問題
/* Connect EXTI9 Line to PB.09 pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);
/* Configure EXTI9 line */
EXTI_InitStructure.EXTI_Line = EXTI_Line9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI9_5 Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/**
* @brief This function handles External lines 9 to 5 interrupt request.
* @param None
* @retval None
*/
void EXTI9_5_IRQHandler(void)
{
#if defined (STM32F10X_HD_VL) || defined (STM32F10X_HD) || defined (STM32F10X_XL)
if(EXTI_GetITStatus(EXTI_Line8) != RESET)
{
/* Toggle LED2 */
STM_EVAL_LEDToggle(LED2);
/* Clear the EXTI line 8 pending bit */
EXTI_ClearITPendingBit(EXTI_Line8);
}
#else
if(EXTI_GetITStatus(EXTI_Line9) != RESET)
{
/* Toggle LED2 */
STM_EVAL_LEDToggle(LED2);
/* Clear the EXTI line 9 pending bit */
EXTI_ClearITPendingBit(EXTI_Line9);
}
#endif
}
回复:STM32F10x 的EXTI 問題
当然可以设置EXIT5~EXIT15
/* Connect EXTI9 Line to PB.09 pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);
/* Configure EXTI9 line */
EXTI_InitStructure.EXTI_Line = EXTI_Line9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI9_5 Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/**
* @brief This function handles External lines 9 to 5 interrupt request.
* @param None
* @retval None
*/
void EXTI9_5_IRQHandler(void)
{
#if defined (STM32F10X_HD_VL) || defined (STM32F10X_HD) || defined (STM32F10X_XL)
if(EXTI_GetITStatus(EXTI_Line8) != RESET)
{
/* Toggle LED2 */
STM_EVAL_LEDToggle(LED2);
/* Clear the EXTI line 8 pending bit */
EXTI_ClearITPendingBit(EXTI_Line8);
}
#else
if(EXTI_GetITStatus(EXTI_Line9) != RESET)
{
/* Toggle LED2 */
STM_EVAL_LEDToggle(LED2);
/* Clear the EXTI line 9 pending bit */
EXTI_ClearITPendingBit(EXTI_Line9);
}
#endif
}
大大您好
我懂您所寫的
但是庫件裡面沒有EXTI9_5_IRQHandler的定義
請問這是要自己定義嗎?
回复:STM32F10x 的EXTI 問題【悬赏问答】
RE:STM32F10x 的EXTI 問題【悬赏问答】
/**
* @brief Configure PB.09 or PG.08 in interrupt mode
* @param None
* @retval None
*/
void EXTI9_5_Config(void)
{
#if defined (STM32F10X_HD_VL) || defined (STM32F10X_HD) || defined (STM32F10X_XL)
/* Enable GPIOG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE);
/* Configure PG.08 pin as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOG, &GPIO_InitStructure);
/* Enable AFIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/* Connect EXTI8 Line to PG.08 pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOG, GPIO_PinSource8);
/* Configure EXTI8 line */
EXTI_InitStructure.EXTI_Line = EXTI_Line8;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI9_5 Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#else
/* Enable GPIOB clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/* Configure PB.09 pin as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Enable AFIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/* Connect EXTI9 Line to PB.09 pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);
/* Configure EXTI9 line */
EXTI_InitStructure.EXTI_Line = EXTI_Line9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI9_5 Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#endif
}
配置:Configure PB.09 or PG.08 in interrupt mode PG 08 09 中断模式
中断函数:
void EXTI9_5_IRQHandler(void)
{
#if defined (STM32F10X_HD_VL) || defined (STM32F10X_HD) || defined (STM32F10X_XL)
if(EXTI_GetITStatus(EXTI_Line8) != RESET)
{
/* Toggle LED2 */
STM_EVAL_LEDToggle(LED2);
/* Clear the EXTI line 8 pending bit */
EXTI_ClearITPendingBit(EXTI_Line8);
}
#else
if(EXTI_GetITStatus(EXTI_Line9) != RESET)
{
/* Toggle LED2 */
STM_EVAL_LEDToggle(LED2);
/* Clear the EXTI line 9 pending bit */
EXTI_ClearITPendingBit(EXTI_Line9);
}
#endif
}
回复:STM32F10x 的EXTI 問題【悬赏问答】
、PA0 ... PF0 共用一个中断标志 EXT0
PA1 ... PF1 共用一个中断标志 EXT1
. .
. .
PA15... PF15共用一个中断标志 EXT15
2、EXT5-9 共用一个中断源
EXT10-15 共用一个中断源
3、启用中断前,需ENABLE IO口的复用功能(AFIO)
4、设置中断IO口
5、将IO口注册到中断线(将IO口映射到中断线N)
例:GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3); 将GPIOD.3注册至
中断线EXTILine3
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource4); 将GPIOD.4注册至
中断线EXTILine4
6、配置中断
EXTI_InitStructure.EXTI_Line = EXTI_Line3;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; 中断
= EXTI_Mode_Event 事件(触发其它模块)
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising 上升沿触发
= EXTI_Trigger_Falling 下降沿触发
= EXTI_Trigger_Rising_Falling 脉冲触发
7、配置NVIC
8、如果使用库函数写中断,要开放stm32f10x_conf.h中的相应中断
----------------------------------------------------------------------------------------------------
例:
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE);
/* PD3,4,5,6按键输入*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* 连接IO口到中断线 */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource4);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource5);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource6);
/* 配置中断线3为边降沿触发*/
EXTI_InitStructure.EXTI_Line = EXTI_Line3;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/*其他为下降沿触发*/
EXTI_InitStructure.EXTI_Line = EXTI_Line4|EXTI_Line5|EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
RE:STM32F10x 的EXTI 問題【悬赏问答】
/*
外部中断/事件我的理解是可以将单片机的IO口全部设置为外部中断口,我们可以根据触发哪个IO口中断,去执行相应的中断处理函数。这个其实很简单,51一般有2个外部中断口,而stm32将其扩展,每个IO口都可以作为外部中断口。
外部中断配置也很简单,只需要打开相应的IO口配置,时钟,打开stm32f10x_conf.h里的 #include "stm32f10x_exti.h" ,配置EXIT和中断处理函数即可。下面是简单的实例(基于3.0库):
*/
void GPIO_Configuration(void)
{
//配置GPIOC_5口作为外部中断口
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_InitStructure.EXTI_Line = EXTI_Line5; //外部中断线
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //中断模式
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //中断触发方式
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //打开中断
EXTI_Init(&EXTI_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource5); //选择 GPIO管脚用作外部中断线路
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); // 抢占式优先级别
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //指定中断源
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // 指定响应优先级别1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//中断处理函数
void EXTI9_5_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line5) != RESET)
{
//添加中断处理程序
EXTI_ClearFlag(EXTI_Line5);
//EXTI_ClearITPendingBit(EXTI_Line5); //本函数与上一句功能相同
}
}
RE:STM32F10x 的EXTI 問題【悬赏问答】
RE:STM32F10x 的EXTI 問題【悬赏问答】