这个是程序:void INit()
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO,ENABLE); //因为A口为复用时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);
///////////////////////////////////////////////////////////////////////
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3|GPIO_Pin_4; //CE 引脚控制模式选择,因为要用来控制它的
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; //它的电平,所以选择输出方式((》》》))
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //
GPIO_Init(GPIOA,&GPIO_InitStructure); //
Set_NRF2401_CE; ///必须先拉高,因为不工作时为H
Set_nss; //先拉高,不让工作
//////////////////////////////////////////////////////////////////////
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4|GPIO_Pin_6|GPIO_Pin_7; //用一个使能,先拉高 ((b)),把所有的片选都配置上了
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//因为用它来控制外面的,所以选择输出,上下拉随意
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//
GPIO_Init(GPIOB,&GPIO_InitStructure);
Set_NRF2401_CS; //
//GPIO_SetBits(GPIOB,GPIO_Pin_6); //
//GPIO_SetBits(GPIOB,GPIO_Pin_7); //
////////////////////////////////////////////////////////////////////
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2; //IRQ 中断引脚
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;////上拉输入
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //初始化时先拉高,因为触发时为L
//////////////////////////////////////////////////////////////////////
////////////////////设置俩处,1:GPIO 2:SPI那里的/////////////////////
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; //复用推挽输出 ,只有这样才可以区别不是普通IO口
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_SetBits(GPIOA,GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7);
//////////////////////////////////////////////////
////////////////////////////////////////////////////////usart
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;//选择口
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOD,&GPIO_InitStructure);
//////////////////////////////////////////////////////
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;//选择口
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init(GPIOD,&GPIO_InitStructure);
//////////////////////////////////////////////////
////////////////////////////////////////////////////////usart
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;//选择口
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
//////////////////////////////////////////////////////
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;//选择口
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init(GPIOA,&GPIO_InitStructure);
//////////////////////////////////////////////////
/*GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure); */
}
void USART2_init() //串口初始化
{
USART_InitTypeDef USART_InitStructure; //
NVIC_InitTypeDef NVIC_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure; //
USART_InitStructure.USART_BaudRate=9600; //
USART_InitStructure.USART_WordLength=USART_WordLength_8b; //
USART_InitStructure.USART_StopBits=USART_StopBits_1; //
USART_InitStructure.USART_Parity=USART_Parity_No;//
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None; //
USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx; //
USART_ClockInitStructure.USART_Clock=USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL=USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA=USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit=USART_LastBit_Disable;
USART_Init(USART2,&USART_InitStructure);
USART_ClockInit(USART2,&USART_ClockInitStructure);
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
USART_Cmd(USART2,ENABLE);
////////////////////////////////
NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//////中断函数////////////////
void interrupt()
{
if((USART_GetITStatus(USART2,USART_IT_RXNE)!=RESET))
{
table0[i++]=USART_ReceiveData(USART2);
if(table0[0]=='$')
{
flag=1;
if(i>=70)
i=0;
}
else i=0;
}
}
void GPS_GetDATA()
{
u8 i,j,k=0 ;
if(flag==1)
{
flag=0;
if(table0[4]=='G')
{
for(j=0;i<70;j++)
{
printf("\r\n table2==%c\r\n",table0);
}
if (table0[j]==',')
{
k++;
if(k==0)
{
for(i=0;i<10;i++)
{
table2=table0[j+i]; //时间
printf("\r\n table2==%c\r\n",table2);
}
}
if(k==1)
{
for(i=0;i<10;i++)
{
table3=table0[j+i];//纬度
}
}
if(k==2)
{
for(i=0;i<10;i++)
{
table4=table0[j+i];//经度
}
}
if(k==8)
{
for(i=0;i<10;i++)
{
table5=table0[j+i]; //高度
}
}
}
}
}
}
这个是总的代码,
现象是这样的:由于中断进不了,所以flag 不能被置位,可是不知哪的错,原子哥给看看 |