目前通信不了。这个程序是在原子哥485实验上改的
我使用串口一来查看两边发送的数据结果观察到:01 03 00 10 00 01 85 CF 03 02 00 00 B8 44
01 03 00 10 00 01 85 CF 03 02 00 00 B8 44
01 03 00 10 00 01 85 CF 03 02 00 00 B8 44
01 03 00 10 00 01 85 CF 03 02 00 00 B8 44
01 03 00 10 00 01 85 CF
01 03 02 00 00 B8 44
01 03 00 10 00 01 85 CF 01 03 02 00 00 B8 44
01 03 00 10 00 01 85 CF 03 02 00 00 B8 44
01 03 00 10 00 01 85 CF 01 03 02 00 00 B8 44
01 03 00 10 00 01 85 CF 01 03 02 00 00 B8 44
这种情况,从01-CF是屏发送的,后面是板子返回的,应该是01开始,但是为什么有时候没有
部分程序如下:串口中断:
void USART2_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(USART2,USART_IT_RXNE)!=RESET)
{
res =USART_ReceiveData(USART2);
USART_SendData(USART1,res);//用来看接收到的数据
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
if(Uart1_rev_flag != 1)
{
if(recenum < 12)
{
ReceBuf[recenum] = res;
// USART_SendData(USART1,ReceBuf[recenum]);
recenum++;
usDataLen = recenum - 2;
TIM_SetCounter(TIM3, 0);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM3, ENABLE);
}
else
{
recenum=0;
TIM_ClearFlag(TIM3, TIM_FLAG_Update);
TIM_SetCounter(TIM3, 0);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM3, ENABLE);
}
}
else
{
USART_ReceiveData(USART2);
}
}
if(USART_GetFlagStatus(USART2,USART_FLAG_ORE)!=RESET)
{
USART_ClearFlag(USART2,USART_FLAG_ORE);
USART_ReceiveData(USART2);
}
}
定时器中断:
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
//USART_SendData(USART1, 'a');
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
TIM_ClearFlag(TIM3, TIM_FLAG_Update);
TIM_Cmd(TIM3, DISABLE);
if(recenum >= 8)
{
recenum = 0;
Uart1_rev_flag = 1;
// USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
//GPIO_SetBits(GPIOB,GPIO_Pin_5);
// USART_SendData(USART1, 'f');
}
else
{
recenum = 0;
// USART_SendData(USART1, 'd');
}
}
}
处理后板子返回的数据就是简单的while的循环发送(包括给串口二即屏,同事也给串口一用于观察),处理函数较长就不写了
while(i<sendnum)
{
USART_SendData(USART1,SendBuf);
USART_SendData(USART2,SendBuf);
i++;
while(!(USART2->SR & USART_FLAG_TXE));
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>