CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC18F14K50 USB trouble

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Eoin87



Joined: 20 Oct 2009
Posts: 18

View user's profile Send private message

PIC18F14K50 USB trouble
PostPosted: Sat Mar 20, 2010 12:10 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Mar 20, 2010 1:29 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Mar 20, 2010 3:35 pm     Reply with quote

Yes you are right, but doesn't really affect my USB code now does it :P
Eoin87



Joined: 20 Oct 2009
Posts: 18

View user's profile Send private message

PostPosted: Wed Mar 31, 2010 5:00 am     Reply with quote

Sorry to bump this topic, but does anyone have any ideas why I cannot send data from the PIC to PC.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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