|
|
View previous topic :: View next topic |
Author |
Message |
MatrixPhreak Guest
|
Compiler Error when using USB |
Posted: Tue Dec 09, 2008 1:41 am |
|
|
My includes:
Code: | #include<18F4550.h>
#include<pic18_usb.h> |
The relevant includes in the pic18_usb.h:
The error:
Code: | ***Error 112 ".\PICC\drivers\pic18_usb.h" Line 472(1,1): Function used but not defined: ... usb_token_reset SCR=1732 |
My only error... and it's in a file I haven't even touched. The paths to the relevant includes all seem to be fine (usb_token_reset being defined in usb.h), but I can't for the life of me figure out what keeps giving me that error. |
|
|
Ttelmah Guest
|
|
Posted: Tue Dec 09, 2008 5:28 am |
|
|
You can't just load 'PIC18_USB.H', without telling the code what type of USB device you are actually wanting to use.
Normally, you would load USB_CDC, USB_CDC2, or the HID drivers, which willl _themselves_ load the PIC18_USB file.
USB has a whole series of 'parts'. The low level driver to actually talk to the periheral itself, the descriptor file, and the higher level functions that call the low level part. PIC18_USB, is the low level driver. It needs the higher level functions, and the descriptor loaded _first_.
Best Wishes |
|
|
MatrixPhreak Guest
|
|
Posted: Tue Dec 09, 2008 11:56 am |
|
|
Thanks for your reply it was very helpful, and by going into the example code (specifically ex_usb_mouse.c) to check what #includes I've been missing, I've managed to get it to compile with no errors....
But the code I took from that sample for my main() function isn't working. It should be moving my mouse cursor in circles... and while it programmed nicely, it's not working. Am I missing something critical that I (probably) just decided was extra code I didn't need for my demo? For instance, I left out most of the serial port code and LED code because I didn't think I needed them. My main() function is as follows:
Code: | void main(void) {
#define MOUSE_SEQUENCE_STEPS 16
const char mouse_seq[MOUSE_SEQUENCE_STEPS]=
{0, 1, 3, 4, 4, 4, 3, 1, 0, -1, -3, -4, -4, -4, -3, -1};
int8 out_data[4];
int8 x_seq=0; int8 y_seq=MOUSE_SEQUENCE_STEPS/4;
int8 count=0;
while (TRUE) {
usb_task();
if (usb_enumerated()) {
out_data[0]=0; //button state goes here
out_data[1]=mouse_seq[x_seq];
out_data[2]=mouse_seq[y_seq];
out_data[3]=0; //wheel state goes here
if (usb_put_packet(1,out_data,4,USB_DTS_TOGGLE))
count++;
if (count > 10) {
if (++x_seq>=MOUSE_SEQUENCE_STEPS) {x_seq=0;}
if (++y_seq>=MOUSE_SEQUENCE_STEPS) {y_seq=0;}
count=0;
}
delay_ms(10);
}
}
}
|
That's taken directly from the example source and compiled as my main() function. Am I missing something big? |
|
|
MatrixPhreak Guest
|
|
Posted: Tue Dec 09, 2008 12:00 pm |
|
|
Whoops... sorry for the double post but since I'm not actually a member, I can't edit or delete. I definitely missed something in my code.... a nice healthy
Unfortunately, even with that thrown in there before my while(TRUE) loop... my mouse cursor refuses to move in circles. |
|
|
Ttelmah Guest
|
|
Posted: Tue Dec 09, 2008 1:45 pm |
|
|
The question now, is whether the device is enumerating?.
Does windows 'see' a new mouse device when the chip is attached?. If not, there are a lot of things to look at:
The connections themselves.
Definition of the connection sense pin. Is it used?. If so, is it wired correctly?.
Clock. Are you sure the clock is programmed correctly for whatever crystal you are using?.
USB power and sense resistors. Have you got the internal 3.3v regulator enabled?. If not are you supplying 3.3v to Vusb. What capacitors have you got on Vusb. What power feeds the chip itself?. Are you using the internal USB transceiver or an external one?. USB detects the device's presence, and it's basic configuration from the two sense resistors. Are you using the internal ones or external ones?.
Best Wishes |
|
|
Guest
|
|
Posted: Tue Dec 09, 2008 5:58 pm |
|
|
So many thanks to you! It works perfectly now! The problem was it wasn't enumerating properly, but now I've got it sorted out, and it works like a dream.
Thank you very much, Ttelmah... your help has been the keystone in getting this thing to work. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|