View previous topic :: View next topic |
Author |
Message |
Eoin87
Joined: 20 Oct 2009 Posts: 18
|
PIC18F14K50 USB trouble |
Posted: Sat Mar 20, 2010 12:10 pm |
|
|
I'm having some trouble trying to get USB code to run on an 18F14K50.
I had this code already working perfectly with an 18f2450. At the moment the code compiles perfectly and downloads to the part ok. The PC recognises the USB device when it starts up and I can send commands to it from Labview and make lights flash, etc. But whenever it attempts to send a USB packet to the PC it returns 0 from the usb_send_packet function.
Here is a snippet of my code:
Code: |
if (usb_enumerated () ) // Is Usb buffer ready ?
{
led1 = true;
while (true)
{
if (usb_kbhit (1)) //does endpoint contain data from host ?
{
output_toggle(pin_c0);
usb_get_packet (1, rxbuffer, 10); // fetch USB data from buffer and flush
switch (rxbuffer[0])
{
case 0x46: /// Trigger
{
int8 usb=77;
int1 x;
output_toggle(pin_c2);
x= usb_put_packet (1,&usb, 1, USB_DTS_TOGGLE);
output_bit(x,pin_c3);
}
break;
|
usb_put_packet keeps returning 0. I read up in the USB include files and apparently that indicates that.
Quote: |
Output: TRUE if data was sent correctly, FALSE if it was not. The only
/* reason it will return FALSE is if because the TX buffer is still full
/* from the last time it tried to send a packet.
|
Does anyone have any experience with USB on this chip? Any ideas?
I also manually set the internal pull up on D+ and set the speed bit to full speed in the UCFG register. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 20, 2010 1:29 pm |
|
|
Quote: |
output_bit(x,pin_c3);
|
The parameters are reversed in your line of code, above.
The manual says the Pin comes first. Then the value:
Quote: |
output_bit( )
Syntax:
output_bit (pin, value)
|
|
|
|
Eoin87
Joined: 20 Oct 2009 Posts: 18
|
|
Posted: Sat Mar 20, 2010 3:35 pm |
|
|
Yes you are right, but doesn't really affect my USB code now does it :P |
|
|
Eoin87
Joined: 20 Oct 2009 Posts: 18
|
|
Posted: Wed Mar 31, 2010 5:00 am |
|
|
Sorry to bump this topic, but does anyone have any ideas why I cannot send data from the PIC to PC. |
|
|
|