请各位指教,在配置完SPI1,再去配置外部中断无法被触发,有试过把SPI1配置拿掉,外部中断就可以被触发了,以下是几个相关的函数。。帮忙看下,感谢外部中断配置:
void EXTI_B4_CONFIG(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
//NVIC_InitTypeDef NVIC_InitStruture;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO,ENABLE);
//config the IRQ pin,B0
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4;
//GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;//IP IPD IPU
GPIO_Init(GPIOB, &GPIO_InitStructure);
///RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//
EXTI_ClearITPendingBit(EXTI_Line4);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource4);
EXTI_InitStructure.EXTI_Line=EXTI_Line4;//
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;//falling edge trigger interrupt
EXTI_Init(&EXTI_InitStructure);
}
SPI1配置:
void SPI1_CONFIG(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);
//config the sck ,MISO,MOSI pin
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//config ce pin,A4
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4|GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//config the CS pin,A3
//GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;
//GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
//GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
//GPIO_Init(GPIOA, &GPIO_InitStructure);
SPI_CS_H();
SPI_InitStructure.SPI_Direction=SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode=SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize=SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL=SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA=SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS=SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_8;
SPI_InitStructure.SPI_FirstBit=SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial=7;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);
}
NVIC 配置:
void NVIC_Config(void)
{
//config nrf24l01 interrupt
NVIC_InitTypeDef NVIC_InitStruture;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStruture.NVIC_IRQChannel=EXTI4_IRQn;//EXTI9_5_IRQn;
NVIC_InitStruture.NVIC_IRQChannelPreemptionPriority=1;//抢占优先级
NVIC_InitStruture.NVIC_IRQChannelSubPriority=2;//响应优先级
NVIC_InitStruture.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStruture);
NVIC_SetPriority(SysTick_IRQn,NVIC_EncodePriority(NVIC_PriorityGroup_2, 2,0));
//NVIC_EnableIRQ(SysTick_IRQn);
NVIC_InitStruture.NVIC_IRQChannel=TIM3_IRQn;
NVIC_InitStruture.NVIC_IRQChannelPreemptionPriority=2;//抢占优先级
NVIC_InitStruture.NVIC_IRQChannelSubPriority=1;//响应优先级
NVIC_InitStruture.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStruture);
}
|