From ae25bf68c24ee68f0354be23d3b1aec27d352b92 Mon Sep 17 00:00:00 2001 From: armink Date: Sat, 28 Dec 2013 09:45:05 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91F?= =?UTF-8?q?reeModbus=E4=B8=AD=E5=85=B3=E4=BA=8ESTM32=E4=B8=B2=E5=8F=A3?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E4=B8=AD=E6=96=AD=E9=83=A8=E5=88=86=E7=9A=84?= =?UTF-8?q?=E6=BA=90=E7=A0=81=EF=BC=8C=E4=BF=9D=E8=AF=81=E5=9C=A8485?= =?UTF-8?q?=E9=80=9A=E4=BF=A1=E7=8E=AF=E5=A2=83=E4=B8=8B=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: armink --- FreeModbus/port/port.c | 12 +++++++++--- FreeModbus/port/port.h | 9 +++++---- FreeModbus/port/portserial.c | 4 ++++ FreeModbus/port/portserial_m.c | 4 ++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/FreeModbus/port/port.c b/FreeModbus/port/port.c index 459481c..7f58ba8 100644 --- a/FreeModbus/port/port.c +++ b/FreeModbus/port/port.c @@ -1,6 +1,6 @@ /* - * FreeModbus Libary: LPC214X Port - * Copyright (C) 2007 Tiago Prado Lone + * FreeModbus Libary: STM32 Port + * Copyright (C) 2013 Armink * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -16,7 +16,7 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - * File: $Id: port.c,v 1.1 2007/04/24 23:15:18 wolti Exp $ + * File: $Id: portevent.c,v 1.60 2013/12/28 9:18:05 Armink $ */ /* ----------------------- System includes --------------------------------*/ @@ -37,3 +37,9 @@ void ExitCriticalSection(void) //开启全局中断 __enable_irq(); } + +void vMBDelay(ULONG nCount) +{ + for(; nCount > 0;nCount--); +} + diff --git a/FreeModbus/port/port.h b/FreeModbus/port/port.h index c79df3d..87a776f 100644 --- a/FreeModbus/port/port.h +++ b/FreeModbus/port/port.h @@ -1,6 +1,6 @@ /* * FreeModbus Libary: BARE Port - * Copyright (C) 2006 Christian Walter + * Copyright (C) 2013 Armink * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -43,9 +43,6 @@ #define ENTER_CRITICAL_SECTION() EnterCriticalSection() #define EXIT_CRITICAL_SECTION() ExitCriticalSection() -void EnterCriticalSection(void); -void ExitCriticalSection(void); - typedef uint8_t BOOL; typedef unsigned char UCHAR; @@ -65,4 +62,8 @@ typedef int32_t LONG; #define FALSE 0 #endif +void EnterCriticalSection(void); +void ExitCriticalSection(void); +void vMBDelay(ULONG nCount); + #endif diff --git a/FreeModbus/port/portserial.c b/FreeModbus/port/portserial.c index 3768702..62bf50a 100644 --- a/FreeModbus/port/portserial.c +++ b/FreeModbus/port/portserial.c @@ -33,6 +33,10 @@ void vMBPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable) { if (xRxEnable) { + /* 485通信时,等待串口移位寄存器中的数据发送完成后,再去使能485的接收、失能485的发送 + * 该延时时间可以结合CPU主频及串口波特率做适当调整 + * */ + vMBDelay(1000); SLAVE_RS485_RECEIVE_MODE; USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); } diff --git a/FreeModbus/port/portserial_m.c b/FreeModbus/port/portserial_m.c index 3a9f660..461228a 100644 --- a/FreeModbus/port/portserial_m.c +++ b/FreeModbus/port/portserial_m.c @@ -35,6 +35,10 @@ void vMBMasterPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable) { if (xRxEnable) { + /* 485通信时,等待串口移位寄存器中的数据发送完成后,再去使能485的接收、失能485的发送 + * 该延时时间可以结合CPU主频及串口波特率做适当调整 + * */ + vMBDelay(1000); MASTER_RS485_RECEIVE_MODE; USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); }