新手上路
- 积分
- 47
- 金钱
- 47
- 注册时间
- 2019-9-5
- 在线时间
- 11 小时
|
void uart5_init(uint32_t bound)
{
//GPIO3õê¼»ˉ
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5,ENABLE);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource12,GPIO_AF_UART5);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource2,GPIO_AF_UART5);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC,&GPIO_InitStructure); //PC12
//UART5????
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //GPIOD2
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD,&GPIO_InitStructure);
//UART5 ?????
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(UART5, &USART_InitStructure);
USART_Cmd(UART5, ENABLE);
// USART_ClearFlag(UART5, USART_FLAG_TC);
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
// USART_ITConfig(UART5, USART_IT_IDLE, ENABLE);
//Usart5 NVIC ??
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void UART5_IRQHandler(void) //′®¿ú6ÖD¶Ïoˉêy
{
u8 Res;
if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
{
Res =USART_ReceiveData(USART2);//(USART1->DR); //¶á衽óêÕμ½μÄêy¾Y
if((UART5_RX_STA&0x8000)==0)//½óêüíê3é
{
if(UART5_RX_STA&0x4000)//½óêÕμ½0x0d
{
if(Res!=0x0a)UART5_RX_STA=0;//½óêü′íÎóÖØD¿aê¼
else UART5_RX_STA|=0x8000; //½óêüíê3éáË
}
else //????0X0D
{
if(Res==0x0d)UART5_RX_STA|=0x4000;
else
{
UART5_RX_BUF[UART5_RX_STA&0X3FFF]=Res ;
UART5_RX_STA++;
if(UART5_RX_STA>(UART5_REC_LEN-1))UART5_RX_STA=0;//½óêü′íÎóÖØD¿aê¼½óêü
}
}
}
}
}
|
|