Table of Contents
Wireless Communications TestingThis page serves to document the procedures taken to get the wireless communications link up and running.
Initial plans for the communications link were focused on utilizing the parallel port for transmitting data to the communications link. Ultimately it was decided that communications through the serial port would be a more suitable for our application. Parallel port information is listed below for documentation purposes only.
A decision was also made to move from MATLAB to LabVIEW, as the options available for threaded or real time applications in MATLAB are severely limited. LabVIEW can successfully act as a data acquisition, processing, and transmission platform. Documentation regarding MATLAB is included for completeness.
The serial port
After the decision was made to move from Matlab to the LabVIEW platform, it was decided that controlling communications would be much easier and likely more reliable if the serial port was utilized on the PC and the built in UART was used on the microprocessor.
The serial port in LabVIEWFor a successful communications link, LabVIEW must be capable of transmitting data serially at a selectable baud rate.
After some quick searching a package was found (link) which outlines serial communications in LabVIEW. This page contains a link to a library file (local copy) in which a LabVIEW VI can be found which can be adapted for use in our application. The VI which is of particular interest is the 'Basic Serial Write and Read.vi' file.
This vi can be integrated into the LabVIEW file which collects data from the BioRadio after a few modifications. The modifications made to this VI include
- hard coding some configuration values such as baud rate, parity, data bits, etc.
- removing serial port read functionality from the VI
- removing the port closing functionality internal to the VI (the port must manually be closed)
- modifying block inputs and outputs
The parallel port
In this case, the parallel communications port could be used as a simple communications link between a running application on a host computer and the wireless transmitter. The parallel port allows for raw data transmission to take place under full control of a software application.
The wireless communications protocol that was developed for use with the RF RX/TX pair can be implemented using the parallel port by bit-banging (systematically asserting the output level) the output within a controlled timing loop. This was not the method used in this project as a mechanism to control threaded timing loops in Matlab was not possible.
The parallel port has eight data pins, only one should be required for this application. Control of the parallel port's associated registers affects it mode of operation as well as data output.
|Register||LPT 1||LPT 2|
|data register(baseaddress + 0)||0x378||0x278|
|status register (baseaddress + 1)||0x379||0x279|
|control register (baseaddress + 2)||0x37a||0x27a|
Controlling the Parallel PortControl of the parallel port on an NT based OS is complicated by the addition of security layers that prevent user applications from complete access to the local machine's resources. This mean that Windows NT/2000/XP user applications cannot access the parallel port directly. Circumventing this security layer can be done by having a system level application (such as a driver) control the parallel port as per commands sent from a user level application. Such functionality is offered by the inpout32 DLL. This dll contains an embedded parallel port driver and compiled C functions for controlling it. This allows simple applications written in C++, Java, VB, and even MATLAB to read and write to the parallel port.
The Parallel Port and MATLABWriting to the parallel port in MATLAB is done by loading the inpout32.dll and then calling its respective functions with the necessary parameters.
Calling a DLL in MATLAB can be done by using the loadlibrary function as shown below.
- loadlibrary inpout32.dll inpout32.h
inpout32.h is a header file. This file provides MATLAB with information about the functions within the DLL that are available to be called. This header file can be created from the source code of the inpout32.dll file. It is also available here.
- Note: for the library to load successfully the .dll and .h file must be discoverable through the MATLAB 'PATH' variable or in the 'Current Directory'.
After the library is loaded, the functions within the header file can be called. The header file contains a function to read from the parallel port(Inp32), and one to write to the parallel port (Out32).
Writing to the parallel port can be performed using the following command.
- calllib('inpout32', 'Out32', 888, DATA)
- Note 888 = 0x378 = LPT1 Data Register.
- Where DATA is the value to be asserted at the data pins of the parallel port.
Reading from the parallel port can be performed using the following command.
- calllib('inpout32', 'Inp32', 888)
- Note 888 = 0x378.
Note: The user issuing these commands must have elevated account privileges (Administrator). Normal user accounts cannot modify the parallel port output.
Additional information is available from Mathworks regarding the use of libraries in MATLAB from link below.
The Parallel Port and JavaJava applications can make use of DLL files as well through the Java Native Interface (JNI) Useful Links:
The Communication ProtocolThe wireless communications link used is based on a frequency paired ASK transmitter module, and a receiver based on the Himark rx3400 IC.
These modules require a fairly neutral disparity of the data bits being transfered. This maintains DC balance.
Data transmissions are begun with a preamble of 0x55 0xAA. This synchronizes the communications link while maintaining DC balance.
After the preamble is transmitted, data communications may take place. Data packets should be in the format illustrated in the image below.
|0 = Left||Magnitude||0 = Forward||Magnitude|
|1 = Right||Magnitude||1 = Reverse||Magnitude|
As shown in the table above, the packet is comprised of two 4 bit sections. The first section controls left and right commands, while the latter controls forward and reverse commands. Of the first four bits (7 - 4) there is a single bit (7) allocated for determining the direction of travel. The remaining three bits (6-4) provide the magnitude in the given direction of travel. This provides 7 discrete levels of magnitude in either direction. The remaining portion of the packet is formed in a similar manner and applies to the forward and reverse controls.
After the data packet is constructed it is transmitted from the serial port through the wireless transmitter. Following this transmission, the complement of the packet should be transmitted. The transmission of the data packet and it's complement will allow for transmission error detection as well as help to keep neutral disparity.
Data transmissions should end with the assertion of a logical high level (this is handled automatically when transmitting data through the serial port). This will ease recognition of data transmissions on the receiving side as well as preventing the receiving module from collecting noise. Assertion of a logical high value will reduce noise reception at the vehicle only for a period of time. After some time the neutral disparity of the link will be lost and noise will be received at the RX module. This can be remedied by transmitting synchronization packets during times when data is not being transmitted.
Controlling TimingTiming issues were of greater concern when the plan was to use the parallel port. If that option was pursued tight timing loops would need to be created on both the PC and the microprocessor. By utilizing built in serial hardware on both the PC and the microprocessor this requirement is lifted as it is implicitly handled in hardware.
Configuring The USARTThe microprocessor's hardware USART was configured to complete the communications link between LabVIEW and the vehicle.
A few options must be configured to instruct the microprocessor to enable the USART and to configure it for communications.
- Enable the receive hardware.
- UCSRB = (1 << RXEN); - This also has the effect of setting Pin2 (PD0/RXD) as an input pin.
- Configure the serial settings
- No parity, 1 stop bit, 8 data bits
- UCSRC |= (1 << UCSZ0) | (1 << UCSZ1); - see ATtiny2313 datasheet
- Define baud rate
- The baud rate prescalar can be determine by using
the following equation:
UBRR = (Fosc/(Baud Rate * 16)) - 1
- Fosc = Clock Speed
- Baud Rate = Desired Baud Rate
- 16 -> mode selection (either 8 or 16)
- After determining baud rate prescalar, it can be moved into UBRR
- UBRR = (Fosc/(Baud Rate * 16)) - 1
- The baud rate prescalar can be determine by using the following equation:
- Enable RX complete interrupt
- UCSRB |= (1<< RXCIE);
AVRFreaks Guide - Using the USART with AVR-GCC
WiringConnecting the wireless transmitter and receiver boards to their respective ends of the communication system is fairly straight forward. Each end simply requires power, ground, and data connections.
A common ground between the serial ground and the transmitter board is required!
A Simple transmitter can be setup by using the microprocessor development board (Olimex AVR-P20) for this project. The board comes with an RS232 to TTL level shifter circuit on the board. Simply connect the computer's serial port to the DB9 connector on the development board (As shown in the schematic to the right). Connect the wireless transmitter to ground and power (+5V) on the development board. Also connect the TX line from the level shifter to Data pin on the transmitter.
RXThe schematic for the wireless receiver is equally as simple. The wireless receiver board needs to be connected to the regulated 5v supply on the vehicle, as well as to ground (see schematic to the right). Additionally the Data pin of the receiver should be connected to the microprocessor. The microprocessor handles interpreting the data received.
Distance TraveledPerform experiment to determine max distance traveled in between packets
Voltage Vs. Transmission RangePerform experiment to determine the effects of adjusting the voltage at the TX board on distance
Resources / Links
- Terminal - A simple serial terminal application
- logix4u.net - inpout32.dll interface to the parallel port under NT based OS
- logix4u.net - Parallel port operation/control
- Mathworks.com - notes regarding use of compiled dll's within MATLAB
- AVRFreaks Guide - Using the USART with AVR-GCC