Inertial Navigation
   IMU and INS
   Your Application
   Unaided Position Estimate
Relative Attitude Determination

Orientation Sensors



   Sensor Model

Using the VN-100
   Embedded Library Example

VectorNav Embedded Firmware Library Example

The VectorNav embedded firmware library is an C/C++ library designed to simplify the development process when creating embedded applications that need to interface with the VectorNav product line of orientation sensors.

The purpose of the embedded firmware library is to help eliminate much of the upfront development cost normally required to learn the communication protocol associated with communicating with a sensor at a hardware level.

This article will walk you through an example application where we will use the embedded firmware library to communicate with the VN-100 orientation sensor using a ST Micro 32-bit microcontroller. Although this example is specific to the use of this particular microcontroller, even if you are using a different hardware platform, you will likely still benefit from this example.

STM32F10X-128K-EVAL Development Board

In this example we will use the ST Micro STM32F103 32-bit ARM microcontroller. ST provides a development board for this family of microcontrollers. More information can be found on the ST website about this board. Below is a link to their User Manual.

Keil uVision IDE and Keil ULINK 2 Programmer

For this example we will use the Keil uVision Integrated Development Environment. Keil provides an excellent compiler and IDE for a wide range of 32-bit ARM microcontrollers.

The programmer used is the Keil ULINK 2.

Connecting the STM32 Development Board to the VN-100 Development Board

In this example we will use the SPI interface on the VN-100. To use SPI we need to hook up a minimum of four signal lines; SCK, MISO, MOSI, and CS. Aside from the signal lines you will also need to connect the grounds planes for the two development boards so that the signals are referenced to the same ground. Additionally we will pull power from the STM32 dev board to power the VN-100. Optionally you can power the VN-100 development board with a separate power supply or by using the USB.

The signal lines on the two development boards are connected as shown below:

STM32 Dev Board Pin

VN-100 Dev Board Pin



Pin 1

3.3V Power supply


Pin 20



Pin 8

CS - Chip Select


Pin 15

SCK - Serial Clock


Pin 19

MISO - Master Input Slave Output


Pin 17

MOSI - Master Output Slave Input

RS-232 Serial Connection

The example program will send commands to the VN-100 and then relay the response to the user over the serial port. It is important to note that the STM32 development board serial connector has the same pinout as your PC, so in order to connect the UART1 on the STM32 to your PC you will need to use a NULL modem adapter. This adapter will cross over the RX (pin 2) of the cable with the TX (pin 3). If you try and use a standard serial cable such as the one included in the VN-100 development kit then you will not be able to communicate with the sensor without adding a NULL modem adapter. You can usually still find a NULL modem adapter at your local electronics store.

Example Code

The example code for this project is included with the firmware library download on our website. After extracting the zip file you fill find the code in the FWLib -> examples -> VN-100 -> SPI folder.

Program Expected Operation

The program provides an example of both a read and write operation for each register and command available on the VN-100. Upon boot-up the program will setup the serial port and SPI for correct operation. It will then write data to each register on the VN-100 and read back the new set value. For each register the device will print out the result over the serial port so that it can be easily viewed using any commonly available serial terminal program.

After each register has been set and read the program will go into an infinite loop where it will poll the sensor for the yaw, pitch, and roll one time per second.

Running the example program


In the firmware library main folder navigate to FWLib -> examples -> VN100 -> SPI -> project -> RVMDK folder and double click on the Project.Uv2 project file. If you have uVision IDE installed then it should open up the example project. After loading the project go to Project -> Build Target to compile the code. After a successful compilation go to Flash -> Download to load the program onto the development board. You will need to first ensure that the ULINK2 programmer is plugged into the development board, and that both have power prior to attempting to program the device.

After successfully programming the development board, unplug the ULINK2 programmer, and then press the Reset button located at the bottom left of the STM32 development board. The program will then begin to run and you should see the results appear at your serial terminal program.

Using the Embedded Firmware on Platforms other than the STMicro STM32

In order to use the firmware library on a different microcontroller you will need to edit the VN_user.c file so that the library can correctly use your hardware. In this file you will find three functions that you will need to edit.


This function is responsible for setting the slave select line on your microcontroller. Put the necessary code here to toggle the SS (also known as CS) line on the SPI bus high or low.


This function is responsible for both sending and receiving a 32-bit word out the SPI bus. You will need to put your SPI code control here.


The function is responsible for delaying the processor for a specified amount of time. This is used in the firmware library to ensure correcting timing of the communication sequences.