初级会员

- 积分
- 83
- 金钱
- 83
- 注册时间
- 2014-8-9
- 在线时间
- 15 小时
|
5金钱
void uart5_init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure; //?¨????????GPIO???á????
// USART_InitTypeDef UART5_InitStructure; //?¨????????USART???á????
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/*????USART5?±??*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOC,ENABLE);
USART_DeInit(UART5); //?????®??5
/*USART5????????*/
/*USART5 Tx(PC12) ???©???ì*/
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
/*USART5 Rx(PD2) ???·????*/
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD,&GPIO_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//??????????3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //×???????3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨??????
NVIC_Init(&NVIC_InitStructure); //?ù?????¨????????????VIC?????÷
/*USART5 ????????*/
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(UART5, &USART_InitStructure); //???????®??
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE); //????????
/*????UART5*/
USART_Cmd(UART5,ENABLE);
}
void UART5_SEND_DATA ( u8 len)
{
u8 i;
for(i=0;i<len;i++)
{
while (USART_GetFlagStatus(UART5,USART_FLAG_TC)!=SET);
USART_SendData(UART5,USART5_TX_BUF);
}
}
void UART5_IRQHandler(void)
{
// u8 ii;
LED1=0;
if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
{
USART5_RX_BUF[UART5_RX_STA]=USART_ReceiveData(UART5);
UART5_RX_STA++;
}
if(UART5_RX_STA>=10)
{UART5_RX_OK=1;UART5_RX_STA=0;}
USART_ClearITPendingBit(UART5,USART_IT_RXNE); //????????±ê??
}
|
|