• Modbus the RTU communication protocol realizes - en.51rd.net on MCF51QE128

    Introduction

    The industrial control moved toward the centralized monitor, the collection and distribution control from the single plane control, now entered the network intensive manufacture time. Industry controller Lian Wang has also provided for the network management conveniently. Modbus is in the industry controller’s network protocol one kind. The Modbus agreement is applies on the electronic controller’s one kind of communication protocol. Through this agreement, the controller, the controller (e.g. ethernet) and between other equipment may correspond by way of the network. It already became one of mainstream industrial standards. The different manufacturer production’s control device may link through the Modbus agreement becomes the industry network, carries on the centralized monitor.

    Modbus communication protocol

    1 correspondence transfer method

    Each data byte includes: Each byte’s position, 1 outset position, 8 data positions, the smallest significant digit transmits, 1 parity check position (not to have verification first not to have), 1 stop position (has when verification), 2 stop positions (not to have time verification).

    Under the RTU pattern each byte form (11bit) as follows:
    Coding system: 8 binary systems
    Byte composition: the 1bit outset position, the 8bit data position, the most low position transmits, the 1bit parity check position, the 1bit stop position first (or does not have parity check position, transmits an additional stop position).

    2 data frame structure

    Address: Address for the correspondence transmission first byte. This byte indicated that from machine will receive the information which by the user hypothesis address transmits by the main engine. And each from machine has the only address, and response return by the respective address start. The main engine transmits the address indicated that will transmit from machine the address, but indicates the return from machine the transmission address from machine the address.

    Functional code: The correspondence transmission second byte. The ModBus communication protocol definition function number is 1~127. Only uses part of functional codes according to the actual need. As the main engine request transmission, tells through the functional code from machine execution any movement. Takes from machine the response, with the functional code which transmits from the main engine is the same from machine the transmission functional code, and indicated that from machine responded the main engine to carry on the operation. If from machine the transmission functional code’s highest order is 1, then indicated that from machine has not responded the operation or the transmission makes a mistake.

    Table 1 each complete data frame constitution

    Data area: But the data area basis different functional code is different. The data area may be the actual value, the establishment spot, the main engine transmission for from machine or for the main engine from machine the transmission the address.

    CRC code: Two byte error detection codes. The redundant cyclic code inspection (CRC) contains two bytes, namely 16 binary systems. The CRC code by the transmitter installation computation, lays aside in the transmitter data rear part. The receive information’s equipment recomputation receives the information again the CRC code, obtains the CRC code compared with the computation whether with to receive match case, if both do not tally, then indicates makes a mistake. The CRC code’s computational method is, initializes 16 registers is 1 first. Carries on gradually again every 8 bit data information processing. When carries on the CRC code computation only uses 8 bit data positions, the outset position and the stop position, if has parity check position also to include the parity check position, does not participate in the CRC code computation.

    When calculates the CRC code, 8 bit data and register’s data different or, obtains the result to moves lowly, with 0 fills the highest order. Again inspection most low position, if the most low position is 1, register’s content and initialization number different or, if the most low position is 0, does not carry on the “or else”.

    This process has been redundant 8 times. After the 8th shifting, next 8 again with present register’s content different or, this process is equally redundant with above 8 times. After all data message processes, finally register’s content is the CRC code value. When CRC code data transmission, receive low byte before. In practical application, to raise the operating speed, has used the table look-up method substitution computational method.

    3 Modbus RTU data frame structure

    Under the RTU pattern, between each data frame’s gap is 3.5 character positions at least. A complete data frame must want the continual transmission, when during a news two byte spacings are bigger than 1.5 character positions, this data frame is wrong, is given up by the receiving end.

    When the correspondence baudrate is smaller than is equal to 19 200b/s. Has the strict request to 1.5 character position /3.5 character position computing time. When the correspondence baudrate is bigger than 19 200b/s. 1.5 character positions fixed are 750μs, 3.5 character positions fixed are 1.75ms. Official Modbus the RTU stipulation standard is 3.5 character long periods, because the different serial port equipment the use environment different possibly presents 5~10 word lengths in the transmission the gaps. Compares the security regarding Modbus RTU the establishment is 50ms.

    4 use function code

    With function code as shown in Table 2.

    Table 2 function codes

    MCF51QE128 principal characteristic

    What the system core controller uses is Freescale Corporation promotes 32 monolithic integrated circuit MCF51QE128. It is section of 32 ColdFire V1 MCU, the characteristic includes: The stop electric current drops to 370nA,6μs awakens the time, the ultra low running current is 50mA; 50.33MHz ColdFire V1 essence movement frequency; 25.165MHz main line frequency; Is 8KB RAM most greatly; Highest 128KB dodges saves; 24 channel’s 12 ADC; Two simulation comparators; 2xSCI, 2xI2C, 2xSPI; 6 channels and two 3 channel’s timer PWM module; RTC; Most 70 group general input/outputs (GPIO); System integration frequency locking link (FLL) and software watch-dog; Internal clock source (ICS); Low power loss exterior 32kHz oscillator; The voltage range is 1.8~ 3.6V; Enlargement mode internal neterodyne, voltage regulator and real-time counter. The general development environment is CodeWarrior for Microcontrollers 6.0.

    Software design

    1 receive software flow
    As shown in Figure 1.

     

    Figure 1 from machine software flow

    2 disposition serial ports and timer

    void usart_init()

     SCI1C1=0×13; //9bit character mode, odd parity
     SCI1C2=0×2c;
     SCI1BDL=0×29; //38400bps
     SCI1BDH=0;
    }
    void timer3_init(void)//8MHz master clock 1333Hz interrupt judgment order package of conclusion
    {
     TPM3CNTH=0;
     TPM3CNTL=0;
     TPM3MODH=0×49;
     TPM3MODL=0xbe;  
     TPM3SC=0×48; 
    }

    3 MCF51QE128 bale breaking modbus RTU procedure

     void interrupt VectorNumber_ Vsci1rx SCI_RX_ISR(void)//byte receive procedure
     {
      if(SCI1S1_PF==1)communication_error=1; // byte verifies the wrong misplacement correspondence defeat flag bit
      * (pointer_RX1)=SCI1D; // puts in the data the cushion formation
      pointer_RX1 ; after // queue pointer, moves
      len_RX1 ; // receives the byte length to add 1
      timer3_reset(); // timer repositions
      timer3_init(); // fixed time thinks highly of the start
     }
     void interrupt VectorNumber_Vtpm3ovf a Timer3_ISR(void)//judgment order package of receive ended
     {
      timer3_cnt ; // timer interrupt number of times adds 1
      if(timer3_cnt==2)
       {   
    timer3_reset(); // timer repositions
    pointer_RX1=Buffer_RX1; // queue pointer initialization
      full_RX1=1; // receives sets at the flag bit
       }
     }

    4 CRC table look-ups have the function

    Because the length is limited, here no longer relates in detail, the table actual content may refer to the related reference.

    Summary

    Author’s design realizes the Modbus agreement based on the MCF51QE128 control core, already succeeded carries on the practical application, the correspondence has been reliable, moreover realizes is quite easy. This design to use the MCF51QE128 micro controller to carry on the manufactured products design correspondence the application to provide the reference plan.

    20080718130305.jpg

    20080718125811.jpg

    20080718125944.jpg

    Share/Save/Bookmark

No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

TOP
Copyright © 51 Research and Design, Electronic Engineers website - Embedded Systems, MCU, DSP, EDA, Test and Measurement, Components, Communications, Power, Microelectronics, Semiconductors
Powered by WordPress | Theme by mg12 | Valid XHTML 1.1 and CSS 3