我用STM32的串口3去接收GPS的数据,并用串口1将数据发到串口助手上。这部分现在可以实现,但是一旦加上LCD的驱动程序后,串口部分就无法接收到程序了。
下面是我的一些程序:
int main(void)
{
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(9600);
USART3_Init(9600);
LED_Init();
LCD_Init();
POINT_COLOR=RED;
LCD_ShowString(70,0,200,200,16,"GPS Navigation");
while(1)
{
if(point1==1)
{
printf("%s",USART3_RX_BUF);
// while((USART1->SR&0X40)==0);
point1=0;
}
}
}
这是串口3的程序:
u16 USART3_RX_STA;
u8 USART3_RX_BUF[USART3_MAX_RECV_LEN];
int point1;
void USART3_Init(u32 bound)
{
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // GPIOA??
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
// USART_DeInit(USART3); //¸′λ′®¿ú2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PA.9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸′óÃíÆíìêä3ö
GPIO_Init(GPIOB, &GPIO_InitStructure);//3õê¼»ˉGPIOA.9
//USART1_RX GPIOA.103õê¼»ˉ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//PA10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//¸¡¿Õêäèë
GPIO_Init(GPIOB, &GPIO_InitStructure);//3õê¼»ˉGPIOA.10
//Usart1 NVIC ÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//ÇàÕ¼óÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //×óóÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μàê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YÖ¸¶¨μÄ2Îêy3õê¼»ˉVIC¼Ä′æÆ÷
//USART 3õê¼»ˉéèÖÃ
USART_InitStructure.USART_BaudRate = bound;
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_Init(USART3, &USART_InitStructure);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_Cmd(USART3, ENABLE);
}
void USART3_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
res =USART_ReceiveData(USART3);
if((USART3_RX_STA== 0) && (res == '$') || (USART3_RX_STA != 0))
{
USART3_RX_BUF[USART3_RX_STA]= res;
USART3_RX_STA++;
if(USART3_RX_STA== USART3_MAX_RECV_LEN) USART3_RX_STA = 0;
if((USART3_RX_BUF[USART3_RX_STA-1]== '
')&&(USART3_RX_BUF[USART3_RX_STA-2] == '
'))
{
USART3_RX_BUF[USART3_RX_STA]= 0;
USART3_RX_STA= 0;
point1=1;
}
}
}
}
希望能得到各位的帮忙。。。。。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
我也用原子的程序该过,就保留了LCD驱动和串口收发,结果还是一样。。。。
应该是你改的程序有问题。你要用仿真器找找原因了
一周热门 更多>