Elastic Sheep

Because elasticdog was already taken

Elastic Sheep header image 2

Testing the LUFA USB Serial with GPS data

May 15th, 2009 · No Comments · Uncategorized

In this post I will present my experimentations with the LUFA USB-Serial demo. My target is a Teensy board.

I will first check that the serial link is correctly working with a loopback test. Then I will plug my EM-406A GPS module to get NMEA data from the serial input to the host.

The USBtoSerial Demo

The USBtoSerial Demo can be found in the Demos/USBtoSerial directory of the LUFA distribution.

It is based on the CDC demo to which it add buffered UART management. Data sent by the PC are sent to the TX output of the Teensy while data read from the RX input are sent back to the PC.

On the PC side the USB device is viewed as a hardware serial port for which generic drivers exists in Windows and OS X, as in the CDC Demo case.

Adapting the LUFA library for the Teensy target

In my previous post I directly modified the original demo code to fit the target board. In this post I will rather keep the demo code untouched and create a specific board driver file for the Teensy target.

I still have to modify the makefile to select the correct MCU and clock speed:

#MCU = at90usb1287
MCU = at90usb162


#F_CPU = 8000000
F_CPU = 16000000

If we execute the makefile we notice that a LEDs.h file is missing:

In file included from USBtoSerial.h:51,
                 from USBtoSerial.c:31:
../../LUFA/Drivers/Board/LEDs.h:68:26: error: Board/LEDs.h: No such file or directory

As we are now using a USER board, the LUFA library tried to load driver files from our project directory but we haven’t provided any yet.

Driver stubs are available in the LUFA/DriverStub directory: create a Board directory in the USBtoSerial project and copy the LEDs.h from DriverStubs into it if you want to start from a bare driver. You can also copy LEDs.h from LUFA/Drivers/Board/USBKEY/LEDs.h.

Then you can modify LEDs.h to match the port you want to use for led output on your target.

In my case I will use the PD4 and PD5 outputs for LED1 and LED2, thus bit 4 and 5 on port D. I will not use LED3 and LED4.

#define LEDS_LED1    (1 << 4)
#define LEDS_LED2    (1 << 5)
static inline void LEDs_Init(void)

I also simplify USBtoSerial.c to just use two leds in the UpdateStatus function:

case Status_USBNotReady:
  LEDMask = (LEDS_LED1);
case Status_USBEnumerating:
  LEDMask = (LEDS_LED1 | LEDS_LED2);
case Status_USBReady:
  LEDMask = (LEDS_LED2);

You should now be able to fully compile the USBtoSerial project with a make command and obtain a USBtoSerial.hex file to download on your target.

Loopback test

To check if serial data are correctly exchanged with the target I establish a serial loopback by connecting the TXD output from the AT90USB162 to the its RXD input with a wire.

Teensy Serial Loopback

I now connect the board to the PC and check its behavior with GNU screen.

HOST:~ host$ screen tty.usbmodem0000111D1 115200

GNU Screen loopback

Expected behavior: each character you type should be sent to the target, received back and displayed once on the screen. If you push the Enter key, the Carriage-Return character will be sent and when received back the cursor will move back to the start of the line.

When the loopback is working you can connect a data source to the serial input.

Connecting a GPS

I now connect a GPS to my target. I am using my EM-406A module with a voltage adaptation circuit raising the level of its RX output from 2.8V to 5V.

Teensy connected to EM-406A GPS module

By default the EM-406 output serial data at 4800 bauds. I launch GNU Screen to observe incoming NMEA sentences.

HOST:~ host$ screen tty.usbmodem0000111D1 4800

GNU Screen GPS Data

Going further

The Teensy with the LUFA USB-Serial can be used as a replacement for a stock USB to RS-232 adapter but it is not really more useful than that for the moment.

My next goal is to use the AVR MCU to implement a GPS application, i.e doing NMEA parsing in real-time and being able to trigger events depending on positioning data.

Project Source Code


Tags: ·····

No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment