Hi,
i'm completely new to v-usb (and only got realy small knowledge to AVR)
I've a Curcuit for USB Generic Hid (including an ISP-Port) and try to
make a Generic HID device, to get the status of a potentiometer.
I managed to get the "hid-custom-rq" example to work and now i'm trying
to add a new request.
The problem is, that i wanted to test multiple byte answer (to report
back the value from the potentiometer) so i added the request id 3
(CUSTOM_RQ_GET_POTI) and set the dataBuffer to the size of 4 and then to
[0] = 0 ; [1] = 1 ; [2] = 1. All works fine i think, but on the client
side, i only get the first byte and the others are random (or zero if i
first clear the buffer)
could anybody give me a hint what i#m doing wrong?
here is the code for the usb device
request.h
1
/* Name: requests.h
2
* Project: custom-class, a basic USB example
3
* Author: Christian Starkjohann
4
* Creation Date: 2008-04-09
5
* Tabsize: 4
6
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8
* This Revision: $Id: requests.h 692 2008-11-07 15:07:40Z cs $
9
*/
10
11
/* This header is shared between the firmware and the host software. It
12
* defines the USB request numbers (and optionally data types) used to
13
* communicate between the host and the device.
14
*/
15
16
#ifndef __REQUESTS_H_INCLUDED__
17
#define __REQUESTS_H_INCLUDED__
18
19
#define CUSTOM_RQ_SET_STATUS 1
20
/* Set the LED status. Control-OUT.
21
* The requested status is passed in the "wValue" field of the control
22
* transfer. No OUT data is sent. Bit 0 of the low byte of wValue controls
23
* the LED.
24
*/
25
26
#define CUSTOM_RQ_GET_STATUS 2
27
/* Get the current LED status. Control-IN.
28
* This control transfer involves a 1 byte data phase where the device sends
29
* the current status to the host. The status is in bit 0 of the byte.
30
*/
31
32
#define CUSTOM_RQ_GET_POTI 3
33
34
35
#endif /* __REQUESTS_H_INCLUDED__ */
main.c
1
/* Name: main.c
2
* Project: hid-custom-rq example
3
* Author: Christian Starkjohann
4
* Creation Date: 2008-04-07
5
* Tabsize: 4
6
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8
* This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
9
*/
10
11
/*
12
This example should run on most AVRs with only little changes. No special
13
hardware resources except INT0 are used. You may have to change usbconfig.h for
14
different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or
15
at least be connected to INT0 as well.
16
We assume that an LED is connected to port B bit 0. If you connect it to a
17
different port or bit, change the macros below:
18
*/
19
#define LED_PORT_DDR DDRB
20
#define LED_PORT_OUTPUT PORTB
21
#define LED_BIT 0
22
23
#include <avr/io.h>
24
#include <avr/wdt.h>
25
#include <avr/interrupt.h> /* for sei() */
26
#include <util/delay.h> /* for _delay_ms() */
27
28
#include <avr/pgmspace.h> /* required by usbdrv.h */
29
#include "usbdrv.h"
30
#include "oddebug.h" /* This is also an example for using debug macros */
31
#include "requests.h" /* The custom request numbers we use */
A question of your own?
This thread is over 15 years old.
Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.