我想起用外部中断0和外部中断6。经过我的设置,程序总是在外部中断6的服务程序里运行。PC6的电平一直是低电平。下面是我的设置:
I/O口设置:
void CC113L_SPI_GPIOInit(void)
{
GPIO_Init(GPIOD, GPIO_Pin_0, GPIO_Mode_In_FL_IT); //GDO0 外部中断0
GPIO_Init(GPIOB, GPIO_Pin_5, GPIO_Mode_Out_PP_Low_Slow); //SCK
GPIO_Init(GPIOA, GPIO_Pin_3, GPIO_Mode_Out_PP_Low_Slow); //MOSI
GPIO_Init(GPIOA, GPIO_Pin_2, GPIO_Mode_In_PU_No_IT); //MISO
GPIO_Init(GPIOC, GPIO_Pin_4, GPIO_Mode_Out_PP_Low_Slow); //CSN
GPIO_Init(GPIOC, GPIO_Pin_5, GPIO_Mode_In_FL_No_IT);
}
void USART_GpioInit(void)
{
GPIO_Init(GPIOC, GPIO_Pin_6, GPIO_Mode_In_FL_IT); //外部中断6
GPIO_Init(GPIOC, GPIO_Pin_0, GPIO_Mode_Out_PP_High_Slow); //PC0
}
void EXIT_Init(void)
{
EXTI_DeInit();
EXTI_SetPinSensitivity(GPIO_Pin_0,EXTI_Trigger_Rising);
EXTI_SetPinSensitivity(GPIO_Pin_6,EXTI_Trigger_Falling);
ITC_SetSoftwarePriority(EXTI6_IRQn,ITC_PriorityLevel_3);
ITC_SetSoftwarePriority(EXTI0_IRQn,ITC_PriorityLevel_2);
EXTI_ClearITPendingBit(EXTI_IT_Pin6);
EXTI_ClearITPendingBit(EXTI_IT_Pin0);
enableInterrupts();
}
下面是Vector.c里的设置:
#include "stm8l15x_it.h"
typedef void @far (*interrupt_handler_t)(void);
struct interrupt_vector {
unsigned char interrupt_instruction;
interrupt_handler_t interrupt_handler;
};
@far @interrupt void NonHandledInterrupt (void)
{
/* in order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction
*/
return;
}
extern void _stext(); /* startup routine */
extern void EXTI0_IRQHandler(void);
extern void EXTI6_IRQHandler(void);
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap */
{0x82, NonHandledInterrupt}, /* irq0 */
{0x82, NonHandledInterrupt}, /* irq1 */
{0x82, NonHandledInterrupt}, /* irq2 */
{0x82, NonHandledInterrupt}, /* irq3 */
{0x82, NonHandledInterrupt}, /* irq4 */
{0x82, NonHandledInterrupt}, /* irq5 */
{0x82, NonHandledInterrupt}, /* irq6 */
{0x82, NonHandledInterrupt}, /* irq7 */
{0x82, EXTI0_IRQHandler}, /* irq8 */
{0x82, NonHandledInterrupt}, /* irq9 */
{0x82, NonHandledInterrupt}, /* irq10 */
{0x82, NonHandledInterrupt}, /* irq11 */
{0x82, NonHandledInterrupt}, /* irq12 */
{0x82, NonHandledInterrupt}, /* irq13 */
{0x82, EXTI6_IRQHandler}, /* irq14 */
{0x82, NonHandledInterrupt}, /* irq15 */
{0x82, NonHandledInterrupt}, /* irq16 */
{0x82, NonHandledInterrupt}, /* irq17 */
{0x82, NonHandledInterrupt}, /* irq18 */
{0x82, NonHandledInterrupt}, /* irq19 */
{0x82, NonHandledInterrupt}, /* irq20 */
{0x82, NonHandledInterrupt}, /* irq21 */
{0x82, NonHandledInterrupt}, /* irq22 */
{0x82, NonHandledInterrupt}, /* irq23 */
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, NonHandledInterrupt}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, NonHandledInterrupt}, /* irq27 */
{0x82, NonHandledInterrupt}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
};
外部中断6的服务程序:
@far @interrupt void EXTI6_IRQHandler(void)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
EXTI_ClearITPendingBit(EXTI_IT_Pin6);
time_ok = 1;
sleep_ok = 1;
}
|
|