title: How to Map Modbus Register address using C / C++
body: <p>I am trying to implement a ModBus RTU Protocol over a UART Peripheral using STM32F4-Discovery Board.</p>
  
  <p>I am planning to implement Master and Slave functionality using Modbus RTU. </p>
  
  <p>Here are my Questions</p>
  
  <p>How could i move my received data in UART to MODBUS and Transmit data from MODBUS layer to UART, using C/C++ , Please provide some code snippet that can help me understand your explanation. (As of now i am thinking of coming up with some API's please suggest some patterns)</p>
  
  <p>secondly how could i implement Modbus Registers and coils. I meant how could i define there address as specified in the ModBus Application Manual. Please explain me with a code snippet. Below something i tried to implement. </p>
  
  <pre><code>/*Global Array, Structure and Variable Declarations*/
  /* So to access Discrete_Output_Coils[2345] 
     the valid address to include in the protocol would be
     so we have to access address 0x929 to read the 
     data.*/
  const unsigned short int Discrete_Output_Coils[4999];
  const unsigned short int Discrete_Input_Contacts[4999];
  const unsigned short int Analog_Input_Register[4999];
  const unsigned short int Anlog_output_Holding_Register[4999];
  </code></pre>