I want to make an ATMega8 USB device that reads a DS18B20 temperature sensor every few seconds and a corresponding PC program with which you can read the temperature from the atmega via v-usb.
The temperature is stored in a int variable.
I first did this:
Code: Select all
int temp = 255;
t_char[2] = {0};
t_char[0] = (temp >> 8) & 0xff;
t_char[1] = (temp) & 0xff;
and then in the usbFunctionSetup:
Code: Select all
usbMsgPtr = t_char;
return sizeof(t_char);
But when I try to read this out via a gcc console program:
Code: Select all
nBytes = usb_control_msg(handle,
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
USB_GET_TEMP, 0, 0, (char *)buffer, sizeof(buffer), 5000);
printf("Bytecount: %d, Buffer: %s\n", nBytes, buffer);
int temp = (buffer[0] << 8) | buffer[1];
printf("Temperature: %i\n", temp);
Nothing happens, that means no temperature is displayed.
How can I fix this or is there something clearly wrong in my idea?
Thank you for your help, nictex