|
void CpuIoInit(void)
{
///////(PA8)用于MCO输出/////
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOA,&GPIO_InitStructure);
///////(PA12)用于对DSP的复位控制输出/////
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;//
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; //开漏输出
GPIO_Init(GPIOA,&GPIO_InitStructure);
///########################### 配置GPIOB ################################################################
//////(PB8)用于前面报警灯控制输出//////
GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_8);//
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //开漏输出
GPIO_Init(GPIOB,&GPIO_InitStructure);
//////(PC12)用于CPU读取DSP中断线的状态//////
GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_12);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //输入浮空
GPIO_Init(GPIOC,&GPIO_InitStructure);
/////////////////////////////////////////////////////////
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); // Set the Vector Table base location at 0x20000000
#else // VECT_TAB_FLASH
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); // Set the Vector Table base location at 0x08000000
#endif
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); //设置为16级抢占式优先级
////////////////////////////////
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel; //PC12
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //EX0,最高优先级(与DSP的通讯)
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void CpuExitInterrupetInit(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
// NVIC_StructInit(EXTI_InitStructure); //把NVIC_InitStruct中的每一个参数按缺省值填入
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource12); //dsp
EXTI_InitStructure.EXTI_Line = DSP_EXTI_INTERRUPT;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //外部下降沿中断
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
///////外中断NVIC设置/////
}
void sysInit(void)
{
delay(3000);
sysClockInit(); //必须放在外设初始化的前面,因为APB1,APB2,AFIO时钟的原因
RCC_MCOConfig(RCC_MCO_HSE); //MCO输出时钟,给外面的DSP用。
NVIC_Configuration(); //中断初始化
CpuIoInit(); //IO口初始化
//DSP_RST_CLR; //复位DSP接低
//RS485RXD_ON;
//DisplayInit(); //
//Uart1Init(); //程序调试时用
// Uart2Init(); //
//Uart3Init(); //KFT接收外部的控制。
//E24c02Init(); //
//TIM2Init(); //用TIM2作为系统时钟
CpuExitInterrupetInit(); //CPU外中断初始化
////////////////////////
}
void main(void)
{
sysInit();
while(1)
{
LED_OFF; //
}
}
//////////////中断处理////////////////////////
#define DSP_EXTI12_PIN (GPIOC->IDR & 0x1000) //DSP外中断管脚为PC12
void EXTI15_10_IRQHandler(void)
{
LED_ON;
//////////////////////////////////////////
while(DSP_EXTI12_PIN==0){NOP;}//1
while(DSP_EXTI12_PIN){NOP;} //2
while(DSP_EXTI12_PIN==0){NOP;}//3
while(DSP_EXTI12_PIN){NOP;} //4
while(DSP_EXTI12_PIN==0){NOP;}//5
//////////////////////////////////////////////
EXTI->PR = EXTI_Line12; //退出时必须清中断
} |
|