6DoF Robotic Arm


The R680 Banshi Robotic Arm

The R680 Banshi Robotic Arm is an affordable robot designed for educators and hobbyists. It can help users learn the basics of electronics, mechanics, and programming. The Banshi is controlled by an ATmega64 microcontroller that is programmable via open-source tools in C.

The robot includes many example programs that can be easily downloaded to the robot using the supplied USB interface and the RobotLoader software. You can also use the free open-source WinAVR software to write your own custom programs.

The robot can be controlled with the included keyboard or RACS software. The software can record and play back the Banshi’s movements. You can use I/Os and the flexible I2C bus system to add extra modules that enable the robot to react to its environment.


The Banshi Robot kit

The Banshi Robot comes unassembled as a kit with included assembly tools. The robot’s additional features include six degrees of freedom (6DoF), a 12-V power supply, an I2C bus, a USB interface, and a complete 72-page manual.

The Banshi Robotic Arm costs $199.

Global Specialties

Small, Self-Contained GNSS Receiver

TM Series GNSS modules are self-contained, high-performance global navigation satellite system (GNSS) receivers designed for navigation, asset tracking, and positioning applications. Based on the MediaTek chipset, the receivers can simultaneously acquire and track several satellite constellations, including the US GPS, Europe’s GALILEO, Russia’s GLONASS, and Japan’s QZSS.

LinxThe 10-mm × 10-mm receivers are capable of better than 2.5-m position accuracy. Hybrid ephemeris prediction can be used to achieve less than 15-s cold start times. The receiver can operate down to 3 V and has a 20-mA low tracking current. To save power, the TM Series GNSS modules have built-in receiver duty cycling that can be configured to periodically turn off. This feature, combined with the module’s low power consumption, helps maximize battery life in battery-powered systems.

The receiver modules are easy to integrate, since they don’t require software setup or configuration to power up and output position data. The TM Series GNSS receivers use a standard UART serial interface to send and receive NMEA messages in ASCII format. A serial command set can be used to configure optional features. Using a USB or RS-232 converter chip, the modules’ UART can be directly connected to a microcontroller or a PC’s UART.

The GPS Master Development System connects a TM Series Evaluation Module to a prototyping board with a color display that shows coordinates, a speedometer, and a compass for mobile evaluation. A USB interface enables simple viewing of satellite data and Internet mapping and custom software application development.
Contact Linx Technologies for pricing.

Linx Technologies

Member Profile: Scott Weber

Scott Weber

Scott Weber

Arlington, Texas, USA

Scott said he started his Circuit Cellar subscription late in the last century. He chose the magazine because it had the right mix of MCU programming and electronics.

He has always enjoyed mixing discrete electronic projects with MCUs. In the early 1980s, he built a MCU board based on an RCA CDP1802 with wirewrap and programmed it with eight switches and a load button.

Back in the 1990s, Scott purchased a Microchip Technology PICStart Plus. “I was thrilled at how powerful and comprehensive the chip and tools were compared to the i8085 and CDP1802 devices I tinkered with years before,” he said.

Scott said he recently treated himself to a brand-new Fluke 77-IV multimeter.

Scott is building devices that can communicate through USB to MS Windows programs. “I don’t have in mind any specific system to control, it is something to learn and have fun with,” he said. “This means learning not only an embedded USB software framework, but also Microsoft Windows device drivers.”

“Embedded devices are popping up everywhere—in places most people don’t even realize they are being used. It’s fun discovering where they are being applied. It is so much easier to change the microcode of an MCU or FPGA as the unit is coming off the assembly line than it is to rewire a complex circuit design,” Scott said.

“I also like Member Profile Joe Pfeiffer’s final comment in Circuit Cellar 276: Surface-mount and ASIC devices are making a ‘barrier to entry’ for the hobbyist. You can’t breadboard those things! I gotta learn a good way to make my own PCBs!”

Dual-Channel Waveform Generators

B&K Precision 4053 Waveform Generator

B&K Precision 4053 Waveform Generator

The 4050 Series is a new line of four dual-channel function/arbitrary waveform generators. The instruments can generate 5-to-50-MHz waveforms for applications requiring stable and precise sine, square, triangle, and pulse waveforms with modulation and arbitrary waveform capabilities.

All models provide a main output voltage that can be vary from 0 to 10 VPP into 50 Ω and a secondary output that can vary from 0 to 3 VPP into 50 Ω. The generators feature a 3.5” color LCD, a rotary control knob, and a numeric keypad with dedicated waveform keys and output buttons.

The 4050 Series provides users with 48 built-in arbitrary waveforms. Using the included waveform editing software via the standard USB interface on the rear, users can create and load up to 10 custom 16-kpt waveforms. For general-purpose interface bus (GPIB) connectivity, an optional USB-to-GPIB adapter is available.

The generators offer a variety of modulation schemes for modulated signal applications including amplitude and frequency modulation (AM/FM), double sideband amplitude modulation (DSB-AM), amplitude and frequency shift keying (ASK/FSK), phase modulation (PM), and pulse-width modulation (PWM). Additional standard features include a linear and logarithmic sweep function, a built-in counter, sync output, a trigger I/O terminal, and a USB host port on the front panel to save and recall instrument settings and waveforms. A standard external 10-MHz reference clock input is provided to synchronize the instrument to another generator.

The 4052 (5-MHz) costs $499, the 4053 (10 MHz) costs $599, the 4054 (25 MHz) costs $850, and the 4055 (50 MHz) costs $1,050. Note: B&K Precision is offering 10% off MSRP through November 30, 2013. See website for details.

B&K Precision Corp.

OEM Host Adapter Flash Memory

Total Phase Aaardvark USB-to-I2C Host Adapter

Total Phase Aardvark USB-to-I2C Host Adapter

The Aardvark OEM Adapter is based on Total Phase’s Aardvark I2C/SPI USB-to-I2C adapter, which is a flexible tool for system design and testing. The new adapter is available in an I2C or SPI configuration and includes the Total Phase API, which enables you to create custom application GUIs.

The Aardvark OEM Adapter and API are cross-platform compatible with various OSes, including Windows, Linux, and Mac OS X. In a production environment, you can use the API for automated testing or device programming.

Contact Total Phase for pricing.

Total Phase, Inc.

Low-Cost, High-Performance 32-bit Microcontrollers

The PIC32MX3/4 32-bit microcontrollers are available in 64/16-, 256/64-, and 512/128-KB flash/RAM configurations. The microcontrollers are coupled with Microchip Technology’s software and tools for designs in connectivity, graphics, digital audio, and general-purpose embedded control.

The microcontrollers offer high RAM memory options and high peripheral integration at a low cost. They feature 28 10-bit ADCs, five UARTS, 105-DMIPS performance, serial peripherals, a graphic display, capacitive touch, connectivity, and digital audio support.
The PIC32MX3/4 microcontrollers are supported with general software development tools, including Microchip Technology’s MPLAB X integrated development environment (IDE) and the MPLAB XC32 C/C++ compiler.

Application-specific tools include the Microchip Graphics Display Designer X and the Microchip Graphics Library, which provide a visual design tool that enables quick and easy creation of graphical user interface (GUI) screens for applications. The microcontrollers are also supported with a set of Microchip’s protocol stacks including TCP/IP, USB Device and Host, Bluetooth, and Wi-Fi. For digital audio applications, Microchip provides software for tasks such as sample rate conversion (SRC), audio codecs—including MP3 and Advanced Audio Coding (AAC), and software to connect smartphones and other personal electronic devices.

The PIC32MX3/4 family is supported by Microchip’s PIC32 USB Starter Kit III, which costs $59.99 and the PIC32MX450 100-pin USB plug-in module, which costs $25 for the modular Explorer 16 development system. Pricing for the PIC32MX3/4 microcontrollers starts at $2.50 each in 10,000-unit quantities.

Microchip Technology, Inc.

Accurate Measurement Power Analyzer

The PA4000 power analyzer provides accurate power measurements. It offers one to four input modules, built-in test modes, and standard PC interfaces.

The analyzer features innovative Spiral Shunt technology that enables you to lock onto complex signals. The Spiral Shunt design ensures stable, linear response over a range of input current levels, ambient temperatures, crest factors, and other variables. The spiral construction minimizes stray inductance (for optimum high-frequency performance) and provides high overload capability and improved thermal stability.

The PA4000’s additional features include 0.04% basic voltage and current accuracy, dual internal current shunts for optimal resolution, frequency detection algorithms for noisy waveform tracking, application-specific test modes to simplify setup. The analyzer  easily exports data to a USB flash drive or PC software. Harmonic analysis and communications ports are included as standard features.

Contact Tektronix for pricing.

Tektronix, Inc.

Data Acquisition Instrument

The DI-145 USB data acquisition instrument features four ±100-V analog channels and two dedicated digital inputs. The included DATAQ WinDaq data acquisition software (DAS) enables you to display and record data to a PC hard drive in real time. Once recorded, data can be played back, analyzed, or exported to an array of data acquisition and spreadsheet formats.

DATAQ also provides access to the DI-145 data protocol, which enables access to the DI-145 on any Windows, Linux, or MAC OS. In addition, .NET control is available to Windows users who wish to use a third-party programming language (e.g., Microsoft’s Visual Basic or National Instruments’s LabVIEW) to interface with the DI-145.

The four ±10-V fixed differential channels are protected from transient spikes up to ±150 V peak (±75 V, continuous). A 10-bit ADC provides 19.5-mV resolution across the full-scale measurement range. Digital inputs are protected up to ±30 VDC/peak AC. The digital inputs enable you to use a switch closure or TTL signal to remotely insert event marks or record data to disk.

The DI-145 measures 1.53” × 2.625” × 5.5” (3.89 cm × 6.67 cm × 13.97 cm) and weighs 3.6 oz. The data acquisition instrument costs $29 and includes a mini screwdriver, a USB cable, WinDaq/Lite DAS, access to the data protocol, and .NET control.

DATAQ Instruments, Inc.

AAR Arduino Autonomous Mobile Robot

The AAR Arduino Robot is a small autonomous mobile robot designed for those new to robotics and for experienced Arduino designers. The robot is well suited for hobbyists and school projects. Designed in the Arduino open-source prototyping platform, the robot is easy to program and run.

The AAR, which is delivered fully assembled, comes with a comprehensive CD that includes all the software needed to write, compile, and upload programs to your robot. It also includes a firmware and hardware self test. For wireless control, the robot features optional Bluetooth technology and a 433-MHz RF.

The AAR robot’s features include an Atmel ATmega328P 8-bit AVR-RISC processor with a 16-MHz clock, Arduino open-source software, two independently controlled 3-VDC motors, an I2C bus, 14 digital I/Os on the processor, eight analog input lines, USB interface programming, an on-board odometer sensor on both wheels, a line tracker sensor, and an ISP connector for bootloader programming.

The AAR’s many example programs help you get your robot up and running. With many expansion kits available, your creativity is unlimited.

Contact Global Specialties for pricing.

Global Specialties

New Products: July 2013



The USBee QX is a PC-based mixed-signal oscilloscope (MSO) integrated with a protocol analyzer utilizing USB 3.0 and Wi-Fi technology. The highly integrated, 600-MHz MSO features 24 digital channels and four analog channels.

With its large 896-Msample buffer memory and data compression capability, the USBeeQX can capture up to 32 days of traces. It displays serial or parallel protocols in a human-readable format, enabling developers to find and resolve obscure and difficult defects. The MOS includes popular serial protocols (e.g., RS-232/UARTs, SPI, I2C, CAN, SDIO, Async, 1-Wire, and I2S), which are typically costly add-ons for benchtop oscilloscopes. The MOS utilizes APIs and Tool Builders that are integrated into the USBee QX software to support any custom protocol.

The USBee QX’s Wi-Fi capability enables you set up testing in the lab while you are at your desk. The Wi-Fi capability also creates electrical isolation of the device under test to the host computer.

The USBee QX costs $2,495.

CWAV, Inc.


DownStream Technologies FabStream


FabStream is an integrated PCB design and manufacturing solution designed for the DIY electronics market, including small businesses, start-ups, engineers, inventors, hobbyists, and other electronic enthusiasts. FabStream consists of free SoloPCB Design software customized to each manufacturing partner in the FabStream network.

The FabStream service works in three easy steps. First, you log onto the FabStream website (www.fabstream.com), select a FabStream manufacturing partner, and download the free design software. Next, you create PCB libraries, schematics, and board layouts. Finally, the software leads you through the process of ordering PCBs online with the manufacturer. You only pay for the PCBs you purchase. Because the service is mostly Internet-based, FabStream can be accessed globally and is available 24/7/365.

FabStream’s free SoloPCB Design software includes a commercial-quality schematic capture, PCB layout, and autorouting in one, easy-to-use environment. The software is customized to each manufacturing partner. All of the manufacturer’s production capabilities are built into SoloPCB, enabling you to work within the manufacturers’ constraints. Design changes can be made and then verified through an integrated analyzer that uses a quick pass/fail check to compare the modification to the manufacturer’s rules.

SoloPCB does not contain any CAM outputs. Instead, a secure, industry-standard IPC-2581 manufacturing file is automatically extracted, encrypted, and electronically routed to the manufacturer during the ordering process. The IPC-2581 file contains all the design information needed for manufacturing, which eliminates the need to create Gerber and NC drill files.

FabStream is available as a free download. More information can be found at www.fabstream.com

DownStream Technologies, LLC


Rohde Schwarz SMW200A


The R&S SMW200A high-performance vector signal generator combines flexibility, performance, and intuitive operation to quickly and easily generate complex, high-quality signals for LTE Advanced and next-generation mobile standards. The generator is designed to simpify complex 4G device testing.

With its versatile configuration options, the R&S SMW200A’s range of applications extends from single-path vector signal generation to multichannel multiple-input and multiple-output (MIMO) receiver testing. The vector signal generator provides a baseband generator, a RF generator, and a real-time MIMO fading simulator in a single instrument.

The R&S SMW200A covers the100 kHz-to-3-GHz, or 6 GHz, frequency range, and features a 160-MHz I/Q modulation bandwidth with internal baseband. The generator is well suited for verification of 3G and 4G base stations and aerospace and defense applications.

The R&S SMW200A can be equipped with an optional second RF path for frequencies up to 6 GHz. It can have a a maximum of two baseband and four fading simulator modules, providing users with two full-featured vector signal generators in a single unit. Fading scenarios, such as 2 × 2 MIMO, 8 × 2 MIMO for TD-LTE, and 2 × 2 MIMO for LTE Advanced carrier aggregation, can be easily simulated.

Higher-order MIMO applications (e.g., 3 × 3 MIMO for WLAN or 4 × 4 MIMO for LTE-FDD) are easily supported by connecting a third and fourth source to the R&S SMW200A. The R&S SGS100A are highly compact RF sources that are controlled directly from the front panel of the R&S SMW200A.

The R&S SMW200A ensures high accuracy in spectral and modulation measurements. The SSB phase noise is –139 dBc (typical) at 1 GHz (20 kHz offset). Help functions are provided for additional ease-of-use, and presets are provided for all important digital standards and fading scenarios. LTE and UMTS test case wizards simplify complex base station conformance testing in line with the 3GPP specification.

Contact Rohde & Schwarz for pricing.

Rohde & Schwarz


Texas Instruments CC2538


The Texas Instruments (TI) CC2538 system-on-chip (SoC) is designed to simplify the development of ZigBee wireless connectivity-enabled smart energy infrastructure, home and building automation, and intelligent lighting gateways. The cost-efficient SoC features an ARM Cortex-M3 microcontroller, memory, and hardware accelerators on one piece of silicon. The CC2538 supports ZigBee PRO, ZigBee Smart Energy and ZigBee Home Automation and lighting standards to deliver interoperability with existing and future ZigBee products. The SoC also uses IEEE 802.15.4 and 6LoWPAN IPv6 networks to support IP standards-based development.

The CC2538 is capable of supporting fast digital management and features scalable memory options from 128 to 512 KB flash to support smart energy infrastructure applications. The SoC sustains a mesh network with hundreds of end nodes using integrated 8-to-32-KB RAM options that are pin-for-pin compatible for maximum flexibility.

The CC2538’s additional benefits include temperature operation up to 125°C, optimization for battery-powered applications using only 1.3 uA in Sleep mode, and efficient processing for centralized networks and reduced bill of materials cost through integrated ARM Cortex-M3 core.

The CC2538 development kit (CC2538DK) provides a complete development platform for the CC2538, enabling users to see all functionality without additional layout. It comes with high-performance CC2538 evaluation modules (CC2538EMK) and motherboards with an integrated ARM Cortex-M3 debug probe for software development and peripherals including an LCD, buttons, LEDs, light sensor and accelerometer for creating demo software. The boards are also compatible with TI’s SmartRF Studio for running RF performance tests. The CC2538 supports current and future Z-Stack releases from TI and over-the-air software downloads for easier upgrades in the field.

The CC2538 is available in an 8-mm x 8-mm QFN56 package and costs $3 in high volumes. The CC2538 is also available through TI’s free sample program. The CC2538DK costs $299.

Texas Instruments, Inc.

The Future of Data Acquisition Technology

Maurizio Di Paolo Emilio

Maurizio Di Paolo Emilio

By Maurizio Di Paolo Emilio

Data acquisition is a necessity, which is why data acquisition systems and software applications are essential tools in a variety of fields. For instance, research scientists rely on data acquisition tools for testing and measuring their laboratory-based projects. Therefore, as a data acquisition system designer, you must have an in-depth understanding of each part of the systems and programs you create.

I mainly design data acquisition software for physics-related experiments and industrial applications. Today’s complicated physics experiments require highly complex data acquisition systems and software that are capable of managing large amounts of information. Many of the systems require high-speed connections and digital recording. And they must be reconfigurable. Signals that are hard to characterize and analyze with a real-time display are evaluated in terms of high frequencies, large dynamic range, and gradual changes.

Data acquisition software is typically available in a text-based user interface (TUI) that comprises an ASCII configuration file and a graphic user interface (GUI), which are generally available with any web browser. Both interfaces enable data acquisition system management and customization, and you don’t need to recompile the sources. This means even inexperienced programmers can have full acquisition control.

Well-designed data acquisition and control software should be able to quickly recover from instrumentation failures and power outages without losing any data. Data acquisition software must provide a high-level language for algorithm design. Moreover, it requires data-archiving capability for verifying data integrity.

You have many data acquisition software options. An example is programmable software that uses a language such as C. Other software and data acquisition software packages enable you to design the custom instrumentation suited for specific applications (e.g., National Instruments’s LabVIEW and MathWorks’s MATLAB).

In addition to data acquisition software design, I’ve also been developing embedded data acquisition systems with open-source software to manage user-developed applications. The idea is to have credit-card-sized embedded data acquisition systems managing industrial systems using open-source software written in C. I’m using an ARM processor that will give me the ability to add small boards for specific applications (e.g., a board to manage data transmission via Wi-Fi or GSM).

A data acquisition system’s complexity tends to increase with the number of physical properties it must measure. Resolution and accuracy requirements also affect a system’s complexity. To eliminate cabling and provide for more modularity, you can combine data acquisition capabilities and signal conditioning in one device.

Recent developments in the field of fiber-optic communications have shown longer data acquisition transmission distances can cause errors. Electrical isolation is also an important topic. The goal is to eliminate ground loops (common problems with single-ended measurements) in terms of accuracy and protection from voltage spikes.

During the last year, some new technological developments have proven beneficial to the overall efficacy of data acquisition applications. For instance, advances in USB technology have made data acquisition and storage simpler and more efficient than ever (think “plug and play”). Advances in wireless technology have also made data transmission faster and more secure. This means improved data acquisition system and software technologies will also figure prominently in smartphone design and usage.

If you look to the future, consumer demand for mobile computing systems will only increase, and this will require tablet computers to feature improved data acquisition and storage capabilities. Having the ability to transmit, receive, and store larger amounts of data with tablets will become increasingly important to consumers as time goes on. There are three main things to consider when creating a data acquisition-related application for a tablet. Hardware connectivity: Tablets have few control options (e.g., Wi-Fi and Bluetooth). Program language support: Many tablets support Android apps created in Java. Device driver availability: Device drivers permit a high-level mode to easily and reliably execute a data acquisition board’s functionality. C and LabVIEW are not supported by Android or Apple’s iOS. USB, a common DAQ bus, is available in a set of tablets. In the other case, an adapter is required. In these instances, moving a possible data acquisition system to a tablet requires extra attention.

For all of the aforementioned reasons, I think field-programmable arrays (FPGAs) will figure prominently in the evolution of data acquisition system technology. The flexibility of FPGAs makes them ideal for custom data acquisition systems and embedded applications.

Debugging USB Firmware

You’ve written firmware for your USB device and are ready to test it. You attach the device to a PC and the hardware wizard announces: “The device didn’t start.” Or, the device installs but doesn’t send or receive data. Or, data is being dropped, the throughput is low, or some other problem presents itself. What do you do?

This article explores tools and techniques to debug the USB devices you design. The focus is on USB 2.0 devices, but much of the information also applies to developing USB 3.0 (SuperSpeed) devices and USB hosts for embedded systems.


If you do anything beyond a small amount of USB developing, a USB protocol analyzer will save you time and trouble. Analyzers cost less than they used to and are well worth the investment.

A hardware-based analyzer connects in a cable segment upstream from the device under test (see Photo 1).

Photo 1: The device under test connects to the analyzer, which
captures the data and passes it unchanged to the device’s host. The
cable on the back of the analyzer carries the captured data to the
analyzer’s host PC for display.

You can view the data down to each packet’s individual bytes and see exactly what the host and device did and didn’t send (see Photo 2).

Photo 2: This bus capture shows the host’s request for a configuration
descriptor and the bytes the device sent in response. Because the endpoint’s
maximum packet size is eight, the device sends the first 8 bytes in one
transaction and the final byte in a second transaction.

An analyzer can also decode data to show standard USB requests and class-specific data (see Photo 3).

Photo 3: This display decodes a received configuration descriptor and its subordinate descriptors.

To avoid corrupted data caused by the electrical effects of the analyzer’s connectors and circuits, use short cables (e.g., 3’ or less) to connect the analyzer to the device under test.

Software-only protocol analyzers, which run entirely on the device’s host PC, can also be useful. But, this kind of analyzer only shows data at the host-driver level, not the complete packets on the bus.


The first rule for developing USB device firmware is to remember that the host computer controls the bus. Devices just need to respond to received data and events. Device firmware shouldn’t make assumptions about what the host will do next.

For example, some flash drives work under Windows but break when attached to a host with an OS that sends different USB requests or mass-storage commands, sends commands in a different order, or detects errors Windows ignores. This problem is so common that Linux has a file, unusual_devs.h, with fixes for dozens of misbehaving drives.

The first line of defense in writing USB firmware is the free USB-IF Test Suite from the USB Implementers Forum (USB-IF), the trade group that publishes the USB specifications. During testing, the suite replaces the host’s USB driver with a special test driver. The suite’s USB Command Verifier tool checks for errors (e.g., malformed descriptors, invalid responses to standard USB requests, responses to Suspend and Resume signaling, etc.). The suite also provides tests for devices in some USB classes, such as human interface devices (HID), mass storage, and video.

Running the tests will usually reveal issues that need attention. Passing the tests is a requirement for the right to display the USB-IF’s Certified USB logo.


Like networks, USB communications have layers that isolate different logical functions (see Table 1).

Table 1: USB communications use layers, which are each responsible for a
specific logical function.

The USB protocol layer manages USB transactions, which carry data packets to and from device endpoints. A device endpoint is a buffer that is a source or sink of data at the device. The host sends data to Out endpoints and receives data from In endpoints. (Even though endpoints are on devices, In and Out are defined from the host’s perspective.)

The device layer manages USB transfers, with each transfer moving a chunk of data consisting of one or more transactions. To meet the needs of different peripherals, the USB 2.0 specification defines four transfer types: control, interrupt, bulk, and isochronous.

The function layer manages protocols specific to a device’s function (e.g., mouse, printer, or drive). The function protocols may be a combination of USB class, industry, and vendor-defined protocols.


The layers supported by device firmware vary with the device hardware. At one end of the spectrum, a Future Technology Devices International (FTDI) FT232R USB UART controller handles all the USB protocols in hardware. The chip has a USB device port that connects to a host computer and a UART port that connects to an asynchronous serial port on the device.

Device firmware reads and writes data on the serial port, and the FT232R converts it between the USB and UART protocols. The device firmware doesn’t have to know anything about USB. This feature has made the FT232R and similar chips popular!

An example of a chip that is more flexible but requires more firmware support is Microchip Technology’s PIC18F4550 microcontroller, which has an on-chip, full-speed USB device controller. In return for greater firmware complexity, the PIC18F4550 isn’t limited to a particular host driver and can support any USB class or function.

Each of the PIC18F4550’s USB endpoints has a series of registers—called a buffer descriptor table (BDT)—that store the endpoint buffer’s address, the number of bytes to send or receive, and the endpoint’s status. One of the BDT’s status bits determines the BDT’s ownership. When the CPU owns the BDT, firmware can write to the registers to prepare to send data or to retrieve received data. When the USB module owns the BDT, the endpoint can send or receive data on the bus.

To send a data packet from an In endpoint, firmware stores the bytes’ starting address to send and the number of bytes and sets a register bit to transfer ownership of the BDT to the USB module. The USB module sends the data in response to a received In token packet on the endpoint and returns BDT ownership to the CPU so firmware can set up the endpoint to send another packet.

To receive a packet on an Out endpoint, firmware stores the buffer’s starting address for received bytes and the maximum number of bytes to receive and transfers ownership of the BDT to the USB module. When data arrives, the USB module returns BDT ownership to the CPU so firmware can retrieve the data and transfer ownership of the BDT back to the USB module to enable the receipt of another packet.

Other USB controllers have different architectures and different ways of managing USB communications. Consult your controller chip’s datasheet and programming guide for details. Example code from the chip vendor or other sources can be helpful.


A USB 2.0 transaction consists of a token packet and, as needed, a data packet and a handshake packet. The token packet identifies the packet’s type (e.g., In or Out), the destination device and endpoint, and the data packet direction.

The data packet, when present, contains data sent by the host or device. The handshake packet, when present, indicates the transaction’s success or failure.

The data and handshake packets must transmit quickly after the previous packet, with only a brief inter-packet delay and bus turnaround time, if needed. Thus, device hardware typically manages the receiving and sending of packets within a transaction.

For example, if an endpoint’s buffer has room to accept a data packet, the endpoint stores the received data and returns ACK in the handshake packet. Device firmware can then retrieve the data from the buffer. If the buffer is full because firmware didn’t retrieve previously received data, the endpoint returns NAK, requiring the host to try again. In a similar way, an In endpoint will NAK transactions until firmware has loaded the endpoint’s buffer with data to send.

Fine tuning the firmware to quickly write and retrieve data can improve data throughput by reducing or eliminating NAKs. Some device controllers support ping-pong buffers that enable an endpoint to store multiple packets, alternating between the buffers, as needed.


In all but isochronous transfers, a data-toggle value in the data packet’s packet identification (PID) field guards against missed or duplicate data packets. If you’re debugging a device where data is transmitting on the bus and the receiver is returning ACK but ignoring or discarding the data, chances are good that the device isn’t sending or expecting the correct data-toggle value. Some device controllers handle the data toggles completely in hardware, while others require some firmware control.

Each endpoint maintains its own data toggle. The values are DATA0 (0011B) and DATA1 (1011B). Upon detecting an incoming data packet, the receiver compares its data toggle’s state with the received data toggle. If the values match, the receiver toggles its value and returns ACK, causing the sender to toggle its value for the next transaction.

The next received packet should contain the opposite data toggle, and again the receiver toggles its bit and returns ACK. Except for control transfers, the data toggle on each end continues to alternate in each transaction. (Control transfers always use DATA0 in the Setup stage, toggle the value for each transaction in the Data stage, and use DATA1 in the Status stage.)

If the receiver returns NAK or no response, the sender doesn’t toggle its bit and tries again with the same data and data toggle. If a receiver returns ACK, but for some reason the sender doesn’t see the ACK, the sender thinks the receiver didn’t receive the data and tries again using the same data and data toggle. In this case, the repeated data receiver ignores the data, doesn’t toggle the data toggle, and returns ACK, resynchronizing the data toggles. If the sender mistakenly sends two packets in a row with the same data-toggle value, upon receiving the second packet, the receiver ignores the data, doesn’t toggle its value, and returns ACK.


All USB devices must support control transfers and may support other transfer types. Control transfers provide a structure for sending requests but have no guaranteed delivery time. Interrupt transfers have a guaranteed maximum latency (i.e., delay) between transactions, but the host permits less bandwidth for interrupt transfers compared to other transfer types. Bulk transfers are the fastest on an otherwise idle bus, but they have no guaranteed delivery time, and thus can be slow on a busy bus. Isochronous transfers have guaranteed delivery time but no built-in error correction.

A transfer’s amount of data depends in part on the higher-level protocol that determines the data packets’ contents. For example, a keyboard sends keystroke data in an interrupt transfer that consists of one transaction with 8 data bytes. To send a large file to a drive, the host typically uses one or more large transfers consisting of multiple transactions. For a high-speed drive, each transaction, except possibly the last one, has 512 data bytes, which is the maximum-allowed packet size for high-speed bulk endpoints.

What determines a transfer’s end varies with the USB class or vendor protocol. In many cases, a transfer ends with a short packet, which is a packet that contains less than the packet’s maximum-allowed data bytes. If the transfer has an even multiple of the packet’s maximum-allowed bytes, the sender may indicate the end of the transfer with a zero-length packet (ZLP), which is a data packet with a PID and error-checking bits but no data.

For example, USB virtual serial-port devices in the USB communications device class use short packets to indicate the transfer’s end. If a device has sent data that is an exact multiple of the endpoint’s maximum packet size and the host sends another In token packet, the endpoint should return a ZLP to indicate the data’s end.


Upon device attachment, in a process called enumeration, the host learns about the device by requesting a series of data structures called descriptors. The host uses the descriptors’ information to assign a driver to the device.

If enumeration doesn’t complete, the device doesn’t have an assigned driver, and it can’t perform its function with the host. When Windows fails to find an appropriate driver, the setupapi.dev.log file in Windowsinf (for Windows 7) can offer clues about what went wrong. A protocol analyzer shows if the device returned all requested descriptors and reveals mistakes in the descriptors.

During device development, you may need to change the descriptors (e.g., add, remove, or edit an endpoint descriptor). Windows has the bad habit of remembering a device’s previous descriptors on the assumption that a device will never change its descriptors. To force Windows to use new descriptors, uninstall then physically remove and reattach the device from Windows Device Manager. Another option is to change the device descriptor’s product ID to make the device appear as a different device.


Unlike the other transfer types, control transfers have multiple stages: setup, (optional) data, and status. Devices must accept all error-free data packets that follow a Setup token packet and return ACK. If the device is in the middle of another control transfer and the host sends a new Setup packet, the device must abandon the first transfer and begin the new one. The data packet in the Setup stage contains important information firmware should completely decode (see Table 2).

Table 2: Device firmware should fully decode the data received in a control transfer’s Setup stage. (Source: USB Implementers Forum, Inc.)

The wLength field specifies how many bytes the host wants to receive. A device shouldn’t assume how much data the host wants but should check wLength and send no more than the requested number of bytes.

For example, a request for a configuration descriptor is actually a request for the configuration descriptor and all of its subordinate descriptors. But, in the first request for a device’s configuration descriptor, the host typically sets the wLength field to 9 to request only the configuration descriptor. The descriptor contains a wTotalLength value that holds the number of bytes in the configuration descriptor and its subordinate descriptors. The host then resends the request setting wLength to wTotalLength or a larger value (e.g., FFh). The device returns the requested descriptor set up to wTotalLength. (Don’t assume the host will do it this way. Always check wLength!)

Each Setup packet also has a bmRequestType field. This field specifies the data transfer direction (if any), whether the recipient is the device or an interface or endpoint, and whether the request is a standard USB request, a USB class request, or a vendor-defined request. Firmware should completely decode this field to correctly identify received requests.

A composite device has multiple interfaces that function independently. For example, a printer might have a printer interface, a mass-storage interface for storing files, and a vendor-specific interface to support vendor-defined capabilities. For requests targeted to an interface, the wIndex field typically specifies which interface applies to the request.


For interrupt endpoints, the endpoint descriptor contains a bInterval value that specifies the endpoint’s maximum latency. This value is the longest delay a host should use between transaction attempts.

A host can use the bInterval delay time or a shorter period. For example, if a full-speed In endpoint has a bInterval value of 10, the host can poll the endpoint every 1 to 10 ms. Host controllers typically use predictable values, but a design shouldn’t rely on transactions occurring more frequently than the bInterval value.

Also, the host controller reserves bandwidth for interrupt endpoints, but the host can’t send data until a class or vendor driver provides something to send. When an application requests data to be sent or received, the transfer’s first transaction may be delayed due to passing the request to the driver and scheduling the transfer.

Once the host controller has scheduled the transfer, any additional transaction attempts within the transfer should occur on time, as defined by the endpoint’s maximum latency. For this reason, sending a large data block in a single transfer with multiple transactions can be more efficient than using multiple transfers with a portion of the data in each transfer.


Most devices’ functions fit a defined USB class (e.g., mass storage, printer, audio, etc.). The USB-IF’s class specifications define protocols for devices in the classes.

For example, devices in the HID class must send and receive all data in data structures called reports. The supported report’s length and the meaning of its data (e.g., keypresses, mouse movements, etc.) are defined in a class-specific report descriptor.

If your HID-class device is sending data but the host application isn’t seeing the data, verify the number of bytes the device is sending matches the number of bytes in a defined report. The device should prepend a report-ID byte to the data only if the HID supports report IDs other than the zero default value.

In many devices, class specifications define class-specific requests or other requirements. For example, a mass storage device that uses the bulk-only protocol must provide a unique serial number in a string descriptor. Carefully read and heed any class specifications that apply to your device!

Many devices also support industry protocols to perform higher-level functions. Printers typically support one or more printer-control languages (e.g., PCL and Postscript). Mass-storage devices support SCSI commands to transfer data blocks and a file system (e.g., FAT32) to define a directory structure.

The higher-level industry protocols don’t depend on a particular hardware interface, so there is little about debugging them that is USB-specific. But, because these protocols can be complicated, example code for your device can be helpful.

In the end, much about debugging USB firmware is like debugging any hardware or software. A good understanding of how the communications should work provides a head start on writing good firmware and finding the source of any problems that may appear.

Jan Axelson is the author of USB Embedded Hosts, USB Complete, and Serial Port Complete. Jan’s PORTS web forum is available at www.lvr.com.


Jan Axelson’s Lakeview Research, “USB Development Tools: Protocol analyzers,” www.lvr.com/development_tools.htm#analyzers.

This article appears in Circuit Cellar 268 (November 2012).

CC268: The History of Embedded Tech

At the end of September 2012, an enthusiastic crew of electrical engineers and journalists (and significant others) traveled to Portsmouth, NH, from locations as far apart as San Luis Obispo, CA,  and Paris, France, to celebrate Circuit Cellar’s 25th anniversary. Attendees included Don Akkermans (Director, Elektor International Media), Steve Ciarcia (Founder, Circuit Cellar), the current magazine staff, and several well-known engineers, editors, and columnists. The event marked the beginning of the next chapter in the history of this long-revered publication. As you’d expect, contributors and staffers both reminisced about the past and shared ideas about its future. And in many instances, the conversations turned to the content in this issue, which was at that time entering the final phase of production. Why? We purposely designed this issue (and next month’s) to feature a diversity of content that would represent the breadth of coverage we’ve come to deliver during the past quarter century. A quick look at this issue’s topics gives you an idea of how far embedded technology has come. The topics also point to the fact that some of the most popular ’80s-era engineering concerns are as relevant as ever. Let’s review.

In the earliest issues of Circuit Cellar, home control was one of the hottest topics. Today, inventive DIY home control projects are highly coveted by professional engineers and newbies alike. On page 16, Scott Weber presents an interesting GPS-based time server for lighting control applications. An MCU extracts time from GPS data and transmits it to networked devices.

The time-broadcasting device includes a circuit board that’s attached to a GPS module. (Source: S. Weber, CC268)

Thiadmer Riemersma’s DIY automated component dispenser is a contemporary solution to a problem that has frustrated engineers for decades (p. 26). The MCU-based design simplifies component management and will be a welcome addition to any workbench.

The DIY automated component dispenser. (Source: T. Riemersma, CC268)

USB technology started becoming relevant in the mid-to-late 1990s, and since then has become the go-to connection option for designers and end users alike. Turn to page 30 for Jan Axelson’s  tips about debugging USB firmware. Axelson covers controller architectures and details devices such as the FTDI FT232R USB UART controller and Microchip Technology’s PIC18F4550 microcontroller.

Debugging USB firmware (Source: J. Axelson, CC268)

Electrical engineers have been trying to “control time” in various ways since the earliest innovators began studying and experimenting with electric charge. Contemporary timing control systems are implemented in a amazing ways. For instance, Richard Lord built a digital camera controller that enables him to photograph the movement of high-speed objects (p. 36).

Security and product reliability are topics that have been on the minds of engineers for decades. Whether you’re working on aerospace electronics or a compact embedded system for your workbench (p. 52), you’ll want to ensure your data is protected and that you’ve gone through the necessary steps to predict your project’s likely reliability (p. 60).

The issue’s last two articles detail how to use contemporary electronics to improve older mechanical systems. On page 64 George Martin presents a tachometer design you can implement immediately in a machine shop. And lastly, on page 70, Jeff Bachiochi wraps up his series “Mechanical Gyroscope Replacement.” The goal is to transmit reliable data to motor controllers. The photo below shows the Pololu MinIMU-9.

The Pololu MinIMU-9’s sensor axes are aligned with the mechanical gyro so the x and y output pitch and roll, respectively. (Source: J. Bachiochi, CC268)