msp430ware++ method of calling using 3:modbus module
Source: Internet
Author: User
Msp430ware++ 's call method using the 3:modbus module Msp430ware is a set of open source MSP430 hierarchical software architecture based on C + + language, which supports multiple peripherals. This article describes the calling method for the Modbus module driver.
1, the hardware schematic diagram uses the Modbus module driver to be connected with the MSP430 monolithic computer UART0 port.
2, use Method A, add driver
Select the Modbus folder and right-click "Exclude from Build". The Modbus driver consists of several files, as shown in the following illustration. Where RSP1_CONFIG.HPP is the RSP1 configuration file, RSP1.cpp is the RSP1 class source program, RSP1.HPP is the RSP1 class header file.
b, enabling peripherals in the CONFIG.HPP to enable peripherals Modbus, the source program is as follows: #define PROTOCOL_MODBUS1
C, the driver configuration.
The following options can be set, as explained below:
Modbus_reg_input_start: Enter register start address
Modbus_reg_input_nregs: Number of input registers (double-byte)
Modbus_reg_holding_start: Keep Register start address
Modbus_reg_holding_nregs: Keep the number of registers (double byte)
Modbus_mode: Mode, can be Mb_rtu (binary mode)
Mb_ascii (ASCII mode)
MB_TCP (TCP mode)
MODBUS_SLAVE_ID: From address
Modbus_baud: Baud rate
Modubs_parity: Parity bit, can be mb_par_none (invalid test)
Mb_par_odd (Miraculous examination)
Mb_par_even (parity) according to the actual requirements of the project, change the MODBUS_CONFIG.HPP configuration file, the following changes to the source program:
#define MODBUS_REG_INPUT_START 1 #define MODBUS_REG_INPUT_NREGS (2 * 16)
#define MODBUS_REG_HOLDING_START 1 #define MODBUS_REG_HOLDING_NREGS (2 * 64)
#define MODBUS_MODE Mb_rtu #define MODBUS_SLAVE_ID 1 #define MODBUS_BAUD 115200 #define Modubs _parity Mb_par_none
D, derivation of classes
has been set at the PTL level and does not need to be derived.
E, Declaration of objects
has been declared at the PTL level and does not need to be declared.
F, other operations
Modbus module itself occupies the UART0 and Timera, when used, should be shielded in C onfig.hpp, the source program is as follows:
#define INTERNAL_PERIPHERAL_CLOCK_MODE 1
#define INTERNAL_PERIPHERAL_UART0_MODE 0
#define INTERNAL_PERIPHERAL_TIMERA_MODE 0
G, Call method
Called on line 1th of the main loop, the following statement:
Target.PTL.Modbus.Dispose ();
At any point in the main loop, change the input register or maintain the value of the register, in case the main Modbus call, the sample code is as follows:
while (1) {Target.PTL.Modbus.Dispose (); if (Target.PTL.Modbus.flag = = True) {Target.PTL.Modbus.flag = False;// Receive write hold register data
//read-hold register/Read input register
Feed the Dog Target.HAL.WatchDog.Feed (); }
3, Cmodbus class member variables and member functions of the description member variables:
UInt16 Usreginputstart; Input register start address uint16 Usreginputbuf[modbus_reg_input_nregs]; The input register buffers buffer uint16 Usregholdingstart; Keep Register start address uint16 Usregholdingbuf[modbus_reg_holding_nregs]; Keep Registers Buffered buffer
member functions
Cmodbus (void); constructor void Dispose (void); Called on line 1th of the main loop
Note 1: The sample code in this article is in green notation.
Note 2: The member variables and member functions that are closely related to the use are marked in red in this article.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service