CN104052579A - Automatic MODBUS-RTU communication baud rate matching method - Google Patents

Automatic MODBUS-RTU communication baud rate matching method Download PDF

Info

Publication number
CN104052579A
CN104052579A CN201410289938.XA CN201410289938A CN104052579A CN 104052579 A CN104052579 A CN 104052579A CN 201410289938 A CN201410289938 A CN 201410289938A CN 104052579 A CN104052579 A CN 104052579A
Authority
CN
China
Prior art keywords
baud rate
message
communication
bus
slave station
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201410289938.XA
Other languages
Chinese (zh)
Inventor
周晓峰
邓君
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hunan Super Information Co Ltd
Original Assignee
Hunan Super Information Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hunan Super Information Co Ltd filed Critical Hunan Super Information Co Ltd
Priority to CN201410289938.XA priority Critical patent/CN104052579A/en
Publication of CN104052579A publication Critical patent/CN104052579A/en
Pending legal-status Critical Current

Links

Landscapes

  • Communication Control (AREA)

Abstract

The invention discloses an automatic MODBUS-RTU communication baud rate matching method. The method is achieved through the steps of firstly, setting the baud rate of a serial port as the default baud rate when a slave station is powered on, waiting for receiving a serial port message on a bus, resetting the baud rate of the serial port as the agreed next baud rate of a master station and the slave station if the messages unceasingly received five times are wrong messages till a correct serial port message is received, and achieving communication with the master station with the baud rate; secondly, changing the baud rate of the master station under the normal communication condition, detecting whether the received message on the bus is correct or not in real time through the slave station, repeatedly executing the baud rate matching process if the wrong messages are unceasingly received five times till the correct message is received, judging the data format based on a MODBUS communication protocol according to whether the message received by the slave station is correct or not, and conducting verification, wherein a CRC verification code and the length of the whole message are mainly verified. By means of the method, the baud rate of the master station and the baud rate of the slave station can be automatically matched without changing bus communication or all devices arranged on the bus.

Description

MODBUS-RTU communication baud rate Auto-matching
Technical field
The present invention relates to field of industrial automatic control, particularly MODBUS-RTU communication baud rate Auto-matching.
Background technology
MODBUS-RTU agreement is disclosed, a to be widely used serial communication protocol, formulated for its Programmable Logic Controller and industrial automation system by Modicon company at first, while being widely used in the I/O of transmission of digital and simulation between control appliance and register data, use, this protocol definition controller can be familiar with the message structure using, and no matter they through which kind of network communicate.It has described the process of a controller request access miscellaneous equipment, how to respond the request from miscellaneous equipment, and how to detect wrong and record.It has formulated the common format of message field general layout and content, in RS-485 bus, and most of master-slave communication mode that adopts, a main frame, connects many slave stations.Main frame and slave station communication mainly rely on slave station to identify for No. ID, make main website and corresponding slave station carry out exchanges data.And the prerequisite of main website and slave station communication is, main website wants consistent with the baud rate of slave station communication, existing technology mainly adopts toggle switch that the baud rate of every slave station is set or the baud rate of slave station is set by software, the baud that needs only main website is in use changed, will will every baud rate be set to equipment on communication bus by toggle switch or software, use very inconvenient, after whole system is moved, communication is unstable especially, need to change the baud rate of bus time, the use of the long serious system that affects of needed time.
RS-485 bus communication, the devices communicating baud rate being connected on same bus must be consistent, the Configuration of baud rate of establishing of existing RS-485 communication is all to develop by dial-up, software or other mode separate units arrange, the baud rate that need to change bus communication must arrange every equipment in bus, in a bus, may there be tens equipment, every equipment arrives hundreds of rice at a distance of tens meters, likely go up km, if it is unstable that whole system is communicated by letter after moving, when need to reducing communication baud rate and strengthen the stability of communication, just need to stop whole bus apparatus operation, develop by dial-up, software or the artificial separate unit of other modes arrange, after setting up, rerun the equipment in whole bus, this process need dozens of minutes was by several hours, 1, increase the cost of labor of safeguarding of whole system, 2, stopping whole bus apparatus operation dozens of minutes can have serious consequences to whole system by several hours.
Summary of the invention
The object of the invention is the shortcoming and defect in order to overcome prior art, providing a kind of does not need to change bus communication and every equipment in bus is set, and realizes the MODBUS-RTU communication baud rate Auto-matching of the Auto-matching of master-salve station baud rate.
The present invention is achieved by the following technical programs:
The implementation procedure of MODBUS-RTU communication baud rate Auto-matching is as follows:
The baud rate that serial ports is set when 1, slave station powers on is the baud rate of acquiescence, wait for the serial ports message receiving in bus, if the continuous message receiving for 5 times is error message, just to reset serial ports baud rate be the next baud rate that master-salve station is better, until while correctly receiving serial ports message, just with this baud rate and master station communication;
2, the in the situation that of proper communication, main website has changed baud rate, and whether the message the standing-meeting bus that detection receives in real time is correct, if continuous 5 times receive error message, repeats baud rate matching process, until receive correct message.Whether correctly the message that slave station the receives data format of basis for estimation MODBUS communication protocol carries out verification, main check (CRC) check code, whole message length.
The invention has the beneficial effects as follows, master-salve station has been arranged several baud rates (9600,19000,38400,57600,93750,1115200,187500,250000,300000,500000,1000000,2000000,2500000bit/s), can change as required, main website can change the communication baud rate in whole bus according to a preconcerted arrangement, when main website changes baud rate, slave station automatically mates with main website baud rate, correctly communicates by letter thereby realize principal and subordinate.
Brief description of the drawings
Fig. 1 is slave station and main website baud rate Auto-matching schematic flow sheet.
Embodiment
Below in conjunction with the drawings and specific embodiments, the invention will be further described.
Slave station as shown in Figure 1 and main website baud rate Auto-matching, following code, based on STM32F103 chip, has called the storehouse of STM32F103, specifically describes as follows:
/*
Slave station communication baud rate combination definition
*/
#define UART_RXBUF_DMA_LEN 300
const unsigned int ASC_Baudrate_Const[15]=
{
9600,19000,38400,57600,93750,1115200,187500,250000,300000,500000,1000000,2000000,
2500000
};
Unsigned char ASCRevBuf[300];
Unsigned char BaudrateInde=0;
Unsggned char ASCRevErroNum=0;
uint32_t AscDMA_Ptr=0;
/*
Serial ports reception & disposal (using serial communication dma mode)
*/
void OnASC2_Event(void)
{
uint16_t i = 0;
uint32_t TempCount,CurrentPos;
Unsigned char ASCRevErroSign=0;
if(USART_GetITStatus(USART2, USART_IT_IDLE) != RESET)
{
TempCount = USART2->SR;
TempCount=USART2->DR; // removing serial ports receive interruption mark
/*
Calculate the length that receives message
*/
CurrentPos=UART_RXBUF_DMA_LEN - DMA_GetCurrDataCounter(DMA1_Channel6);
if(CurrentPos>AscDMA_Ptr)
{
TempCount=CurrentPos-AscDMA_Ptr;
}
else
{
TempCount=CurrentPos+(UART_RXBUF_DMA_LEN-AscDMA_Ptr);
}
/*
The serial ports message COPY receiving is arrived to reception buffer zone
*/
If(TempCount<300)
{
for(i=0;i<TempCount;i++)
{
ASCRevBuf [i]=Uart1_RxBuf_DMA[AscDMA_Ptr];
AscDMA_Ptr++;
if(AscDMA_Ptr>=UART_RXBUF_DMA_LEN)
{
AscDMA_Ptr=0;
}
}
}
Else
{
ASCRevErroSign=1;
}
Whether correctly/* judges serial ports message (CRC check is according to MODBUS standard implementation) receiving
if(ModbusCRCVerify(ASCRevBuf, TempCount)!=0|| ASCRevErroSign)
{
ASCRevErroNum++; // reception error message number adds 1
/*
Receive the baud rate that continuous 6 wrong messages reset serial ports
*/
if(ASCRevErroNum>5)
{
BaudrateInde++;
BaudrateInde%=12;
ASC_Baudrate(ASC_Baudrate_Const【BaudrateInde】;
}
return;
}
/*
Carry out normal MODBUS handling process
*/
if(pAsc->pRxSem)
{
OSMboxPost(pAsc->pRxSem,&Asc1RxMsg);
}
ASCRevErroNum=0;
return;
}
}
void ASC_Baudrate_ (__word32 TheBaudrate,)
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_WordLength=USART_WordLength_8b; // 8 bit data positions
USART_InitStructure.USART_StopBits=USART_StopBits_1; // 1 position of rest
USART_InitStructure.USART_Parity=USART_Parity_No; // no parity
SART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None; // without data flow con-trol
USART_InitStructure.USART_Mode=USART_Mode_Rx | USART_Mode_Tx; // enable send and receive
USART_InitStructure.USART_BaudRate=TheBaudrate; Baud rate is set
USART_Init (USART2, & USART_InitStructure); Initialization serial ports
Enabling corresponding serial ports interrupts
USART_ITConfig(USART2,USART_IT_TC,DISABLE);
USART_ITConfig(USART2,USART_IT_RXNE,DISABLE);
USART_ITConfig(USART2,USART_IT_TXE ,DISABLE);
USART_ITConfig(USART2,USART_IT_IDLE,ENABLE);
USART_Cmd (USART2, ENABLE); Enable serial ports
}。

Claims (1)

1.MODBUS-RTU communication baud rate Auto-matching, it is characterized in that, its implementation procedure is as follows: the baud rate that serial ports is set when 1. slave station powers on is the baud rate of acquiescence, wait for the serial ports message receiving in bus, if the continuous message receiving for 5 times is error message, just to reset serial ports baud rate be the next baud rate that master-salve station is better, until while correctly receiving serial ports message, just with this baud rate and master station communication; 2. the in the situation that of proper communication, main website has changed baud rate, whether the message the standing-meeting bus that detection receives in real time is correct, if continuous 5 times receive error message, repeat baud rate matching process, until receive correct message, whether correctly the message that slave station the receives data format of basis for estimation MODBUS communication protocol carries out verification, main check (CRC) check code, whole message length.
CN201410289938.XA 2014-06-26 2014-06-26 Automatic MODBUS-RTU communication baud rate matching method Pending CN104052579A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410289938.XA CN104052579A (en) 2014-06-26 2014-06-26 Automatic MODBUS-RTU communication baud rate matching method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410289938.XA CN104052579A (en) 2014-06-26 2014-06-26 Automatic MODBUS-RTU communication baud rate matching method

Publications (1)

Publication Number Publication Date
CN104052579A true CN104052579A (en) 2014-09-17

Family

ID=51504971

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410289938.XA Pending CN104052579A (en) 2014-06-26 2014-06-26 Automatic MODBUS-RTU communication baud rate matching method

Country Status (1)

Country Link
CN (1) CN104052579A (en)

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104796222A (en) * 2014-11-21 2015-07-22 湖南先步信息股份有限公司 A CAN baud-rate automatic matching method
CN105656600A (en) * 2015-12-29 2016-06-08 湖南先步信息股份有限公司 Communication method for slave station to adapt to two communication protocols
CN106326157A (en) * 2015-06-30 2017-01-11 深圳市科陆电子科技股份有限公司 Method and device for receiving variable-length data of serial port
CN107147553A (en) * 2017-05-10 2017-09-08 深圳市亿维自动化技术有限公司 Method of adjustment, adjusting apparatus and the adjusting device of slave station baud rate and frame format
CN108072779A (en) * 2017-12-20 2018-05-25 福建利利普光电科技有限公司 A kind of digital oscilloscope CAN bus baud rate automatic identifying method
CN108259130A (en) * 2017-12-29 2018-07-06 伟乐视讯科技股份有限公司 The Modbus Transmission systems and method of a kind of baud rate even-odd check position adaptive
CN109361585A (en) * 2018-12-22 2019-02-19 沈阳阿尔特科技发展有限公司 A kind of method that child node baud rate and address is arranged in host node automatically
CN113691412A (en) * 2021-06-28 2021-11-23 国网浙江省电力有限公司台州供电公司 RS485 bus-based self-adaptive interception and analysis method for communication of power internet of things terminal
CN113688086A (en) * 2021-08-23 2021-11-23 湖南芯力特电子科技有限公司 Baud rate matching detection system of high-speed CAN transceiver for local network
CN114389911A (en) * 2022-01-13 2022-04-22 上海步科自动化股份有限公司 Parameter setting method, device, terminal and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20080041946A (en) * 2006-11-08 2008-05-14 엘지전자 주식회사 Apparatus and method for automatic boud rate setting
CN103777538A (en) * 2012-10-19 2014-05-07 重庆长安汽车股份有限公司 Baud-rate automatic matching method for controller and CAN bus

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20080041946A (en) * 2006-11-08 2008-05-14 엘지전자 주식회사 Apparatus and method for automatic boud rate setting
CN103777538A (en) * 2012-10-19 2014-05-07 重庆长安汽车股份有限公司 Baud-rate automatic matching method for controller and CAN bus

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104796222A (en) * 2014-11-21 2015-07-22 湖南先步信息股份有限公司 A CAN baud-rate automatic matching method
CN106326157A (en) * 2015-06-30 2017-01-11 深圳市科陆电子科技股份有限公司 Method and device for receiving variable-length data of serial port
CN105656600A (en) * 2015-12-29 2016-06-08 湖南先步信息股份有限公司 Communication method for slave station to adapt to two communication protocols
CN105656600B (en) * 2015-12-29 2019-05-10 湖南先步信息股份有限公司 A kind of communication means of the adaptive two kinds of communication protocol of slave station
CN107147553B (en) * 2017-05-10 2019-12-17 深圳市亿维自动化技术有限公司 Method, device and equipment for adjusting Baud rate and frame format of slave station
CN107147553A (en) * 2017-05-10 2017-09-08 深圳市亿维自动化技术有限公司 Method of adjustment, adjusting apparatus and the adjusting device of slave station baud rate and frame format
CN108072779A (en) * 2017-12-20 2018-05-25 福建利利普光电科技有限公司 A kind of digital oscilloscope CAN bus baud rate automatic identifying method
CN108259130A (en) * 2017-12-29 2018-07-06 伟乐视讯科技股份有限公司 The Modbus Transmission systems and method of a kind of baud rate even-odd check position adaptive
CN109361585A (en) * 2018-12-22 2019-02-19 沈阳阿尔特科技发展有限公司 A kind of method that child node baud rate and address is arranged in host node automatically
CN109361585B (en) * 2018-12-22 2021-10-26 沈阳阿尔特科技发展有限公司 Method for automatically setting baud rate and address of child node by main node
CN113691412A (en) * 2021-06-28 2021-11-23 国网浙江省电力有限公司台州供电公司 RS485 bus-based self-adaptive interception and analysis method for communication of power internet of things terminal
CN113688086A (en) * 2021-08-23 2021-11-23 湖南芯力特电子科技有限公司 Baud rate matching detection system of high-speed CAN transceiver for local network
CN114389911A (en) * 2022-01-13 2022-04-22 上海步科自动化股份有限公司 Parameter setting method, device, terminal and storage medium

Similar Documents

Publication Publication Date Title
CN104052579A (en) Automatic MODBUS-RTU communication baud rate matching method
CN105656600B (en) A kind of communication means of the adaptive two kinds of communication protocol of slave station
CN104796222A (en) A CAN baud-rate automatic matching method
CN103777538B (en) The baud rate automatic matching method of controller and CAN
CN103023715B (en) A kind of fault monitoring method based on RS485 bus communication link
CN106462528A (en) Power-saving mode for USB power delivery sourcing device
CN105610876A (en) Industrial control type automatic network communication protocol converter and communication protocol conversion method
CN104199298A (en) Controller area network (CAN) bus Baud rate self-adapting method
CN102332971B (en) Field-bus full duplex reliable communication method for numerical control system
CN104794089B (en) The method, apparatus and system to be communicated suitable for the modified UART of single-chip microcomputer
CN103916284A (en) RS485 communication interface automatic baud rate and communication address detection method
CN103795520B (en) Method for real-time synchronization based on FPGA message
CN101404556A (en) One-wire bus communication method
CN102053935A (en) MODBUS serial communication protocol-based communication method
TW201642535A (en) Universal serial bus (USB) hub for connecting different port types and method thereof
CN101626288A (en) UART device with Baud rate detection and set function and detection and set method thereof
CN103514724A (en) Adaptive configuration method of data acquisition unit
CN103986610A (en) Communication interface matching method, device and controller
CN106130856A (en) A kind of self adaptation baud rate RS485 communications protocol
CN107547475A (en) A kind of data processing equipment and its system for supporting more communication protocol conversions
CN105553628B (en) A kind of serial communication baud rate detection method and device
CN106610885A (en) Server failure detection system and method
CN106569440A (en) Method for achieving communication between microprocessor and touch screen based on MODBUS-RTU protocol
CN105922261B (en) A kind of robot controller and its control method
CN103268301B (en) A kind of half-duplex UART interface circuit of automatic stream

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20140917

RJ01 Rejection of invention patent application after publication