请各位指教,在配置完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); } |
【MCU实战经验】基于STM32F103C8T6的hart总线调试器设计
求教STM32F103进入STOP模式后用外部中断唤醒的问题
基于STM32F103RCT6的无源蜂鸣器音乐播放(生日快乐歌)
STM32F103c8t6有没有DAC 功能?
STM32F103x中文数据手册
新手求教,为何在我电脑上找不到STM32F1Xx.h文件
金龙107例程汇总(STM32F107)
万利STM32F107VC 原理图
STM32F103 ADC多通道检测必须要DMA吗?
【官方例程】STM32F107以太网官方例程
目前我把SPI 跟中断合在一起配置,结果还是触发不了
void SPI1_CONFIG(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_SPI1|RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO,ENABLE);
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);
//config the sck ,MOSI pin
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//config the ,MISO
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;
//GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//config ce cspin,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);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;//GPIO_Mode_IN_FLOATING;//GPIO_Mode_IPU;//IP IPD IPU
GPIO_Init(GPIOB, &GPIO_InitStructure);
///RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//
EXTI_ClearITPendingBit(EXTI_Line12);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource12);
EXTI_InitStructure.EXTI_Line=EXTI_Line12;//
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);
//RCC_MCOConfig(RCC_MCO_HSE);
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;//PCLK/8
SPI_InitStructure.SPI_FirstBit=SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial=7;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);
}
void Exit_Ini(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure PB9 as input floating (EXTI Line9) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Connect EXTI Line9 to PB.09 */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource2);
/* Configure EXTI Line9 to generate an interrupt on falling edge */
EXTI_InitStructure.EXTI_Line = EXTI_Line2;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configure the nested vectored interrupt controller.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Con(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the EXTI15_10 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
哈哈
这个无所谓呀 其实是我的板子定义的是PB0,因为没办法触发 才一直在换其他的IO去试的。。
。这样试试看
这句写的是把CS pin 拉high,CS pin 定义的是PA3,CE pin 定义的PA4
谢谢版主 如此帮忙
Quadrotor FOR EXTI BUG.rar
2015-5-15 16:37 上传
点击文件名下载附件
下载积分: ST金币 -15.51 MB, 下载次数: 6, 下载积分: ST金币 -1
è¿æ¯æçå·¥ç¨
嗯嗯 这个也试过了。。
因为我手里只有一块板子,所以没办法对比。。。麻烦你了
没有没有 是我不好意思。。。呵呵
快点帮我试试吧,