Abstract This paper describes the design and implementation of wireless sensor technology module based on Bluetooth technology. The interrupt control mode of analog/digital conversion of MC9S12DT128 microcontroller in CodeWarrior development environment and the driving process of master and slave Bluetooth modules are described in detail. The system includes two Bluetooth modules: the master Bluetooth module is controlled by PC; the slave Bluetooth module uses Freescale's MC9S12DT128 microcontroller as the core processor.
Keywords Wireless sensor network Bluetooth technology MC9S12DT128
Introduction
The development and wide application of microsensor technology have made wireless sensor networks an inevitable trend in the development of sensor networks. Wireless sensor networks are composed of a large number of ubiquitous tiny sensor nodes with communication and computing capabilities, densely deployed in unattended monitoring areas, and constitute an "intelligent" autonomous measurement and control network system that can independently complete the tasks set according to the environment. Since wireless sensor networks work in an unattended state for a long time, it is impossible to frequently replace the power supply for sensor nodes. Therefore, energy consumption becomes one of the key issues in the design of wireless sensor networks. When designing the system, the system energy consumption must be reduced as much as possible. This paper takes wireless sensor network technology as the theoretical basis and takes the teaching prototype system as the development goal. It proposes a design method for wireless sensor network nodes with MC9S12DT128 as the core processor and implemented by Bluetooth wireless communication protocol.
1 Hardware Design
1.1 System Principle
As a node in a wireless sensor network, this system consists of 7 parts: sensor unit, signal conditioning circuit, A/D conversion circuit, signal processing unit (implemented by a single-chip microcomputer), slave Bluetooth module, master Bluetooth module and PC workstation, as shown in Figure 1.
The specific working process is: the signal quantity in the environment collected by the sensor is sent to the analog input port of the MC9S12DT128 single-chip microcomputer through the conditioning circuit; the ATD module built into the single-chip microcomputer realizes A/D conversion, processes the conversion result, and transmits the processed signal to the slave Bluetooth module through UART. The master Bluetooth module is controlled by the PC, and the master and slave Bluetooth modules realize data exchange through the Bluetooth protocol.
Figure 1 System Principle Block Diagram
1.2 Introduction to MC9S12DT128
MC9S12DT128 is a high-performance 16-bit microcontroller from Freescale, powered by 5 V. Its core is S12, which is faster than the core CPU12 of 68HC12, and its bus frequency can reach 25 MHz. It features a rich set of I/O modules and communication modules dedicated to industrial control, as shown in Figure 2, and has a wide range of industrial applications.
Figure 2 MC9S12DT128 on-chip resources
The MC9S12DT128 microcontroller has an internal voltage regulator that converts 5 V to 2.5 V. Its core voltage is only 2.5 V, and its power consumption is very low. The external I/O is powered by 5 V, but the output power is software-adjustable, and the output power can be reduced to 50% of the full power. In addition, the microcontroller provides three low-power working modes: stop mode, sleep mode, and wait mode for users to choose; some communication modules can also be set to sleep mode to reduce the power consumption of the system. MC9S12DT128 not only has a fast computing speed, but also can reduce power consumption to a very low level, which is suitable for wireless sensor networks.
1.3 Master-slave Bluetooth module
This system contains two paired master and slave Bluetooth modules. The slave Bluetooth module is Hitachi's DOCENGMBM0202 Bluetooth module, which complies with the Bluetooth 1.1 specification and has a class 2 RF output. It supports multiple interfaces: USB interface, UART interface, PCM voice interface, PIO general I/O port, and ISP interface. In addition, this system uses UART to achieve communication between MC9S12DT128 and Bluetooth module, as well as Bluetooth module driver and signal transmission.
The main Bluetooth module uses the Jinou Bluetooth Development Platform 3.0 version developed based on CSR's BlueCore02 chip. It provides UART, RS232, USB, and SPI interfaces for users to develop and debug, and the audio interface can transmit Bluetooth voice. In this system, the PC controls the main Bluetooth module through the RS232 interface.
1.4 Sensor Selection
To reduce the energy consumption of the system, the sensors used in this system are all small and low-power sensors. Among them, the temperature sensor uses Maxim's MAX6611. Under normal working conditions, the supply current is only 150 μA and the power consumption is 0.75 mW; when the SHDN pin is grounded, it is in power saving mode, the supply current is only 1 μA and the power consumption is only 5 μW. The humidity sensor uses Honeywell's HIH4000, whose supply current under normal working conditions is only 200 μA and the power consumption is 1 mW. The pressure sensor uses Motorola's MPX4100A, whose supply current under normal working conditions is 7 mA and the power consumption is 35 mW. The total power consumption of the three sensors under normal working conditions is 36.75 mW; in power saving working conditions, the total power consumption is 36.005 mW.
2 Software Design
2.1 Interrupt Control Mode of MC9S12DT128
In this system, MC9S12DT128 is developed using CodeWarrior4.5, a development environment that integrates editing, compiling, debugging, and program downloading. CodeWarrior4.5 is a cross-compiler that supports high-level languages (such as C, C++, and Java), as well as assembly languages for most microcontrollers.
Interrupt control is an important milestone in the development of microprocessors and an effective way to improve CPU efficiency and reduce system power consumption.
Under CodeWarrior4.5, there are only two ways to define interrupt functions: using pragma TRAP_PROC or the interrupt keyword. The specific usage methods are as follows (assuming the interrupt function is named INCount):
① #pragma TRAP_PROC
void INCount(void){
Tcount++;
}
② interrupt void INCount(void){
tcount++;
}
Corresponding to the different definitions of the interrupt function, there are also two methods to initialize the interrupt vector table in CodeWarrior4.5:
① Use VECTOR ADDRESS or VECTOR keyword. The specific implementation method is to add the entry address of the interrupt function to the .prm file of the project:
VECTOR ADDRESS0x8AINCount
, where 0x8A is the interrupt entry address. Or, add the interrupt vector number:
VECTOR 69 INCount
, where 69 is the interrupt vector number.
② Use the keyword interrupt. The specific implementation method is to add the interrupt vector number when defining the interrupt function:
interrupt 69 void INCount(void){
tcount++;
}
, where 69 is the interrupt vector number.
2.2 Implementation of A/D conversion interrupt mode
In this system, the A/D conversion of the analog signal collected by the sensor is realized by the ATD module of the single-chip microcomputer. Using the interrupt control method for the ATD module can save system resources and improve the system execution speed.
First, the ATD module must be set to interrupt mode in the initialization program of the ATD module, and the ATD conversion completion interrupt must be enabled. The conversion completion interrupt function is named ATD0. Its function is to read the A/D conversion result. It is defined using the interrupt keyword:
#pragma CODE_SEG ATD0Interrupt_SEG
interrupt void ATD0(void){
ATD0STAT0_SCF = 0; //Disable interrupt
MeasureResult[0]=ATD0DR0H
; MeasureResult[1]=ATD0DR0L;
MeasureResult[2
]=ATD0DR1H; MeasureResult[3]=ATD0DR1L;
MeasureResult[4]=ATD0DR2H;
MeasureResult[5]=ATD0DR2L;
}
#pragma CODE_SEG DEFAULT
The interrupt function entry is implemented by adding the ATD interrupt entry address 0xFFD2 in the precompiled file, that is, adding the statement in P&E_Multilink_CyclonePro_linker.prm:
VECTOR ADDRESS 0xFFD2 ATD0
The Flash space of MC9S12DT128 is 128 KB, which adopts paging management. Its address allocation is:
RAM = READ_WRITE 0x0400 TO 0x1FFF;
/*unbanked Flash*/
ROM_4000 = READ_ONLY0x4000TO0x7FFF;
ROM_C000 = READ_ONLY0xC000 TO0xFEFF;
/*banked Flash*/
PAGE_38=READ_ONLY0x388000TO0x38BFFF;
PAGE_39=READ_ONLY0x398000TO0x39BFFF;
PAGE_3A=READ_ONLY0x3A8000TO0x3ABFFF;
PAGE_3B=READ_ONLY0x3B8000TO0x3BBFFF;
PAGE_3C=READ_ONLY0x3C8000TO0x3CBFFF;
PAGE_3D=READ_ONLY0x3D8000TO0x3DBFFF;
It can be seen that the Flash space is divided into two parts: unbanked Flash and banked Flash. For banked Flash, the functions defined in its space can only be called by the program on this page; while the functions defined in unbanked Flash can be called by any program in the project. In order for the interrupt function to respond to the interrupt request correctly, it must be placed in the unbanked Flash, so the interrupt function needs to be placed in a specific location. It can be seen from the definition of the A/D interrupt function ATD0 that ATD0 is defined in the CODE_SEG ATD0Interrupt_SEG part. CODE_SEG ATD0Interrupt_SEG is the self-defined ATD0 interrupt code segment, and its storage location is defined under the PLACEMENT keyword in the P&E_Multilink_CyclonePro_linker.prm file:
PLACEMENT
ATD0Interrupt_SEG,
COPY
INTOROM_C000
In this way, the location of ATD0Interrupt_SEG is defined in ROM_C000 of the unbanked Flash space.
Finally, create the ATD0Interrupt.c file in the project and declare the interrupt function ATD0() as an external function:
#pragma CODE_SEG ATD0Interrupt_SEG
extern void ATD0();
#pragma CODE_SEG DEFAULT
In this way, it can be ensured that the main program placed in any storage space can get a timely and correct interrupt response when requesting an interrupt.
2.3 Master-slave Bluetooth module driver
Bluetooth technology is a short-range wireless communication technology using the 2.4 GHz frequency band. Compared with other wireless communication methods, Bluetooth's transmission rate is not the fastest, but because of its advantages such as master-slave self-organizing micro-net, low power consumption, and open frequency band, it has a good prospect in the application of wireless sensor networks. The wireless
sensor network module in this design is implemented using Bluetooth communication. The signal collected by the sensor is converted by A/D, and the conversion result needs to be transmitted to the PC through Bluetooth wireless communication. The Bluetooth system can support two types of connections, namely point-to-point connection and point-to-multipoint connection. This forms two network structures: micro-net and scatternet. This system belongs to a micro-net with only one slave device. In this piconet, the master Bluetooth is the Bluetooth module connected to the PC, and the slave Bluetooth is the Bluetooth module connected to the microcontroller. The difference between the master and slave Bluetooth is that the master Bluetooth can actively send commands to search for Bluetooth devices, establish and disconnect links, while the slave Bluetooth must wait for the master Bluetooth command to start working. The communication between
the PC and the master Bluetooth module, and the microcontroller and the slave Bluetooth module is serial, with a baud rate of 57,600 b/s. The initialization process of the master and slave Bluetooth modules is roughly the same. The following 10 instructions are sent in sequence through serial communication:
Reset[01 03 0C 00]
Read_Buffer_Size[01 05 10 00]
Clear:Set_Event_Filter[01 05 0C 01 00]
Write_Scan_Enable[01 1A 0C 01 03]
Write_Authentication_Enable[01 20 0C 01 00]
Write_Voice_Setting[01 26 0C 02 60 00]
Set_Event_Filter[01 05 0C 03 02 00 02]
Write_Connection_Accept_Timeout[01 16 0C 02 00 20]
Write_Page_Timeout[01 18 0C 02 00 30]
Read_BD_ADDR[01 09 10 00]
After receiving the instruction, the Bluetooth module returns the corresponding instruction execution status. The processor determines the returned instruction status and sends the next instruction only after it is confirmed to be correct; otherwise, the current instruction must be resent. The workflow of the master and slave Bluetooth modules is shown in Figure 3.
Figure 3 Workflow of master and slave Bluetooth modules
The monitoring program is developed using VC6.0, and the Bluetooth instructions are encapsulated in the function to realize the control of the master Bluetooth module by the PC. Specifically, it includes: initializing and driving it to start working, actively searching for the slave Bluetooth module, completing the link, and displaying the instruction execution status and the searched Bluetooth device address; controlling the communication with the slave Bluetooth module, processing the data received by the master Bluetooth module, refreshing the data in real time, and displaying the measurement results of the temperature, humidity, and pressure sensors. The system operation results are shown in Figure 4.
Figure 4 Prototype system operation results
Conclusion
This system uses MC9S12DT128 as the core processor and uses Bluetooth technology to achieve wireless communication between the host computer and the sensor node, completing the development of a wireless sensor network module with 3 sensors. Experiments have shown that this system has the characteristics of low power consumption, high stability, good real-time performance, and stable data transmission. Its implementation is a useful attempt to establish a micro-sensor node in a wireless sensor network.
Previous article:Design of reversing radar control system
Next article:Design of a simple intelligent controller for street lamps
- Popular Resources
- Popular amplifiers
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- CGD and Qorvo to jointly revolutionize motor control solutions
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Nidec Intelligent Motion is the first to launch an electric clutch ECU for two-wheeled vehicles
- Bosch and Tsinghua University renew cooperation agreement on artificial intelligence research to jointly promote the development of artificial intelligence in the industrial field
- GigaDevice unveils new MCU products, deeply unlocking industrial application scenarios with diversified products and solutions
- Advantech: Investing in Edge AI Innovation to Drive an Intelligent Future
- CGD and QORVO will revolutionize motor control solutions
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [TI recommended course] #TI? Application of interface chips in automotive products#
- 【GD32E231_DIY】-01: Schematic diagram & PCB
- Live broadcast at 10 am today [ST three-phase motor control solution for home appliances]
- Apply for free evaluation! ——ESP32-S2-Kaluga-1 new multimedia development board, flexible disassembly and assembly to meet various needs
- What is the difference between a multivibrator and a bistable trigger? Their circuits are similar. What are the categories of triggers?
- Dengge's open source FOC motor driver data based on esp32 (less than 100 yuan, you can DIY it yourself)
- Key points of RF circuit design
- EEWORLD University Hall----TI.com Online Purchasing Special: Smart Buildings
- About the loop compensation part in DCDC current control mode
- Two-phase four-wire stepper motor