1. Three CY7C63001 Cypress USB Cont r oller devices (One pre-programmed windowed
controller on the CY3640 US B Therm om eter Demo board, and two spare devices (one
windowed and one OTP)
2. One Cypress USB Programmer from HI-LO Systems with a wall power adapter, a serial cable
and programming soft ware on a floppy disk
3. One CY3640 USB Starter Kit printed circuit board
4. One low-speed unshielded US B " A to B" Cable
5. One Cypress USB Starter Kit CD- ROM:
Software:
CYASM: Cypress USB controller assembler
USB Thermometer devic e assembly source code
USB Thermometer Wi ndows appli c ation program executable code
USB Thermometer devic e driver
Documentati on:
Cypress USB controller family datasheets
USB Thermometer User's Guide and Application Note: Designing a USB
Thermometer with the CY7C63001 USB Controller
USB Thermometer PC board l ay out and schematics
USB Specificati on v 1.0
Cypress CYASM assembler manual
Cypress USB-related application notes
Cypress databook
6. Printed documentation:
USB Starter Kit User's Guide
USB Starter Kit Application Note
Registrati on c ar d – Please fil l it out and drop it in the mail
Starting to use your Cypress USB thermometer is easy. Just follow these simpl e steps:
1. Insert the Cypress USB CD- ROM
The Cypress CD-ROM contains the Cypress USB Thermometer application and driv er files
you will need. Place it in t he CD- ROM drive you use to install y our software.
2. Run SETUP.EXE from the CD-ROM
This will install the Cypr ess USB Thermometer Windows application.
The Cypress USB Thermomet er applic ation is the user interface program which displ ay s the
temperature measurement received from the Cypress USB Thermometer devic e on the USB
Starter Kit PC board.
The SETUP.EXE is located in the root directory of the Starter Kit CD-ROM. After you have
run SETUP.EXE, the Cypress USB Thermometer Windows application will be properly
install ed in the def ault directory C:\Program Files\Thermometer or a direct or y selected by
you.
The setup program also i nstalls an entry in the Programs section of your Start menu.
The Cypress USB Thermomet er applic ation may be uninstalled by selecting it in the
“Add/Remov e Program s” section of the “Control Panel.”
3. Plug the A-end (flat connect or) of the USB cable into the USB port of your PC
4. Plug the B-end (square connect or) of the USB cable into the B-receptacle of the
CY3640 USB Starter Kit
The computer will notify you that it has found new hardware and is looking for a driver. If it
does not find a driver, it will then ask you to supply a driver.
5. Insert the Cypress USB CD- ROM (if p romp t ed to do so)
If your computer pr om pts you to suppl y a driver, make sure that your Cypress USB CD-ROM
is inserted into your c om puter’s CD-RO M drive.
Your computer will now automatically install the Cypress USB driver from the CD-ROM.
6. Run the Cypress USB Thermometer app li cat io n
When you want to run the Cypress USB Thermom eter application, use the “Programs” menu
and select the Cypress USB Thermometer entry. The computer will display a graph showing
the temperatur e r eading ov er time. Use the options described in the following sections to
control vari ous aspects of the USB thermometer.
: if you cannot get the thermometer to work, you may not be using the correct operating
C. Uninstalli n g the Cypr es s USB T her mometer application
If you want to remove the Cypress USB Therm om eter application from your system, it may be
uninstall ed by selecting Cypress USB Thermometer in the “Add/Remov e Program s” section of the
“Control Panel.”
D. The Cypress USB Thermometer Application Options
Changing the display st yle from conventional thermometer display to a history of
temperature
The Thermometer application will display either the current temper ature using a conventional
thermometer symbol or a histor y of t he temper ature recorded during the last 64 sample periods
(See
Figure C1
).
Conventional
Thermometer Display
Figure C1
To change the display style, click on the “Options” box in either the conventi onal thermometer
display or the temper ature history display. Checking the “Show Tim e Line” box will sel ect the
temperature history display. “Unchecking” the “Show Time Line” box will sel ec t t he c onv entional
thermometer displ ay . Click on the “OK” box to complete your selection. (see
Changing the maximum and minimum temperature value displayed
The Thermometer application can display temperatures between 0ºC and 70ºC. (32ºF and 158ºF)
The user may set the temperatur e r ange display on the Options screen by entering the desired
value in the appropriate “Temperature Limits” text box.
Changing the user’s name
The user may change the headi ng, which appear s at the top of the temperature display.
This is done on the Options screen by changing the text in the “User’s Name” text box.
Changing the display mod e from Centig rade to Fahrenheit
The Thermometer application can display temperature in either Centigrade or Fahrenheit.
The display mode is selected in the Options screen by selecting either the Fahrenheit or the
Centigrade radio buttons box.
Changing the time between temperature sample periods
The Thermometer application can sample the temperature at a variabl e rate determined by the
user.
The user sets the sample rat e on the Options screen by selec ting the appropriate options in the
“Sample Interv al” ar ea. Sam ple intervals may be chosen between one per second to one every
30 hours.
Simulating temperature measurements
The Temperatur e displ ay pr ogr am all ows you to simulate temperature readings instead of
actually measuring them.
You can select this by clic ki ng on the “US B Opti ons” box. The “USB Options” screen will be
displayed. (S ee
Figure C3
)
Checking the “Simulate Temperature” box will cause the thermomet er to enter a test mode in
which a series of random temper ature readings will be displayed.
Testing to see if a Cypress USB Thermo met er devi ce is present
If your Cypress USB Thermometer device is plugged in to the USB and you cannot get
temperature measurements, you may try to connect to it by clicking the “Check For Device”
button on the USB Options screen (See
Figure C3
). This screen is available by clicking the “USB
Options” button on t he Opti ons screen.
The text above the button will indicate whether the Thermometer application is connected to the
Cypress USB Thermometer device t hr ough the device driver. If it is, the “Check For Device”
button will be disabled.
Changing the brightness of the Enumerated LED on the Cypress USB Thermometer device
The brightness of the E num er ation LED on the Cypress USB Thermometer PC board may be set
to one of sixteen lev els.
The user can set the brightness level desired on the “US B Options” screen by changing the value
of the “LED Brightness” box ( S ee
Figure C3
). This screen is available by clicking the “USB
Options” button on t he Opti ons screen.
The values may be set from zero to fif teen, with z er o being the lowest setting.
Saving the current config uration of the Thermometer application
The user can choose to autom atically save the current configuration of the Therm om eter
applicati on when they ex it the program by checking the “Remember Settings” box. The
parameters saved inc lude:
Location on the desktop where the application screen will reside
•
User Name text
•
Centigrade or Fahrenheit mode
•
T em per ature history or conventional thermom eter display selection
The Cypress CY3640 USB Start er Kit incl udes a fully functional USB thermometer devic e, a
Windows95 thermometer application, and a USB Thermometer device driver. Together, these
components allow the user to m easure and display temperatures between 0ºC and 70ºC to an
accuracy of ±1ºC.
In addition to bei ng a useful US B device, Cypress has designed t he US B S tarter Kit to serve as
an easily customizable platform for USB device development using the Cy pr ess CY7C63X0X
family of USB contr oller s.
Features
The CY3640 has the following features:
The Cypress USB Controller is socketed i n a 20- pin socket
It may be removed, reprogrammed, and replaced for easy development of new assembly
code.
Cypress has supplied a bread board ar ea ( sea of holes)
This area will accept wir e wrap pi ns and wire wrap sockets. This area will make it easy to
develop additi onal logic on-board.
A connector for use with standard 40-pin flat-cable connectors has been prov ided.
All signals fr om the Cypress USB Controller, which are useful for the developm ent of exter nal
logic, are available at pins on the connector. The signal names are label ed on the t op lay er of
the board. Pin numbers on the c onnec tor are labeled on both the top and bottom layers of the
board to make it easy to wire to the connec tor.
An identical set of signal vias is placed adjacent to the connector for easy wiri ng to the
signals.
Connections to ext er nal power source
There is a location f or an ext er nal power supply c onnec tor, but the connector is not suppli ed
with the kit. Indiv idual labeled locations for Vss, USB Vbus (the positive supply of the USB ),
and External Vcc are provided on either side of the sea of holes.
LED indicators (Power and Enumeration)
The CY3640 includes two LEDs: a red and a green one. A s conf igured when the CY3640 is
shipped from the f actor y, the LEDs are used to indicate that power is applied and that the
USB host has enumerated t he Cy pr ess USB Thermometer device, respectively.
The anode of each LED is connected to the USB Vbus (positive supply) through a current
limiting resistor . The cathode of each device is connected to three places to allow you to
reconfigure them for your own purposes: a j um per , a pin on the 40-pin connector, and a hole
for installi ng a wir e wrap pi n.
The Power LED
The Power LED (as shipped from Cypress) is used t o indicate that power (Vbus) from the
USB has been applied. It is connected through a jumper (JP1) and a current limiting resistor
(R4) directl y between Vbus and Vss, and will be lit whenever power is applied through the
USB. The user may remove JP1 if desired.
The cathode of thi s LED is also connected to a pin on the 40- pin c onnec tor (pin 8) and to an
adjacent hol e that may be used to install a wire wrap pin. This allows the user to remove the
factory-installed jumper to Vss and use the LED for their own purposes.
Although it may be convenient to know when the USB i s appl yi ng power, dur ing
Note:
development. The f act that JP1 is left c onnec ted to Vss makes the dev ic e not strictly
compatible wit h the USB specification, because it will draw approxim ately 20 mA whenever it
is connected. T he USB specification limits power prior to the device being configured to 500
µA.
The Enumeration LED
The Enumeration LED ( as shipped f r om Cy pr ess) is used to i ndic ate that the USB
Thermometer dev ic e has been enumerated. The cathode of the LED is connected to P13
through a jumper (JP2) which controls its path to Vss.
The cathode of thi s LED is also connected to a pin on the 40- pin c onnec tor (pin 10) and to an
adjacent hol e that may be used to install a wire wrap pin. This allows the user to remove the
jumper to P13 and use the LED for their own purposes.
The switch (SW1)
SW1 (as shipped) on the Cypress USB Thermometer is used to select whether the
Thermometer Windows application displays the temperatur e in Centigrade or Fahrenheit. It is
a momentary SPST.
One pole of the switch is connected to Vss. The other pole is connected to Vcc (Vbus)
through R4, to a pin on the 40-pin connector (pin 6), to an adjacent hole that may be used for
installi ng a wire wrap pin, as well as to the GPIO P 12 of t he USB controller through a jumper
JP3. This allows the user to remove the jumper to P12 and use SW1 for their own purposes.
The breadboard area
Sea of holes
Cypress has provided an area that will ac c ept wire wrap pi ns and wire wrap sockets for
development of l ogic and functionality on the board.
USB Vbus (Vcc) and Vss connections
We have provided loc ations for connect ing power and ground from the USB to your bread
board area. These locations will ac c ept wire wrap pins.
External Vcc connect ions
If you need to power your breadboard with an external supply, a connector site (P 1) i s
supplied for t hat purpose. Two capacitor locations are also provi ded adjac ent to the
connector for by pass. C6 i s a bul k bypass and C7 is f or high frequenc y . These capacitors are
not populated wit h the CY3640 as shipped, and y ou shoul d use components appropriate to
your needs.
The External Vcc supply is brought to the bread board area and connected to three locations
labeled (oddly enough) Ext. Vcc. You may insert wire wrap pins in these locations to rout e to
your breadboard area.
The temperatur e sensor (U2)
The temperatur e sensor dev ic e is socketed so i t can be removed if you need to use the
associated pins on the Cy pr ess USB Contr oller for other logic on your breadboard.
Ferrite bead locati ons
If noise is a problem in your envir onm ent, locations for two ferrite beads (FB1 and FB2) have
been provided: one f or the V cc supply from the USB and one for the Ground return to the
USB. These beads should not be nec essarily and are provided for exceptional noisy
environments.
The locations are shorted by a trac e on the bottom layer of the PC board. If you desire to use
ferrite beads, you should c ut the traces and install beads suitable to your needs.
Other items of interest
Bulk capacit or bl eeder r esi stor ( R5)
A resistor is provided to bleed off t he c har ge stor ed on the bulk capacitor . This is provided to
insure that charge is removed fr om the bulk c apaci tor and hence the board logic, within a
short period aft er the devic e is unpl ugged from the USB.
USB connector
A “B” receptacl e has been provided on the board so a detachable A/B cable can be used with
the device.
A footprint for an in-li ne c onnec tor (P2) to a permanently attached USB cable has been
provided if you need to have a non- r em ov able US B cable.
F. Changing the functionality of the Cypress CY3640 USB
Starter Kit
The CY3640 USB Starter Kit is designed t o allow you to add or change its functionality in a
variety of ways in order to meet your needs.
You may easily:
Add logic to the board itself
•
Change t he functionality of the on-board LEDs and the switc h
•
Change t he pr ogr am stored inside the Cypress USB Controller
•
Use an ex ternal power source
•
T ak e si gnals off of or bring signals onto t he boar d
•
Changing the program in your devi ce
You can write your own code for y our Cypress USB Contr oller.
The easiest way is to use the code provided as a base and change only those parts which are
specific to your product.
The routines you will need to focus your changes on are in the file “USB.ASM”. They are
Main
•
SetConfig
•
1024usec IRQ handling
•
Vendor S pec ific Setup Commands
•
Assembling the code for your device
You can assemble your code for the Cypress USB Controller with CYASM, Cypress’ assembler.
See the Cypress CYASM documentation. Both CYASM and its documentation are included in the
USB Starter Kit CD-ROM.
Programming your device
After you have written and assembled your own USB controller firmware code, you can program
a new USB controller using the device programmer contained in the Cypress USB Starter Ki t.
Please note that the devic e pr ogr ammer only supports Cypress CY7C63X0X family of low-speed
USB controll er s, nam ely, CY 7C63000, CY7C63001, CY7C63100, CY7C63101, CY7C63200 and
CY7C63201. Its component s i nc lude:
a device programmer with a 32-pin DIP adapter
•
a f loppy disk with the programming software
•
a 9-pin serial cable
•
a wall power adapter
•
To program a new USB controller simply follow these steps:
Connect the device programmer to your PC's serial port using the serial cable
•
T ur n it on by plugging the wall power adapter
•
Copy the programming software executabl e on the fl oppy disk t o your PC' s hard disk and
•
run it. At startup the software will detect the presence of the programmer connected to
the serial port and perform self-test
I nsert y our Cy pr ess USB cont r oller into the DIP adapter and choose the appropriat e
•
commands from the progr ammer software
The programming sof tware is actually quite simple; however, it provides all the necessary
functions to pr ogr am a USB contr oller, such as blank check, read, program, verify and security
fuse programming. The soft ware i s abl e to read and write .BIN and .HEX format fil es. To erase
the code programmed in t he windowed USB controller devices, use regular UV EPROM erasers
available on the market .
Adding yo ur own logic
See “Appendix D” for a description of the items that you may change to modify your design.
U1Cypress CY7C63001 USB controller
U2Dallas Semiconductor DS1623 temperature sensor
P12-pin header, polarized, 0.1" center, right angle. Not populated.
P25-pin header, polarized, 0.1" center, vertical. Not populated.
SW1SPST, Momentary switch
DS120 mA, 2.2 Vdc Red LED, 0.1" center, 0.02 leads
DS220 mA, 2.2 Vdc Green LED, 0.1" center , 0. 02 leads
X16 MHz c er ami c resonator
JP12-pin header, 0. 1" cent er , wit h shunt
JP22-pin header, 0. 1" cent er , wit h shunt
JP33-pin header, 0. 1" cent er , wit h shunt
R17.5K Ohm, 1%, 1/8 W, carbon film resistor
R2150 Ohm, 10%, 1/8 W, carbon film resistor
R3 150 Ohm, 10%, 1/8 W, carbon film r esi stor
R410K Ohm, 10%, 1/8 W, carbon film resi stor
R550K Ohm, 10%, 1/8 W, carbon film resi stor
C10.1
C24.7
C30.1
C50.1
C6External Vcc Bulk capaci tor. Not populated
C7External Vcc HF capaci tor. Not populated
J140-pin, boxed header, straight, 0.1" x 0.1" center
J2USB "B" connector
FB1Ferrite bead. Not populated
FB2Ferrite bead. Not populated
F, 5%, Low ESL, 50 Vdc capacitor
µ
F, 10%, Tantalum, 25 Vdc capacitor
µ
F, 5%, Low ESL, 50 Vdc capacitor
µ
F, 5%, Low ESL, 50 Vdc capacitor
µ
The USB Starter Kit demo board layout and schematic are shown on the next two pages.
;; USB_20.ASM
;*******************************************************************************
;
; *******************************************************************************
;
; Target:
; Cypress 7C63000 8bit RISC microcontroller with 1.5Mbps USB serial interface
; Dallas 1623: High Resolution Temperature Measurement Sensor
; Overview
; There are four main sub-systems: USB, Thermometer, LED, and Button.
; The system is started in the main() routine at reset. This routine
; initializes the USB variables, the IO ports, the Thermometer logic,
; and the data space. All USB communication occurs on an interrupt basis.
; First, Main() loops waiting for a USB reset.
; After receiving a USB reset, Main() enables the Endpoint 0 interrupt and
; loops waiting for Setups which ultimately will the result in the device
; being enumerated.
; Once the device has been enumerated on the USB, the main loop waits 10ms,
; polls the thermometer, updates the LED, and initializes end point 1 if
; appropriate.
; USB
; Endpoint 0 is used to support Control Transfers and vendor specific
; requests. End point 1 is also available for interrupt requests handling
; small packets of data (good for mouse, joystick, keyboard, thermometer, etc.).
; However, it is not used in this code.
; Each control transfer interrupts the processor and the subsequent routines
; services it.
; Thermometer
; A simple 9-bit temperature value is read from the thermometer every 10ms. At
; startup, the thermometer is initialized and placed into a continuous mode
; storing internally the current temperature. Thereafter, the temperature is
; read synchronously and returned into the USB end point one FIFO buffer.
; LED
; The LED is controlled by P13. When P13 goes low, the LED is turned on.
; The LED indicates the status of the USB connection. Once this device has
; "logically" been enumerated and configured to run on the serial bus, the LED
; is illuminated. The LED supports adjusting the brightness intensity by first
; setting the new brightens value (default: FFh = High) and then setting the
; brightness update field.
; Button
; A momentary push button is used to indicate that the application's
; Celsius/Fahrenheit display mode should be toggled.
; With each GetTemperature request, a value is sent indicating whether the
; button has been pushed.
; The GPIO interrupt is triggered by pushing the button causing its
; level to change from High to Low. A 100ms debounce was added to control the
; erroneous re-occurrence of this logical state change for a period. The
; 1024ms timer decrements the debounce to zero, re-enabling the button if at the
; end of the time out it has returned High.
;
; Port Usage
; P0.0 - Thermometer Data (input/output)
; .1 - Thermometer Clock (output)
; .2 - Thermometer Reset (output)
; .3 ; .4 ; .5 ; .6 ; .7 ; P1.0 ; .1 -
; Global Interrupt
gbSysInterruptMask :equ 20h ; Holds the current interrupt mask
; System tickers
gbSysTick1024us :equ 22h ; # of 1mSec ticks
gbSysTick1024usRoll :equ 24h ; # of 256mSec ticks
; USB management data
gbUSBValidRqsts :equ 25h ; Count of USB recognized requests
; Used during debug
gbUSBSendSequence :equ 26h ; Buffer send data 0/1 line
gbUSBSendBytes :equ 27h ; Buffer bytes left to send
gbUSBSendBuffer :equ 28h ; Offset into current buffer
gbSuspendCount :equ 30h ; # of msec bus has been IDLE
; General
gbSysEnumerated :equ 29h ; Device is enumerated
; LED management
gbLEDBrightnessUpdate :equ 2Bh ; Semaphore to reset brightness
gbLEDBrightness :equ 2Ch ; Current brightness
LED_ON :equ 08h ; P13 is used to indicate Enumeration
; Button management
gbButtonDebounce :equ 2Dh ; Debounce count down value
gbButtonPushed :equ 7Ah ; USBEndP1FIFO +2 (toggles if button was clicked)
Button_Pin :equ 04h ; Pin the switch is on, P12
;*************************************************
SysUnUsed:
push a
mov a,[gbSysInterruptMask]
ipret SysInterrupt
;//$PAGE
;*******************************************************************************
; main()
; @func Entry point after PowerOn, WatchDog timeout or WakeUp from sleeping.
; @comm Never returns
;*******************************************************************************
main:
; This portion of Main is only executed after a RESET (Power-On or USB)
; Setup data stack in high order RAM, just below EP0 FIFO
; It will grow down from here
mov a,70h ; USBEndP0FIFO
swap a,dsp
; Initialize both Ports high
mov a,FFh
iowr SysPort0 ; Port 0 Data reg
iowr SysPort1 ; Port 1 Data reg
; 1 on P13 is needed to make sure enumerate LED is off
; 1 on any port that needs to be an input
; Enable Pullups (0=enable)
mov a,0
iowr SysPort0PullUp
mov a,Button_Pin
iowr SysPort1PullUp ; 1 on P12 is needed to make sure GPIO interrupt
; occurs on LOW to HIGH transistion. This
; disables it's pull up
; Enable or disable interrupts on appropriate pins
mov a,0
iowr SysPort0IntEnable ; All pins irq's are disabled on Port 0
mov a,Button_Pin
iowr SysPort1IntEnable ; Enable P12, the button pin.
; No interrupts will occur until the device
; is enumerated. Then GPIO's will be enabled and
; we will allow P12 to generate interrupts
; Initialize USB variables
mov a,0
mov [gbUSBValidRqsts],a ; No valid requests yet
mov [gbUSBSendSequence],a ; Start with a 0
mov [gbSysEnumerated],a ; Not enumerated
; Initialize LED
mov a,1 ; flag it for an update
mov [gbLEDBrightnessUpdate],a
mov a,FFh ; set for maximum brightness
mov [gbLEDBrightness],a
; Initialized Button
mov a,0
mov [gbButtonPushed],a ; Initial state of 0, no button pushed
; Initialize variables
mov a,0
mov [gbUSBSendBytes],a ; No bytes to send in FIFO buffers
mov [gbSuspendCount],a ; Reset bus activity to 0
mov [gbButtonDebounce],a ; We are not debouncing
; Set interrupt mask
mov a,SysIntTimer1024us | SysIntUSBEndP0
iord USBControl ; Read the USB Status and Control Reg
and a,01h ; Check bit 0
cmp a,0h
jz Inc_Counter ; Hmm! No activity. Branch and keep track of it.
iord USBControl ; Ah! There was activity,
; clear the bus activity bit
and a,0feh
iowr USBControl
mov a,0 ; Clear the suspend counter
mov [gbSuspendCount],a
jmp Suspend_End
Inc_Counter: ; Monitor the IDLE count
mov a,[gbSuspendCount] ; Get # of mSec we have been IDLE
inc a ; Increment the count
mov [gbSuspendCount],a
cmp a,03h ; Has it been 3msec yet?
jnz Suspend_End ; Not yet, branch
mov a,0h ; Yes, clear the suspend counter
mov [gbSuspendCount],a
iord SysStatus
or a,08h ; Set the suspend bit to cause a suspend
iowr SysStatus ; We will enter the suspend state during
; the next instruction.
Suspend_End:
; Increment the 1024 usec counter and check for rollover
inc [gbSysTick1024us]
jnz STimerNo1024usRoll ; No
STimerNo1024usRoll:
; Are we counting down a button debounce
mov a,0
cmp a,[gbButtonDebounce]
jz STimerNoDebounce ; Not debouncing, branch
; Yes, we're debouncing. Let's see if we are timed out.
dec [gbButtonDebounce]
mov a,0
cmp a,[gbButtonDebounce]
; has debounce timed out?
jnz STimerNoDebounce ; No, still debouncing, branch.
; The debounce timer has timed out
; check if the button pin is at a 1. If not, the button is either still
; bouncing or still pushed
iord SysPort1 ; check the port the button is on
and a,Button_Pin ; check the pin
jnz STimerDebounceOver ; branch if it is not pushed ; mrr
; Reset debounce since the button is not yet released or is bouncing
mov a,100
mov [gbButtonDebounce],a
jnz STimerNoDebounce ; continue waiting for debounce to end
STimerDebounceOver:
; it's really ready!
; Toggle the button state flag to let the Windows app know that
; the button has been pushed.
mov a,1
xor [gbButtonPushed],a
; Debounce must be over
STimerNoDebounce:
; Enable interrupts and return
mov a,[gbSysInterruptMask]
;//$PAGE
;********************************************************
; SysGPIOEvent()
; @func General purpose port event
; @comm Which pin?
;********************************************************
SysGPIOEvent:
; Save accumulator
push a
; Reset debounce any time we are here
mov a,100
mov [gbButtonDebounce],a
SysGPIOButtonDebouncing:
; Enable interrupts and return
mov a,[gbSysInterruptMask]
ipret SysInterrupt
;*******************************************************************************
;
; This section of code responds to activity on End Point 0 and determines
; what needs to be done.
;
;*******************************************************************************
;//$PAGE
;********************************************************
; USBEndPoint0Event()
; @func End Point zero USB event.
; @comm Default end point.
;********************************************************
USBEndPoint0Event:
; This code checks to see what type of packet was received
; (Setup, Out, or In) and jumps to the correct routine to decode the
; specifics. After the code to which the jump points is through, it jumps
; back to USBEventEP0End.
; Save accumulator
push a
; Is this a SETUP packet?
iord USBEndP0RxStatus
and a,USBEndP0RxSetup ; Check the setup bit
jnz USBEventEP0_SETUP ; Yes it's a setup, branch
; Not a setup, is it an OUT packet?
;iord USBEndP0RxStatus
;and a,USBEndP0RxOut
;jnz USBEventEP0_OUT
; Not an OUT packet, is it an IN packet?
;iord USBEndP0RxStatus
;and a,USBEndP0RxIn
;jnz USBEventEP0_IN
USBEventEP0_IN:
USBEventEP0_OUT:
USBEventEP0End:
; OK. We're done with the packet.
; Let's enable interrupts and return
mov a,[gbSysInterruptMask]
ipret SysInterrupt ; done with EP0 irq service routine
; Stall any subsequent IN's or OUT's until the
; stall bit (bit 5) is cleard by an I/O write to
; the USB End Point 0 TX Configuration Register (0x10)
; or any SETUP is received.
iord USBEndP0TxConfig
or a,USBEndP0TxStall
iowr USBEndP0TxConfig
; OK. We've set the stall condition for Endpoint 0.
; Now let's complete the routine.
jmp USBEventEP0End
;*******************************************************************************
;
; We know we have received a Setup token. Now we need to parse it to
; determine what command it is.
;
;*******************************************************************************
;//$PAGE
;*******************************************************************************
; USBEventEP0_SETUP()
; @func End point event SETUP packet handler.
; @devnote Runs in interrupt enabled context.
;********************************************************
USBEventEP0_SETUP:
; Well, we have a SETUP packet. Let's find out what to do.
mov A,[gbSysInterruptMask]
iowr SysInterrupt
; If we are here and are and we are processing a previous Setup,
; we need to abort the processing of the previous Setup
mov a,0 ; Clear any indication that we have bytes left to transfer
mov [gbUSBSendBytes],a
; Clear EP0 RxReg (including the Setup flag)
; The Data toggle bit remains unchanged, however.
mov a,0
iowr USBEndP0RxStatus
; Vendor specific commands
USBEventEP0SetupTargetVendorIN_OUT:
; Check request (IN packet OK, OUT packet ERR)
mov a,[USBEndP0FIFO_0]
and a,USBRqstTypeVendor | USBRqstTargetEndPoint | USBRqstTypeDirection
cmp a,USBRqstTypeVendor | USBRqstTargetEndPoint | USBRqstTypeDirection
jz USBEventEP0VendorRqst
; Unsupported request !!!
jmp USBEventEP0Stall ; Oops! We don't support whatever
; request was made.
;//$PAGE
;********************************************************
; USBEventEP0SetupIsSet()
; @func End point event SETUP to set address.
; @devnote Runs in interrupt enabled context.
;********************************************************
USBEventEP0SetupIsSetAddress:
; Unsupported get request !!!
jmp USBEventEP0Stall ; No
;********************************************************
; USBEventEP0SetupSetAddress()
; @func End point zero event SETUP to set address.
; @devnote Runs in interrupt enabled context.
; @comm
; The status token of the SetAddress is an IN. So, we send status manually.
;********************************************************
USBEventEP0SetupSetAddress:
; Send ACK
call USBSendACK
; Now that we have been acknowleged, we actually set the address.
; This is different from all other commands which execute first
; and then acknowlege (_________________)
; Remember this
inc [gbUSBValidRqsts]
; Set Address
mov a,[USBRqstWordValueLo]
iowr USBDeviceAddress
; USBEventEP0SetupSetConfig()
; @func End point zero event SETUP to Set Configuration.
; @devnote Runs in interrupt enabled context.
; 1
; set enumerated (gbSysEnumerated) state,
; enable GPIO (and EP1, if appropriate)
; Enable P0 and P1
; 0
; Reset enumerated (gbSysEnumerated) state,
; Turn off LED
; Reset variables
; Disable GPIO and EP1
; Disable dallas chip and P0 and P1
;********************************************************
USBEventEP0SetupSetConfig:
; Enumerated !
mov a,01h
mov [gbSysEnumerated],a
; Initialize thermometer
call ThermInitialize
; Enable button interrupt on port 1.
; Actually, this has already been done in main().
mov a,04h
iowr SysPort1IntEnable
;//$PAGE
;********************************************************
; USBEventEP0SetupGetDescriptor()
; @func End point zero event SETUP to Get Descriptor.
; @devnote Runs in interrupt enabled context.
;********************************************************
USBEventEP0SetupGetDescriptor:
; Get descriptor type
mov a,[USBRqstWordValueHi]
USBEventEP0SetupGetDescriptorDevice:
; Device Descriptor?
cmp a,USBDescriptorTypeDevice
jnz USBEventEP0SetupGetDescriptorConfig ; No
USBEventEP0SetupGetDescriptorEnd:
; Unsupported Get request !!!
jmp USBEventEP0Stall
;//$PAGE
;********************************************************
; USBSendDescriptorCheckLength()
; @func Check and update send length for Get Descriptor
; requests on end point 0.
; @parm BYTE | gbUSBSendBytes | Number of bytes to send.
;********************************************************
USBSendDescriptorCheckLength:
;//$PAGE
;********************************************************
; USBSendROMBuffer()
; @func Send a number of ROM bytes on end point 0.
; @parm BYTE | gbUSBSendBytes | Number of bytes to send.
; @parm BYTE | gbUSBSendBuffer | Offset from ROM base
; of data to send.
; @comm assumes IN packets are ignored in the interrupt routine
; @devnote Enables interrupts
; Save bytes left
sub a,08h
mov [gbUSBSendBytes],a
jmp USendROMBufferLoop
USendROMBufferLoopDone:
; Send last 8 or less bytes
call _USBSendROMBuffer
USendROMBufferLoopExit:
ret
;//$PAGE
;********************************************************
; _USBSendROMBuffer()
; @func Buffer and inialize USB send of up
; to 8 bytes of ROM data on end point 0.
; @comm affects gbUSBSendBytes & gbUSBSendBuffer
;********************************************************
_USBSendROMBuffer:
; Send bytes
push x
pop a
or a,[gbUSBSendSequence]
or a,USBEndP0TxRespond
iowr USBEndP0TxConfig
; The FIFO is loaded, go and wait untill it's read
call USBSendWaitForComplete
_USendROMBufferEnd:
; Restore and exit
pop x
ret
;//$PAGE
;********************************************************
; USBSendACK()
; func Respond to a "USB Status In" with a zero byte buffer with
; Sequence field set) on end point 0.
; Called by SetAddress and SetConfig commands
;********************************************************
USBSendACK:
; Status response to Status In is to send a zero byte packet
mov a,USBEndP0TxRespond | USBEndP0TxSequence
iowr USBEndP0TxConfig
; Wait for send complete
jmp USBSendWaitForComplete
;********************************************************
; USBSendWaitForComplete()
; @func Wait for send to complete on end point 0.
;********************************************************
; At some point, either the 0 data will be ACK'd or a SETUP
; will come in.
; Either event will cause the "Enable Respond
; to In Packets" to be reset, and we will fall out of the loop.
; In either case, an EP0 IRQ will be generated (5.9.2.2 in Cyp
; device spec) if EP0 irq is enabled.
USBSendWaitForComplete:
; Poll the send complete bit
; This will be reset when the data has been sent to the host
; and the host has ACK's, or the host has sent another SETUP
; which should terminate this activity in any case.
iord USBEndP0TxConfig
and a,USBEndP0TxRespond
jz USBSendWaitComplete
; Check for OUT packet cancelling send. A STATUS OUT should
; terminate any pending IN's. A Setup could also set the Out bit.
iord USBEndP0RxStatus
and a,USBEndP0RxOut
jnz USBSendWaitComplete ; Cancelled
; Keep waiting
jmp USBSendWaitForComplete
USBSendWaitComplete:
ret
;//$PAGE
;********************************************************
; USBEventEP0VendorRqst()
; @func Vendor request on end point zero.
; @devnote Runs in interrupt disabled context.
;********************************************************
USBEventEP0VendorRqst:
; Save it
push x
; Check Protocol
mov a,[USBEndP0FIFO_1]
USBEventEP0VendorRqstPing:
cmp a,0h
jnz USBEventEP0VendorRqstReadROM ; No
; Auto ACK OUT packet
mov a,USBControlAckStatusData
iowr USBControl
; Send bytes as Data1
mov a,8
or a,USBEndP0TxSequence
or a,USBEndP0TxRespond
iowr USBEndP0TxConfig
;call USBSendWaitForComplete
; Restore it
pop x
; Return
jmp USBEventEP0End
;*****************************
;//$PAGE
include "ds1620a.asm"
;*****************************
;********************************************************
; SysDelayMS()
; @func Delay some number of milliseconds.
; @parm register | A | Number of milliseconds (0=65536).
; @comm Protects A and X registers.
;********************************************************
SysDelayMS:
; Save em'
push a
push x
SysDelayMSLoop:
; Save count
push a
; Delay 1ms = 10 * 100us
mov a,10
SysDelayMSLoopDelay:
; Save it
push a
; Delay 100us
mov a,100
call SysDelay
; Done?
pop a
dec a
jnz SysDelayMSLoopDelay
; Done?
pop a
dec a
jnz SysDelayMSLoop
; Restore em'
pop x
pop a
ret
;********************************************************
; SysDelay()
; @func Delay some number of microseconds.
; @parm register | A | Number of microseconds (0=65536).
; @comm Protects A and X registers.
;********************************************************
SysDelay:
;********************************************************
; Data Segment (ROM)
;********************************************************
USBSendROMBufferBase:
USBDeviceDescription:
db 12h ; Length
db 01h ; Type (1=device)
db 00h,01h ; Complies to USB Spec. v1.00
db 00h ; Class code (0=??)
db 00h ; SubClass code (0=??)
db 00h ; Protocol (0=none)(9.6.1)
db 08h ; Max. packet size for port0
db B4h,04h ; Vendor ID: (0x4B4=Cypress)
db 02h,00h ; Product ID (0x02=USB Thermometer)
db 09h,00h ; Device release v0.90
db 01h ; Manufacturer string descriptor index (0=none)
db 02h ; Product string descriptor index (0=none)
db 00h ; Serial number string descriptor index (0=none)
db 01h ; Number of possible configurations
USBDeviceDescriptionEnd:
;*************************************************
;
USBConfigurationDescription:
db 09h ; Length
db 02h ; Type (2=config)
db 19h,00h ; Total data length (1 config,1 interface,1 endpoints)
db 01h ; Interface supported (1=???)
db 01h ; Configuration value (1=???)
db 04h ; Confituration string descriptor index (0=none)
db 80h ; Configuration (80h=Bus powered)
db 32h ; Maximum power consumption in 2mA units
USBConfigurationDescriptionEnd:
;
USBInterfaceDescription:
db 09h ; Length
db 04h ; Type (4=interface)
db 00h ; Number of interfaces (0 based)
db 00h ; Alternate settings
db 01h ; Number of endpoints (1 based) (9.6.3)
db 00h ; Class code (0=non-specified,1=kb,2=mouse,3=joystick ???)
db 00h ; Subclass code (0=???)
db 00h ; Protocol code (0=non-specified)
db 05h ; Interface string index (0=non-specified, 1,2,3,...)
USBInterfaceDescriptionEnd:
;*************************************************
; Never used for EP0
USBEndPointDescriptionInt:
db 07h ; Length
db 05h ; Type (5=endpoint)
db 81h ; Address (EP#=1 | [0x80=IN, 0=OUT])
db 03h ; Attribute (0=control,1=isochronous,2=bulk,3=interrupt)
db 08h,00h ; Max packet size
db 0Ah ; Interval (10 ms)
USBEndPointDescriptionIntEnd:
;*************************************************
;
USBStringLanguageDescription:
db 04h ; Length
db 03h ; Type (3=string)
db 09h ; Language: English
db 01h ; Sub-language: US
USBStringDescription1:
db 10h ; Length
db 03h ; Type (3=string)
dsu "Cypress"
USBStringDescription2:
db 18h ; Length
db 03h ; Type (3=string)
dsu "Thermometer"
USBStringDescription3:
; If a SN is used, this must be unique
; for every device or the device may
; not enumerate properly
USBStringDescription4:
db 20h ; Length
db 03h ; Type (3=string)
dsu "Get Temperature"
USBStringDescription5:
db 3Ch ; Length
db 03h ; Type (3=string)
dsu "EndPoint1 10ms Interrupt Pipe"
;*******************************************************************************
;
; M8 - 8bit microprocessor
; registers: accumulator 'acc'
; index 'x'
; stack pointer 'dsp'
; program SP 'psp'
; program counter 'pc' 16 bits (14 bit addressing)
; PC low 'pcl'
; PC high 'pch'
; When PC is pushed on stack
; carry flag is stored in bit 14
; zero flag is stored in bit 15
;
; Program ROM 4096 bytes in 256 byte pages
; Program RAM 128 bytes
; Processor PORTs contain 16k-ohm resistor (pull-up and slew control)
;
; After reset:
; Port 0 and Port 1 are set high
;
;
;*******************************************************************************
; USB port control
USBControl :equ 13h ; Status/Control register
USBControlBusActive :equ 01h ; 1=active, write 0 and watch if bus dies
USBControlResume :equ 02h ; set transmitter to k state sending resume to
host ???
USBControlReserve2 :equ 04h
USBControlAckStatusData :equ 08h ; Auto ACK Data1 SETUP OUT data packets
USBControlAckOutData :equ 10h ; Auto ACK Data1 OUT data packets
USBControlReserve5 :equ 20h
USBControlReserve6 :equ 40h
USBControlReserve7 :equ 80h
USBEndP0RxStatus :equ 14h ; Port0 receive status
USBEndP0RxSetup :equ 01h ; 1=setup token received (must be cleared to
; Set mode
mov a,[gbThermPortValue]
and a,~(ThermControlOneShot | ThermControlCPUUse)
or a,ThermControlCPUUse | 08h ; set reserved bit
mov [gbThermPortValue],a
; Write it out
mov a,ThermConfigWrite
call ThermPortWrite
; ThermReset =1;
or a,ThermReset
mov [gbThermPortMirror],a
iowr ThermPort
ret
;*******************************************************************************
; ThermPortResetLow()
; @func .
;*******************************************************************************
ThermPortResetLow:
; ThermReset =0;
mov a,[gbThermPortMirror]
and a,~ThermReset
iowr ThermPort
ret
;*******************************************************************************
; ThermWaitForDone()
; @func Wait for indication of temperature conversion complete.
;*******************************************************************************
ThermWaitForDone:
; Test flag
mov a,[gbThermPortValue]
and a,ThermControlDone
jz ThermWaitForDone
ret
;*******************************************************************************
; ThermPortWrite()
; @func Write protocol byte and value byte.
; @parm byte | A | Protocol to send.
call ThermPortResetHigh
call ThermPortProtocolWrite
call ThermPortWrite8Bits
call ThermPortResetLow
ret
;*******************************************************************************
; ThermPortRead()
; @func Write protocol byte and read value byte into gbThermPortValue.
; @parm byte | A | Protocol to send.
;*******************************************************************************
ThermPortRead:
; Read in data pin and check for 0 or 1
iord ThermPort
and a,ThermData
jnz ThermPortTempReadValue1
ThermPortTempReadValue0:
jmp ThermPortTempReadClock
ThermPortTempReadValue1:
; Use bitmask
push x
pop a
or [gbThermTempRead],a
;jmp ThermPortTempReadClock ; redundant, but good practice
; Next bit in mask
push x
pop a
asl a
push a
pop x
;*********************************************
; Finished?
pop a
dec a
jnz ThermPortTempReadLoop
;*********************************************
; Last bit
;*********************************************
; Tri-state data pin for input
mov a,[gbThermPortMirror]
or a,ThermData
iowr ThermPort
; Read in data pin and check for 0 or 1
iord ThermPort
and a,ThermData
jnz ThermPortTempReadLastValue1
ThermPortTempReadLastValue0:
jmp ThermPortTempReadLastClock
ThermPortTempReadLastValue1:
; Use bitmask
mov a,1
mov [gbThermTempRead2],a
;jmp ThermPortTempReadLastClock ; redundant, but good practice
; Read in data pin and check for 0 or 1
iord ThermPort
and a,ThermData
jnz ThermPortReadValue1
ThermPortReadValue0:
jmp ThermPortReadClock
ThermPortReadValue1:
; Use bitmask
push x
pop a
or [gbThermPortValue],a
;jmp ThermPortReadClock ; redundant, but good practice
The Cypress driver i s accessed through t he Windows DeviceIoControl() API. The f ollowing c ode
and table illustr ates its use.
Type OVERLAPPED
Internal As Long
InternalHigh As Long
offset As Long
OffsetHigh As Long
hEvent As Long
End Type
Public gOverlapped As OVERLAPPED
Public hgDrvrHnd As LONG
Dim lIn as long, lInSize as long, lOut as long, lOutSize as long, lSize as long
Dim ltemp as long
FunctionValuelInlOutMSBLSBMSBLSB
Set LED Brightness
Read Thermom et er
Read Port
Write Port
Read RAM
Write RAM
Read ROM
0Eh21NANABrightness 0EhNANANAStatus
0Bh13NAButtonTemp0BhButton SignTemp Status
014h22NANAPort014hNANAValue Status
015h31NAVal uePort015hNANANAStatus
016h22NANAAddress016hNANAValue Status
017h31NAVal ueAddress017hNANANAStatus
018h32NAIndexNA018hNANAValue Stat us
Obtaining the lat est version of the USB specification
You may obtain the current v er si on of t he USB Specification (Revision 1.0) on the Cypress CDROM. You may also obtain updates to t he US B specification and other USB information and
documents from the USB web site (http://www.usb.org).
Obtaining the lat est assembly code for the Cypress USB Thermometer
You may obtain the lat est v er si on of the assembl y c ode for the Cypress USB Thermom eter from
the Cypress web site (http://www.cypress.com).
Obtaining the lat est Cypress US B Th ermometer driver
You may obtain the lat est v er si on of the Cypress USB Thermometer application for the Cypress
USB Thermometer from the Cypr ess web site (htt p://www.cypress.com).
Obtaining the lat est Cypress US B Th ermometer application
You may obtain the lat est v er si on of the driver for the Cy pr ess USB Thermometer from the
Cypress web site (http://www.cypress.com).
In order to use the USB with the Windows operati ng system, you need to have OSR2.1 or a
more recent versi on of Wi ndows such as Memphis (Windows98, currently in Beta test).
You may determine the versi on of W indows you have through the System Properties.
Information to help you determine which version of the Windows operating system y ou hav e
is also availabl e from Microsoft (http://www.microsoft.com/kb/articles/q158/2/38.htm).
Identifying your op erat in g system as OSR2.0, OSR2.1 or Memphis:
ORS 2.0 is Windows 95 version 4.00.950b.
OSR 2.1 is Windows 95 version 4.00.950b with the USB supplement installed.
Memphis is Windows 98 ver si on 4.10. 1423 or later.
System Properties
The version of Windows you hav e installed can be found by clicking on the “System” icon in
the Control Panel (See
You can determine whether the US B suppl em ent has been installed by using the
“Add/Remov e Program s” application, which is also found on the control panel . If the USB
supplement is successf ully installed, you should be able to find it in the list of software that
can be added or deleted from the “Install/Uninstall” option wit hin the “Add/Remov e Program s”
screen.
•
Problem with system stab il ity when a crystal is used with the Cypress CY7C63X0X
family of USB controllers.
For system stabili ty c onsi der ations, we highly recommend the use of ceramic resonator
instead of crystal for the Cypress CY7C63X0X USB controllers. Crystals do not satisfy the
startup and suspend/resume stability requirements of the CY7C63X0X USB controllers.
Memphis (Windows98 Bet a X) is still a b et a program
Because Memphis i s still c hanging as i t mov es thr ough its prerelease phase, releases
subsequent to Bet a 1 may not work well with the current product. If this occurs, Cypress will
post new informati on, assembly code, drivers, or Windows applications (as appropriate).
•
Windows may ask for a USB device driver even if you have p revio usly loaded it
If you attach a USB device to a USB
port to which you have not previously att ac hed the
host
device, Windows may ask for the USB device driver.
This can be confusing if you hav e alr eady att ac hed the device to the other
port in the
host
same system and loaded the driver. However, this is normal Windows behavior.
Simply “Browse” to the Windows/System directory where the device driver is located and
Windows will find it and not ask you again.
•
Hot Unplug problem with Windows98 (M emph is) Beta 2
If your system is running M em phis Bet a 2, a hot unpl ug of t he thermometer device will cause
the operating system to crash (“blue screen”). Cypress is currently worki ng on a sol ution to
this problem. You can work around this problem by performing a Refresh in the Device
Manager (under the Contr ol P anel/System icon) prior to hot unplug. This will effectively
unload the USB thermom eter driver ( please see next bullet).
•
Device Manager Refresh unloads US B thermometer driver
If you press the Refresh butt on on the Device Manager screen, the USB thermometer driver
will unload (if it was loaded) or r eload (if it was not loaded). Cypress is currently worki ng on a
solution to this probl em . To work around this problem, do not refr esh the Dev ic e M anager . If
you must refresh the Device M anager , a second refresh will reload the thermometer driver.
•
A cold system boot will not automatically load the USB thermometer driver
If the system is rebooted, the USB thermometer driver will not automatically reload (even if
the thermomet er device is pl ugged into the USB). Cypress is currently working on a solution
to this problem. There are two possible work-arounds. Once the system is up and running,
either:
1) Press the Refresh button under the Device Manager (please see previous bullet).
-or-
2) Hot unplug/ r eplug the USB thermometer device. The driver will autom atically reload.
CY3650/CY3651USB Developer’s Kit
CY7C63000/63001Universal Serial B us Micr oc ontroller
CY7C63100/63101Universal Serial B us Micr oc ontroller
CY7C63200/63201Universal Serial B us Micr oc ontroller
CY7C63410/63411Low Speed, High I/O 1.5 Mbps USB Contr oller
CY7C63412/63413Low Speed, High I/O 1.5 Mbps USB Contr oller
CY7C63510/63511Low Speed, High I/O 1.5 Mbps USB Contr oller
CY7C63512/63513Low Speed, High I/O 1.5 Mbps USB Contr oller
CY7C64011/64012/64013High Speed USB (12 Mbps) Peri pher al Controller
CY7C64111/64112/64113High Speed USB (12 Mbps) Peri pher al Controller
CY7C65013/651134/8 Downstream Port US B Hub
CY7C66011/66012/66013High Speed USB (12 Mbps) Controller with Hub
CY7C66111/66112/66113High Speed USB (12 Mbps) Controller with Hub
Application Notes:
Designing a Low-Cost USB Mouse with the Cypress Semiconductor CY7C63000 USB Contr oller
Designing a Low-Cost Anal og US B Joystick with the Cypress CY7C63200 USB Mic r oc ontroller