|
发表于 2011-12-22 21:35:52
|
显示全部楼层
发送字符串时,没有必要每个字符都控制DE/RE。
void Uart1_Send_Char(u8 ch)
{
USART1->DR = ch;
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
{
}
}
void Uart1_Send_String(u8 *str)
{
RS485=1;
delay_us(10);
while(*str != '\0')
{
Uart1_Send_Char(*str);
++str;
}
delay_us(10);
RS485=0;
}
要发送单个字符,用下面的函数:
void Uart1_Send_SingleChar(u8 ch)
{
RS485=1;
delay_us(10);
USART1->DR = ch;
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
{
}
delay_us(10);
RS485=0;
}
编辑原因:
补充
利用发送完成中断作为切换DE/RE的依据也一样会有丢字符的问题,延时才是最简单有效的办法 |
|