3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

USB Indoor/Outdoor Thermometer (or, 'My first USB device')

Step 2Firmware

The firmware uses the CDC USB class to emulate a serial port. The device will show up as a virtual com port on a PC. The firmware is broken into three sections:

1. The USB driver takes care of enumerating the device on a PC and emulating a COM port.
2. A service routine alternately reads the temperature values and converts them to a readable format. Doing both of these operations at once caused the USB device to loose connection the PC (time hogging). Converting the floating point values to a string in the service cycle following the conversion cleared up the connectivity problem.*
3. Finally, a main routine receives bytes sent from PC and returns the requested measurements. Multiple measures are separated by a comma, lines are terminated with a null character (hex 0x00)
The demonstration firmware accepts the follow commands:
Hex value Returns
0x00 Indoors temperature (on-board sensor)
0x01 Outdoor temperature (external header)
0x02 Both temperatures (comma separated)

Temperature is calculated based on the 2.5 volt reference and the Microchip TC1047A offset and slope. Other temperature sensors may have different characteristics. The TC1047A datasheet is available here:

http://ww1.microchip.com/downloads/en/DeviceDoc/21498c.pdf

The firmware is written in MPLAB with the demonstration PIC C18 compiler.

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010014&part=SW006011

The actual USB firmware is provided by Microchip. The original environment is available here:

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en021631

To edit the firmware: extract the entire directory structure of the source to your root directory (c:\MCHPFSUSB). You can then load the workspace file in MPLAB.

*The float to string routine is a resource hog. To get around the connectivity problem the USB service routine is called at various points in the float2string routine. This would best be fixed by servicing the USB peripheral on an interrupt. I used the hack so that the firmware stayed as close to the reference version as possible.
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
128
Followers
30
Author:ian(DangerousPrototypes.com)