本来是PC6是外部来的一个脉冲信号,PC7想输出个相位相反的信号。
想着把PC6设为上升/下降沿中断,然后在中断里判断PC6的状态,以此决定PC7输出是高或低。
结果PC7引脚始终是低电平。已排除PC7引脚配置错误的可能,用定时器中断使PC7一秒反转一次,波形是正常的。
然后就改PC6为上升沿中断,中断里将PC7反转一次。结果PC7仍未低电平。
求坛友看看PC6的配置程序和中断程序,是否有问题?
PC6配置程序:
- void PC6_ExintConfig(void)
- {
- EXTI_InitTypeDef EXTI_InitStructure;
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource6);
- EXTI_InitStructure.EXTI_Line = EXTI_Line6;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- }
复制代码
NVIC配置:
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
-
- NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
复制代码
中断程序:
- void EXTI9_5_IRQHandler(void)
- {
- if(EXTI_GetITStatus(EXTI_Line6) != RESET)
- {
- // if(COMP_OK() != 0)
- // LVDS_EN(0);
- // else
- // {
- // SPI_I2S_SendData(SPI2, spi2SendBuff[0]);
- // LVDS_EN(1);
- // }
- // EXTI_ClearITPendingBit(EXTI_Line6);
- GPIOC->ODR ^= GPIO_Pin_7;
- }
- }
复制代码
-----------------------------20160819-------------------------------------
补上GPIO配置:
- void GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
-
- AD7193_CS(ON);
- ADT7310_CS(ON);
- ADG738_CS(ON);
-
- PC6_ExintConfig();
- }
复制代码
----------------------20160819-----------------------------
还是没搞定,新建了个工程,只保留定时器和GPIO,测试定时器控制PA0反转,一秒闪一次,没问题。
然后用PC6外部中断控制PA0反转,其他电路给PC6每秒一个脉冲信号(用示波器捕捉到可,确定拉到PC6了),结果灯不亮...
附件为工程文件。
PB4æµè¯.zip
(321.83 KB, 下载次数: 10)
|
拿出来单独测试PC6中断的程序没问题了,然后又回到原来写的程序。
发现还是不行,然后比较了下,在排至PC6时,没有开AFIO时钟。
我是先配置普通GPIO,包括PC6,然后再配置的SPI3,此时才打开AFIO。
估计是因为打开的晚了,没起作用。
之前也没注意过用外部中断需要打开AFIO时钟,我太疏忽了。
额,板子上没有引出调试接口,以后画板会考虑把SW接口引出来...
已上传工程文件,能否帮看下?
因为用到了SPI2,所以使能了AFIO时钟。
没有仿真器...
IO配置了,已补上IO配置函数。
奈何没有仿真器...
现在的触发方式就是上升沿触发吧?
评分
查看全部评分
感谢帮助测试.
示波器直接量PC6管脚,也有波形。
现在怀疑芯片坏了?
最后是看到IO口配置时,没有配置输出速度这一项...我记得之前有的...
感谢各位回复。
评分
查看全部评分