微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32串口通信测试程序

STM32串口通信测试程序

时间:11-28 来源:互联网 点击:

if( Time20msCnt>

USART_Cmd(USART2, ENABLE);

USART_Cmd(USART3, ENABLE);

USART_Cmd(UART4, ENABLE);

//-----如下语句解决第1个字节无法正确发送出去的问题-----//

USART_ClearFlag(USART1, USART_FLAG_TC);// 清标志

USART_ClearFlag(USART2, USART_FLAG_TC);

USART_ClearFlag(USART3, USART_FLAG_TC);

USART_ClearFlag(UART4 , USART_FLAG_TC);

}

//**********串口中断函数********************

void UART5_IRQHandler(void)

{

uchar x,y,z;

uint checksum1,checksum2;

if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET) //若接收数据寄存器满

{

x=USART_ReceiveData(UART5);

}

Com5TxChar(x);

}

//------------------------------------------------

void USART1_IRQHandler(void)

{

if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //若接收数据寄存器满

{

Com1RecDat[Com1RecCnt]=USART_ReceiveData(USART1);

}

Com1RecCnt++;

Com1RecCnt%=C1_LEN;

Com1TxChar(USART_ReceiveData(USART1));

}

//----------------------------------------------

void USART2_IRQHandler(void)

{

if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //若接收数据寄存器满

{

Com2RecDat[Com2RecCnt]=USART_ReceiveData(USART2);

}

Com2RecCnt++;

Com2RecCnt%=C1_LEN;

Com2TxChar(USART_ReceiveData(USART2));

}

//-------------------------------------------------

void USART3_IRQHandler(void)

{

if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //若接收数据寄存器满

{

Com3RecDat[Com3RecCnt]=USART_ReceiveData(USART3);

}

Com3RecCnt++;

Com3RecCnt%=C1_LEN;

Com3TxChar(USART_ReceiveData(USART3));

}

//----------------------------------------------------

void UART4_IRQHandler(void)

{

if(USART_GetITStatus(UART4, USART_IT_RXNE) != RESET) //若接收数据寄存器满

{

Com4RecDat[Com4RecCnt]=USART_ReceiveData(UART4);

}

Com4RecCnt++;

Com4RecCnt%=C1_LEN;

Com4TxChar(USART_ReceiveData(UART4));

}

//*****************主函数************************

int main(void)

{

u8 ld[69]=0;

u8 i;

RCC_Configuration();

GPIO_Configuration();

NVIC_Configuration();

UART5_Configuration();

USART_Configuration();

TIM2_Configuration();

SysTick_Configuration();

for(i=0;i<69;i++)

{

ld[i]=i;

}

Com1TxStr(ld,69);

Com2TxStr(ld,69);

Com3TxStr(ld,69);

Com4TxStr(ld,69);

Com5TxStr(ld,69);

while(1)

{

}

}

//-------------------------------------------------------------

http://long0329998.blog.163.com/blog/static/58823187201252611116247/

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top