|
上下位机之间的485通讯早就调通,是公司以前做的。
我的硬件就是stm32f的单片机的两路485串口(另加了些抗干扰措施),应该没问题吧。
我的软件用的是KEIL MDK 3.5,主要的代码如下:
USART_InitStructure.USART_BaudRate = 2400;
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
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;
void USARTy_IRQHandler(void)
{
if(USART_GetITStatus(USARTy, USART_IT_RXNE) != RESET)
{
if(RxCounter1<9)
{
/* Read one byte from the receive data register */
RxBuffer1[RxCounter1] = USART_ReceiveData(USARTy);
USART_SendData(USARTz,RxBuffer1[RxCounter1]);
RxCounter1++;
}
else
{
RxCounter1=0;
USART_ReceiveData(USARTy);
}
}
}
void USARTz_IRQHandler(void)
{
if(USART_GetITStatus(USARTz, USART_IT_RXNE) != RESET)
{
if(RxCounter2<9)
{
RxBuffer2[RxCounter2] = USART_ReceiveData(USARTz);
USART_SendData(USARTy,RxBuffer2[RxCounter2]);
RxCounter2++;
}
else
{
RxCounter2=0;
USART_ReceiveData(USARTz);
}
}
}
|
|