|
板凳
楼主 |
发表于 2022-3-14 14:11:02
|
只看该作者
我单片机和串口传输助手是可以的可uwb和单片机还是不行 要不您看看程序大佬
void uart_init(u32 bound)
{
//0. ????????
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//1. ???gpio????
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
//2. gpio??????
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);
//3. GPIO???
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;//LED0?LED1??IO?
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//AF??
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//????
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//??
GPIO_Init(GPIOA, &GPIO_InitStructure);//???GPIO
//4. USART???
USART_InitStructure.USART_BaudRate=115200;
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
USART_InitStructure.USART_Parity=USART_Parity_No;
USART_InitStructure.USART_StopBits=USART_StopBits_1;
USART_InitStructure.USART_WordLength=USART_WordLength_8b;
USART_Init(USART1,&USART_InitStructure);
//5.????
USART_Cmd(USART1,ENABLE);
//???????
//6.??1?????????
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //?? ??1????????? ??
//7.?????
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_Init(&NVIC_InitStructure);
}
u8 Res;
void USART1_IRQHandler(void) //′®¿ú1ÖD¶Ï·tÎñ3ìDò
{
#if SYSTEM_SUPPORT_OS //èç1ûSYSTEM_SUPPORT_OSÎaÕ棬ÔòDèòaÖ§3ÖOS.
OSIntEnter();
#endif
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //½óêÕÖD¶Ï(½óêÕμ½μÄêy¾Y±ØDëêÇ0x0d 0x0a½áÎ2)
{
Res =USART_ReceiveData(USART1);//(USART1->DR); //¶á衽óêÕμ½μÄêy¾Y
if((USART_RX_STA&0x8000)==0)//½óêÕÎ′íê3é
{
if(USART_RX_STA&0x4000)//½óêÕμ½áË0x0d
{
if(Res!=0x0a)USART_RX_STA=0;//½óêÕ′íÎó,ÖØD¿aê¼
else USART_RX_STA|=0x8000; //½óêÕíê3éáË
}
else //»1ûêÕμ½0X0D
{
if(Res==0x0d)USART_RX_STA|=0x4000;
else
{
USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ;
USART_RX_STA++;
if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//½óêÕêy¾Y′íÎó,ÖØD¿aê¼½óêÕ
}
}
}
} |
|