最近弄了个串口屏,使用串口发送数据显示,用的usart3,但一直不能发送数据,程序卡在 while(USART_GetFlagStatus(USART3, USART_FLAG_TC) != SET); ,连第一个字符也没发送出去。相关配置如下
//USART3中断配置
void NVIC_USART3_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //主优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //从优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//usart3配置
void USART3_config (void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//设置USART初始化结构体
USART_InitTypeDef USART_InitStructure;
//时钟使能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
//usart3:tx配置tx->pb_pin10;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//usart3:rx配置rx->pb_pin11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//usart3初始化
USART_InitStructure.USART_BaudRate = 115200;
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_Tx | USART_Mode_Rx;
USART_Init(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
//配置NVIC
NVIC_USART3_Configuration();
//USART_ClearFlag(USART3,USART_FLAG_TC);
//使能串口接收中断
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
//开启usart
USART_Cmd(USART3, ENABLE);
}
//串口屏指令发送
void GpuSend(char * buf1)
{ char i=0;
while (1)
{ if (buf1[i]!=0)
{
//USART1->SR;
USART_ClearFlag(USART3,USART_FLAG_TC);
USART_SendData(USART3, buf1[i]);
while(USART_GetFlagStatus(USART3, USART_FLAG_TC) != SET);
i++;
}
else return;
}
}
用iar仿真,程序一直在 while(USART_GetFlagStatus(USART3, USART_FLAG_TC) != SET);循环,是配置上有什么问题吗?
|