新手入门
- 积分
- 11
- 金钱
- 11
- 注册时间
- 2021-3-25
- 在线时间
- 2 小时
|
1金钱
想用USART2接收openmv发送的数据然后在LCD屏上显示,openmv端能正常发送,可是这边LCD屏上啥都没显示有,麻烦大佬们帮我看看哪里出了问题
void usart2_init(u32 bound){
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_USART3);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
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_Tx|USART_Mode_Rx;
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);
//USART_ClearFlag(USART1, USART_FLAG_TC);
#if EN_USART2_RX
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#endif
}
static u8 Cx=0,Cy=0,Cw=0,Ch=0;
void USART2_IRQHandler(void)
{
u8 com_data;
u8 i;
static u8 RxCounter1=0;
static u16 RxBuffer1[10]={0};
static u8 RxState = 0;
static u8 RxFlag1 = 0;
if( USART_GetITStatus(USART2,USART_IT_RXNE)!=RESET)
{
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
com_data = USART_ReceiveData(USART2);
if(RxState==0&&com_data==0x2C)
{
RxState=1;
RxBuffer1[RxCounter1++]=com_data;
}
else if(RxState==1&&com_data==0x12)
{
RxState=2;
RxBuffer1[RxCounter1++]=com_data;
}
else if(RxState==2)
{
RxBuffer1[RxCounter1++]=com_data;
if(RxCounter1>=10||com_data == 0x5B)
{
RxState=3;
RxFlag1=1;
Cx=RxBuffer1[RxCounter1-5];
Cy=RxBuffer1[RxCounter1-4];
Cw=RxBuffer1[RxCounter1-3];
Ch=RxBuffer1[RxCounter1-2];
}
}
else if(RxState==3)
{
if(RxBuffer1[RxCounter1-1] == 0x5B)
{
USART_ITConfig(USART2,USART_IT_RXNE,DISABLE);
if(RxFlag1)
{
LCD_ShowxNum(30, 40,Cx,8,24,1);
LCD_ShowxNum(30, 60,Cy,8,24,1);
LCD_ShowxNum(30, 80,Cw,8,24,1);
LCD_ShowxNum(30, 100,Ch,8,24,1);
}
RxFlag1 = 0;
RxCounter1 = 0;
RxState = 0;
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
}
else
{
RxState = 0;
RxCounter1=0;
for(i=0;i<10;i++)
{
RxBuffer1=0x00;
}
}
}
else
{
RxState = 0;
RxCounter1=0;
for(i=0;i<10;i++)
{
RxBuffer1=0x00;
}
}
}
}
|
|