4.
Write the endpoint 2 transfer program.
1
2
3
4
5
6
7
8
9
loop:
;
jnb
clr
got_EP2_data,loop
got_EP2_data
; clear my flag
; The user sent bytes to OUT2 endpoint using the USB Control Panel.
; Find out how many bytes were sent.
;
mov
movx
mov
mov
dptr,#OUT2BC
a,@dptr
r7,a
; point to OUT2 byte count register
; get the value
; stash the byte count
; save here also
10
11
r6,a
;
12 ; Transfer the bytes received on the OUT2 endpoint to the IN2 endpoint
13 ; buffer. Number of bytes in r6 and r7.
14
15
16
17
18
;
mov
inc
mov
inc
dptr,#OUT2BUF
dps
dptr,#IN2BUF
dps
; first data pointer points to EP2OUT buffer
; select the second data pointer
; second data pointer points to EP2IN buffer
; back to first data pointer
get OUT byte
19 transfer: movx
movx
20
21
22
23
24
25
26
inc
inc
movx
inc
inc
dptr
dps
@dptr,a
dptr
dps
; bump the pointer
; second data pointer
; put into IN buffer
; bump the pointer
; first data pointer
djnz
r7,transfer
;
27 ; Load the byte count into IN2BC. This arms in IN transfer
28
29
30
31
32
;
mov
mov
movx
dptr,#IN2BC
a,r6
@dptr,a
; get other saved copy of byte count
; this arms the IN transfer
;
33 ; Load any byte count into OUT2BC. This arms the next OUT transfer.
34
35
36
37
;
mov
movx
sjmp
dptr,#OUT2BC
@dptr,a
loop
; use whatever is in acc
; start checking for another OUT2 packet
Figure 6-10. Background Program Transfers Endpoint 2-OUT Data to Endpoint 2-IN
The main program loop tests the “got_EP2_data” flag, waiting until it is set by the end-
point 2 OUT interrupt service routine in Figure 6-10. This indicates that a new data
packet has arrived in OUT2BUF. Then the service routine is entered, where the flag is
cleared in line 2. The number of bytes received in OUT2BUF is retrieved from the
OUT2BC register (Endpoint 2 Byte Count) and saved in registers R6 and R7 in lines 7-10.
The dual data pointers are initialized to the source (OUT2BUF) and destination (IN2BUF)
buffers for the data transfer in lines 15-18. These labels represent the start of the 64-byte
buffers for endpoint 2-OUT and endpoint 2-IN, respectively. Each byte is read from the
OUT2BUF buffer and written to the IN2BUF buffer in lines 19-25. The saved value of
EZ-USB TRM v1.9
Chapter 6. EZ-USB CPU
Page 6-19