Atmel AT89RFD-11 User manual

AT89RFD-11: USB Mouse with Flash
Memory Reference Design
..............................................................................................
User Guide

AT89RFD-11 User Guide 1
7648A–USB–06/06
Section 1
Introduction...........................................................................................1-1
1.1 Features....................................................................................................1-1
1.2 Introduction ...............................................................................................1-1
1.3 Key Reference Design Objectives ............................................................1-2
Section 2
Reference Design Overview.................................................................2-3
Section 3
Theory of Operation..............................................................................3-5
3.1 Mouse Buttons..........................................................................................3-5
3.2 Z-Wheel ....................................................................................................3-5
3.4 Sensor interface........................................................................................3-7
3.5 USB...........................................................................................................3-8
Section 4
Firmware Architecture.........................................................................4-15
Section 5
Schematic & BOM ..............................................................................5-17

AT89RFD-11 User Guide -1
7648A–USB–06/06
Section 1
Introduction
1.1 Features •One MCU = 2 devices (mouse and mass storage controllers) and one USB hub
•No hub required
•USB 2.0 Full Speed compliance
•1 ms minimum Polling Interval
•Low Power bus-powered device
•Supported by all Microsoft O/S from Windows® 2000 and later
•256 MB Nand Flash memory supported (driver supports memories up to 1GB)
•High speed motion detection up to 20 ips (inches per second) and 8 G
•Up to 800 CPI resolution
•No mechanical moving parts
•ISP (In System Programming) to upgrade the firmware
•2K E2PROM to store parameters
•Project sources availble with royalty free licence agreement
1.2 Introduction This design guides describes the design of a composite device (mouse & mass storage
device) using the AT89C5131A Atmel microcontroller and the Avago ADNS-3030 opti-
cal sensor. The firmware implementation section describes the firmware architecture to
implement a composite device with the mouse and the memory functions. The Appendix
contains the hardware implementation and the BOM of this reference design.

-2 AT89RFD-11 User Guide
7648A–USB–06/06
A familiarity with the AT89C5131A-M microcontroller (datasheet available on atmel web
site www.atmel.com), the ADNS 3030 sensor (datasheet available on avago web site
www.avagotech.com) and the USB specification (http://www.usb.org) is assumed.
1.3 Key Reference
Design
Objectives
1. Offer a complete solution based on a full speed mouse with a mass storage
capability.
2. Highlight the AT89C5131A benifits to manage two devices simultaneously.
3. Highlight the low power benifit of the ADNS 3030.
4. Flash based development platform to facilitate customization and firmware
upgrade.
+ =

AT89RFD-11 User Guide -3
7648A–USB–06/06
Section 2
Reference Design Overview
The reference design offers a full speed mouse with a mass storage capability to allow
the user to save and exchange files using his mouse. This solution is based on a double
enumeration (composite device) process to allow the management of both devices with
one microcontroller the AT89C5131A-M. The mouse is based on the ADNS-3030 Avago
sensor to collect the X, Y motion value. An optical quadrature encoder provides the Z-
wheel movement. Each of the button switches is pulled up normally and provides a
Ground when depressed.
Figure 2-1. .Reference Design Overview
AT89C5131A-M
ATMEL
microcontroller
AVAGO
ADNS-3030
Optical Mouse
Sensor
MOSI
MISO
SCLK
STDW
NCS
Z Optics
Wheel
Quadrature
signals
Left Button
Middle Button
Right Button
Nand Flash
Memory
I/Os
Control
&
command
MOTION

AT89RFD-11 User Guide -5
7648A–USB–06/06
Section 3
Theory of Operation
3.1 Navigation
Technology The heart of the optical navigation sensor is a CMOS image array. An LED and an opti-
cal system illuminate the surface that the sensor is navigating on. The texture of the
surface casts bright and dark spots forming distinct images as the sensor is moved
across the surface. A Digital Signal Processing (DSP) engine and its built-in algorithm
evaluate these images and determine the magnitude and direction of the movement.
The motion data is made available in the delta_X and delta_Y registers for the system
controller to retrieve. An extensive power saving topology is implemented within the
ADNS-3030 navigation engine. A Motion pin (output) is available to act as the system
interrupt. As long as there is no motion the system can remain in Sleep mode allowing
maximum battery power saving. Based on the last detected motion the optical naviga-
tion engine enters various power saving modes when no new motion occurs. These
power saving features are particularly beneficial for wireless.
Figure 3-1.

-6 AT89RFD-11 User Guide
7648A–USB–06/06
3.2 Sensor This reference design features the ADNS-3030 optical navigation engine. It contains an
Image Acquisition System (IAS), a Digital Signal Processor (DSP), and a three-wire
Serial Peripheral Interface consists of the serial clock (SCLK), the master-in/slave-out
(MISO) and the master-out/slave-in (MOSI). In addition two signals, Motion, is an output
intended to act as an interrupt to the microcontroller whenever the ADNS-3030 senses
motion, and SHTDWN, is an input pin to set the sensor in shutdown mode. When the
mouse is moved the ADNS-3030 alerts the system controller by activating the Motion
signal. At the same time the ADNS-3030 accumulates the horizontal and vertical dis-
placements (count per inch, or cpi) in its Delta_X and Delta_Y registers respectively.
The ADNS-3030 deactivates the Motion signal as soon as movement stops. The mouse
motion can be also detected by checking if the MOT bit (bit 7 in Motion register) is set.
The SmartSpeed technology automatically optimizes the frame rate by examining the
acquired images of the surface. It also manages the integrated LED driver to coordinate
with the shutter. The system controller reads the motion information and reports it to the
PC to update the cursor position. The advantages of using ADNS-3030 optical sensor
are the efficient power management, high tracking accuracy, and efficient communica-
tions with the optical sensor via the full duplex SPI port. To learn more about sensor’s
technical information, please visit the Avago web site at http://www.avagotech.com
Figure 3-2. Sensor interface
3.3 Mouse Buttons Mouse buttons are connected as standard switches. These switches are pulled up by
the pull up resistors inside the microcontroller. When the user depresses a button, the
switch will be closed and the pin will be pulled LOW to GND. A LOW state at the pin is
interpreted as the button being depressed. A HIGH state is interpreted as the button has
been released or the button is not being depressed. In this reference design there are
three switches: left, Z-wheel (middle), and right.
AT89C5131A-M
ATMEL
microcontroller
AVAGO
ADNS-3030
Optical Mouse
Sensor
MOSI
MISO
SCLK
STDW
NCS
MOTION

AT89RFD-11 User Guide -7
7648A–USB–06/06
Figure 3-3. Mouse Buttons
3.4 Z-Wheel The motion of Z-wheel is detected using the quadrature signal generated by optical sen-
sors. Two phototransistors are connected in a source-follower configuration forming
Channel A and Channel B. An infrared LED shines, causing the phototransistors to turn
on. In between the phototransistors and LED is a pinwheel that turns on the mouse ball
rollers. The fan of this pinwheel is mechanically designed to block the infrared light such
that the phototransistors are turned on and off in a quadrature output pattern. Every
change in the phototransistor outputs represents a count of mouse movement. Compar-
ing the last state of the optics to the current state derives directional information. As
shown in the Figure below, rotating the wheel forward produces a unique set of state
transitions, and rotating the wheel backward produces another set of unique state
transitions.
Figure 3-4. Optics Quadrature Signal Generation
Left Button
Middle Button
Right Button
AT89C5131A-M
P1_0
P1_2
P1_1

-8 AT89RFD-11 User Guide
7648A–USB–06/06
3.5 Memory The target memory used with this reference design is a Nand Flash memory (Micron
M29F2G08AAB) of 256 MBytes. This memory allow the user to save and exchange data
and files with any PC.
The Nand Flash memory is connected to the AT89C5131A-M as below. P0 and P2 ports
are mandatory in order to access the Nand Flash using MOVX instructions.
Figure 3-5. Nand Flash memory interface
3.6 USB
3.6.1 Multiple
Enumeration
(composite device)
Thanks to its seven endpoints, the AT89C5131A-M can manage several USB devices
simultanuously using the multiple enumerations functionality (composite device). This
functionnality allows the user to declare one device with several interfaces. Each inter-
face is seen and managed as a stand-alone device from the PC point of view. In our
case we declare two interfaces: one to manage the mass storage device and the other
to manage the HID mouse device.
To be able to manage two interfaces, the microcontroller should have at the least a con-
trol endpoint and the sum of the endpoints required by both interfaces. For example for
this reference design we need 1 endpoint for control transfer, 1 endpoint for mouse and
2 endpoints for mass storage, which means that we need 4 endpoints to make this
application.
P0.0
P0.1
P0.2
P0.3
P0.4
P0.5
P0.6
P0.7
AVss Vss
Xtal2
Xtal1
24
MHz
22pF
22pF
100
27
27
1.5k
D-
D+
Vref
PLLF
10nF 2.2nF
I/O.0
I/O.1
I/O.2
I/O.3
I/O.4
I/O.5
I/O.6
I/O.7
MiCRON
M29F2G08AAB
AT89C5131A-M
Vss
P2.0
P2.1 CLE
ALE
USBconnector
3.3V
regulator
D-
D+
Vbus
GND
2.2k
Vcc
Vcc
R/B
10µF
Tantal.
P3.7
P2.3
P2.4
VDD AVDD
1µF
100nF
Vcc
P3.3
Vcc
EA
100k
P3.0
Write
Protection
2.2k
WE
CE
RE
P3.6
PSEN
ISP
2.2k
optional
10µF
Tantal.
10k
Vcc
WP
Ucap

AT89RFD-11 User Guide -9
7648A–USB–06/06
Figure 3-6. Multiple Enumeration
From the PC point of view, the reference design is presented as two stand-alone
devices. The figure below shows how the device appears in the device manager.
Device
descriptor
Configuration
descriptor
Interface
descriptor
Mass Storage
Interafce
descriptor
HID mouse
Endpoint IN
descriptor
HID
descriptor
Endpoint OUT
descriptor
Endpoint IN
descriptor
Report
descriptor Physical
descriptor
Mass Storage
Device
Mouse Device

-10 AT89RFD-11 User Guide
7648A–USB–06/06
Figure 3-7. Device Manager Multiple Enumeration
3.6.2 HID Mouse Overview The USB mouse application is a simple data exchange between the PC and the mouse.
The PC asks the mouse if there is a new data available each P time (polling interval
time), the mouse will send the data if it is available, otherwise it will send a NAK (No
Acknowlodge) to tell the PC that there is no data available now.
The data sent to the PC is called report. This report has the structure below :
Figure 1. USB report structure
The X, Y are collected thanks to the sensor.

AT89RFD-11 User Guide -11
7648A–USB–06/06
The button values are updated following the button switches state (1 if depressed, 0 if
released).
The scroll wheel value is updated using the motion of Z-Wheel as explained in section
4.2
3.6.3 Mass Storage
Overview The Mass Storage application is simply file transfer between the PC and the device.
The USB data exchange for this application is based on the SCSI (Small Computer Sys-
tem Interface) commands which use two bulk endpoints (one IN and one OUT) to
perform the status and data transfer. The endpoint 0 (control endpoint) is used only to
perform the enumeration process, the errors management and to determine the LUN
(Logical Unit Number) value.
In other words, the Mass Storage application is a set of SCSI commands send by the
host to manage the file transfers.
The Mass Storage class allows one device to manage several memories at the same
time thanks to the LUN.
Figure 3-8. Mass Storage Application Overview
The standard enumeration process (USB chapter 9 support) is performed through the
default control endpoint. This process consists of a set of parameters sent by the device
to the host to identify the device class and load the appropriate drivers. This parameters
are called the descriptors.
The SCSI command are performed through both endpoints (IN or OUT). Each SCSI
command is decoded and transmitted to the appropriate memory through a command
set (Read, Write, is memory present, is memory write protected,...).
The memory answers are converted in SCSI status before being wrapped in USB CSW
(Command Status Wrapper) and sent to the USB Host controller. Because the USB bus
is a single master bus (the USB Host), each data transfer is initiated by the USB Host,
following a specific Command-Data-Status flow (see figure below)

-12 AT89RFD-11 User Guide
7648A–USB–06/06
Figure 3-9. Command/Data/Status Flow
The CBW (Command Block Wrapper) contains some USB information such as the LUN
addressed, the length of the SCSI command, and of course, it also contains the SCSI
command for the memory.
The CSW (Command Status Wrapper) contains the SCSI status. If the status is GOOD,
the Host will send the next following command. If the status is different from GOOD
(FAILED, PHASE ERROR,...), the host will ask for more information regarding the error
by sending a REQUEST SENSE command.
Note: Please refer to Mass Storage Application Note (available on www.atmel.com) for more
details
3.6.4 Power Management Although this is not a wireless design it is worthwhile to mention the low-power feature of
the ADNS-3030.
The ADNS-3030 has three power-saving modes. Each mode has a different motion
detection period, affecting response time to mouse motion (Response Time). The sen-
sor automatically changes to the appropriate mode, depending on the time since the last
reported motion (Downshift Time). The parameters of each mode are shown in the fol-
lowing table. Mode Response Time (nominal) Downshift Time (nominal)
Each rest mode successively decreases in power consumption. The ADNS-3030 con-
sumes typically 32 µA in Rest 3 mode. Parameter Symbol Minimum Typical Maximum
Units Notes DC Supply Current In various modes.
Mode Response Time (nominal) Downshit Time (nominal)
Rest1 16.5 ms 237 ms
Rest 2 82 ms 8.39 s
Rest 3 410 ms 504 s

AT89RFD-11 User Guide -13
7648A–USB–06/06
3.6.4.1 Motion Pin Timing The motion pin is a level-sensitive output that signals the microcontroller when motion
has occurred. The Motion pin is lowered whenever the Motion bit is set; in other words,
whenever there is data in the Delta_X or Delta_Y registers. Clearing the Motion bit (by
reading Delta_Y and Delta_X, or writing to the Motion register) will set the Motion pin
high. This feature further contributes to the system power saving. As long as the ADNS-
3030 is not sensing motion the microcontroller can enter its own sleep mode as long as
it is capable of waking up from an interrupt by the Motion pin.
3.6.4.2 LED Mode For power savings, the LED will not be continuously on. ADNS-3030 will flash the LED
only when needed. This is fully automated and managed by the ADNS-3030. As a result
the ADNS-3030 consumes only about 4 mA of average current while in the active mode.
Parameter Symbol Minumum Typical Maximum Units Notes
DC Supply IDD 3.9 13
mA
Average current,including
LED current.
No load on MISO,
MOTION.
Current In 0.63 2.3
Various 0.13 0.5
Modes 0.032 0.15

-14 AT89RFD-11 User Guide
7648A–USB–06/06
3.6.5 ISP The ISP (In System Programming) allows the user to upgrade the firmware using the
USB port. To use this feature the user needs Flip software (available on
www.atmel.com).
Please follow the below instruction to put the reference design in ISP mode:
1. Unplug the reference design from the PC.
2. Push the button located on the bottom of the reference desgin (see the figure
below)
Figure 3-10. ISP Button
3. Plug the reference design to the PC
4. Release the button
5. Check the Device Manager, and you should see the same icon (Jungo® icon) as
shown in the figure below. If not, start again from the step1
6. Launch Flip software and start upgrading your firmware
ISP Button

AT89RFD-11 User Guide -15
7648A–USB–06/06
Figure 3-11. Device Manager

AT89RFD-11 User Guide -17
7648A–USB–06/06
Section 4
Firmware Architecture
The firmware of this reference design is written in C language. The main files are
explained below:
• usb_task.c: This file manages the USB enumeration, the SCSI command, the USB
mouse motion (X,Y motion, buttons click, scroll wheel motion) and the USB events
(suspend, resume, reset...)
• usb_enum.c: This file contains the USB endpoint 0 management routines
corresponding to the standard enumeration process (refer to chapter 9 of the USB
specification). This file calls routines of the usb_user_enum.c file for non-standard
request management. The enumeration parameters (descriptor tables) are contained
in the usb_user_configuration.c file.
• usb_user_enum.c: This file contains the non-standard USB requests.
• usb_user_configuration.c: This file contains the enumeration parameters (USB
descriptors)
• sensor.c: This file contains the functions to initialize the sensor and the wheel,
manage the sensor access (read, write) and the wheel motion detection.
• ctrl_access.c: This file manages the interface between the USB and the target
memory using the LUN (Logical Unit Number).
• nf.c: This file contains the high level NF with 2Kb page routines
• nf_mem.c: This file contains the interface routines of Nand Flash memory
• The figure hereunder shows the firmware architecture implementation

-18 AT89RFD-11 User Guide
7648A–USB–06/06
Figure 4-1. Firmware Architecture Implementation
USB enumeration management
(usb_user_enum.c, usb_enum.c,
usb_user_configuration.c,
scsi_decoder.c)
usb driver (usb_drv.c)
MCU driver (mcu_drv.c)
SPI driver (spi_lib.c)
Nand Flash driver (nf_drv.c)
applicationAPIDriversHardware
MCU/Mouse/Memory
hardware
sensor & wheel
management
(sensor.c)
tasks management
(usb_task.c)
-enumeration process
-Mass Storage SCSI command management
-USB mouse report management
usb_task()
-polling call
Is_usb_mouse_event()
-interrupt call each SOF (1ms)
-Check if mouse motion OK
-check if button pressed or released
-check if wheel motion OK
-Fill the USB mouse report out
-Enumeration process management
-SCSI command management
-USB requests management
-USB descriptors declaration
-SCSI commands decoder
-sensor and wheel initialization
-read and write sensor functions
-wheel interrupt management
memory management
(ctrl_access.c, nf.c,
nf_mem.c)
-manage the access to the memory
-manage the NF memory state,
read, write...

AT89RFD-11 User Guide -19
7648A–USB–06/06
Section 5
Schematic & BOM
Vcc
VccVcc
P1_4
P1_3
P3_4
P1_6
P1_7
P1_5
C2
10nF
C2
10nF
C4
10nF
C4
10nF
C31μF C31μF
C1
1μF
C1
1μF
NCS
1
MISO
2
SCLK
3
MOSI
4
MOTION
5XY_LED 6
LED_GND 7
NC 8
AGND
9
SHTDWN
10
NC 20
AGND
19
NC 18
NC 17
GND 16
VDD 15
AGND
14 GND 13
GND 12
AVDD
11
U1
ADNS3030
U1
ADNS3030
R1
10
R1
10
C6
10nF
C6
10nF
C5
1μF
C5
1μF
D1
HLMP_ED80
D1
HLMP_ED80

-20 AT89RFD-11 User Guide
7648A–USB–06/06
_EA
_EA
XTAL1
_PSEN
PLLF
XTAL2
XTAL2
XTAL1
_PSEN
UCAP
UCAP
PLLF
/RST
/RST
VCC
AVCC
AVSS
AVCC
Vcc
Vcc
Vcc
Vcc
Vcc
P3_6
P0_7
P0_6
P0_5
P0_4
P0_3
P0_2
P0_1
P2_3
P2_4
P3_0
P1_0
P1_1
P1_2
P3_2
P3_3
P3_4
P3_5
VREF
D+
D-
P3_5
P3_3
P3_2
P1_7
P1_6
P1_5
P2_1
P2_0
P0_0
P1_4
P1_3
P1_2
P1_1
P1_0
P3_7
Wheel
Smaller Swith
possible (Only
for ISP
programming)
Close to μC
Close to μC
Close to μC
C9
1μF
C9
1μF
R2
2.2 K
R2
2.2 K
C8
1μF
C8
1μF
SW1
ISP
SW1
ISP
Y1 CRYSTAL 24MHzY1 CRYSTAL 24MHz
C13
10nF
C13
10nF
R6
4K7
R6
4K7
R3
10K
R3
10K
R7
100
R7
100
C10
22 pF
C10
22 pF
C14
2.2 nF
C14
2.2 nF
1 2
SW4
Scroll
SW4
Scroll
C12
10nF C12
10nF
1 2
SW3
Right
SW3
Right
R4
100
R4
100
VCC
2
QA
1
QB
3
U3
MID-95A3LH
U3
MID-95A3LH
R5
4K7
R5
4K7
1 2
SW2
Left
SW2
Left
D2
MIE-114A1
D2
MIE-114A1
P2.0/A8/D8 56
P2.1/A9/D9 57
P2.2/A10/D10 58
P1.5/CEX2/KIN5/MISO 59
P1.6/CEX3/KIN6/SCK 60
P1.7/CEX4/KIN7/MOSI 61
P4.0/SCL 62
P4.1/SDA 63
P2.3/A11/D11
2
P2.4/A12/D12
3
P2.5/A13/D13
4
XTAL2
5
XTAL1
6
P2.6/A14/D14
7
P2.7/A15/D15
8
VDD
9
AVDD
10
UCAP
11
AVSS
12
P3.0/RxD
14
PLLF
19
D-
20
D+
21
VREF
22
UVSS
23
EA
24
ALE
25
PSEN
26
P3.1/TxD
27
P3.2/INT0
28
P3.3/INT1/LED0
29
P3.4/T0
30
P3.5/T1/LED1
31
nc11 34
P3.6/WR/LED2 35
P0.7/AD7/D7 36
P0.6/AD6/D6 37
P0.5/AD5/D5 38
P3.7/RD/LED3 39
P0.4/AD4/D4 40
VSS 42
P0.3/AD3/D3 43
RST 44
P0.2/AD2/D2 45
P0.1/AD1/D1 46
nc13 47
P0.0/AD0/D0 55
P1.4/CEX1/KIN4 54
P1.3/CEX0/KIN3 53
P1.2/ECI/KIN2 52
P1.1/T2EX/KIN1/SS 51
P1.0/T2/KIN0 50
nc16 64
nc1
1
nc15 49
nc14 48
nc12 41
nc10 33
nc9
32
nc7
18 nc6
17
nc5
16 nc4
15
nc3
13
U2
AT89C5131A-M_VQFP64
U2
AT89C5131A-M_VQFP64
C11
22 pF
C11
22 pF
C7
100nF
C7
100nF
Table of contents