本帖最后由 877049204 于 2018-6-25 16:56 编辑
今天在调试STM32F407下位机与A5上位机通信协议时总结了一些经验,记录一下。
首先第一个问题:
数据传输由外部100ms的触发信号进行触发,STM32的PD8管脚配置为外部中断,将GPIO配置为外部中断时有以下几个步骤:
1、使能相关时钟:
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//ʹÄÜSYSCFGʱÖÓ
2、配置管脚:
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//WK_UP????PA0
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;//??
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);//???GPIOA0
注意不需要将管脚配置为输入模式
3、将中断线与管脚相连,STM32F407有15条中断线,对应GPIO0~15,
#define EXTI_PinSource0 ((uint8_t)0x00)
#define EXTI_PinSource1 ((uint8_t)0x01)
#define EXTI_PinSource2 ((uint8_t)0x02)
#define EXTI_PinSource3 ((uint8_t)0x03)
#define EXTI_PinSource4 ((uint8_t)0x04)
#define EXTI_PinSource5 ((uint8_t)0x05)
#define EXTI_PinSource6 ((uint8_t)0x06)
#define EXTI_PinSource7 ((uint8_t)0x07)
#define EXTI_PinSource8 ((uint8_t)0x08)
#define EXTI_PinSource9 ((uint8_t)0x09)
#define EXTI_PinSource10 ((uint8_t)0x0A)
#define EXTI_PinSource11 ((uint8_t)0x0B)
#define EXTI_PinSource12 ((uint8_t)0x0C)
#define EXTI_PinSource13 ((uint8_t)0x0D)
#define EXTI_PinSource14 ((uint8_t)0x0E)
#define EXTI_PinSource15 ((uint8_t)0x0F)
调用函数:
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOD, EXTI_PinSource8);//PA0 Á¬½Óµ½ÖжÏÏß0
4、配置中断线参数
/* ÅäÖÃEXTI_Line0 */
EXTI_InitStructure.EXTI_Line = EXTI_Line8;//LINE0
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//ÖжÏʼþ
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //ÉÏÉýÑØ´¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;//ʹÄÜLINE0
EXTI_Init(&EXTI_InitStructure);//ÅäÖÃ
5、中断管理,注意中断通道对应EXTI9_5_IRQn,而不是EXTI8_IRQn,STM32的GPIO0~4对应中断线0~4,有各自的中断入口,而GPIO5~9
共用一个中断向量EXTI9_5_IRQn,GPIO10~15也共用一个中断向量EXTI15_10_IRQn
<font color="black"> </font>NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;//EXTI0_IRQn;//ÍⲿÖжÏ0
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;//ÇÀÕ¼ÓÅÏȼ¶0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//×ÓÓÅÏȼ¶2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//ʹÄÜÍⲿÖжÏͨµÀ
NVIC_Init(&NVIC_InitStructure);//ÅäÖÃ
EXTI0_IRQn = 6, /*!< EXTI Line0 Interrupt */
EXTI1_IRQn = 7, /*!< EXTI Line1 Interrupt */
EXTI2_IRQn = 8, /*!< EXTI Line2 Interrupt */
EXTI3_IRQn = 9, /*!< EXTI Line3 Interrupt */
EXTI4_IRQn = 10, /*!< EXTI Line4 Interrupt */
EXTI9_5_IRQn = 23, /*!< External Line[9:5] Interrupts */
EXTI15_10_IRQn = 40, /*!< External Line[15:10] Interrupts */
|
@山东电子小菜鸟 :在青岛中国石油大学,前辈呢
楼主在山东哪个地方读研
楼主在山东哪个地方读研