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 CCS Technical Support

18F4550 USB Error

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



Joined: 21 Aug 2008
Posts: 3

View user's profile Send private message

18F4550 USB Error
PostPosted: Sat Nov 27, 2010 12:22 pm     Reply with quote

I have 2 LEDs connected to 18F4550. I put two buttons to pc software. Each button turns on one LED while turning of the other one. I am controlling the microchip via usb. My problem is it works if I press one of the buttons once. After second press the pc software freezes and microchip does nothing. Strangely it works fine with Proteus simulation. Can anyone help me solve this problem?

I use the code below.
Code:

#include <18F4550.h>
#fuses HSPLL,USBDIV,PLL5,CPUDIV1,VREGEN,NOWDT,NOPROTECT,NOLVP,NODEBUG,NOMCLR,PUT
#use delay(clock=48000000)

#define USB_HID_DEVICE     FALSE           
#define USB_EP1_TX_ENABLE  USB_ENABLE_BULK
#define USB_EP1_RX_ENABLE  USB_ENABLE_BULK 
#define USB_EP1_TX_SIZE    2             
#define USB_EP1_RX_SIZE    3         

#include <pic18_usb.h>     
#include <PicUSB.h>     
#include <usb.c> 
#include <types.h>

#define LED1    PIN_D2
#define LED2    PIN_D3
#define LED_ON  output_high
#define LED_OFF output_low

#define mode      receive[0]
#define param1    receive[1]
#define param2    receive[2]


void main(void) {
   
   int8 receive[3];                 
   int8 send[2];
   
    usb_init();                       

    usb_task();   
    usb_wait_for_enumeration();
    LED_ON(PIN_D1);
                   

   while (TRUE)
   {
         usb_task();
         if (usb_kbhit(1))         
         {
            usb_get_packet(1, receive, 3);
            if (mode == 1)
            {
             LED_ON(LED1);
             delay_ms(25);
             LED_OFF(LED2);
            }

            if (mode == 2)
            {
             LED_ON(LED2);
             delay_ms(25);
             LED_OFF(LED1);
            }           
         }     
   }
}

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 28, 2010 2:35 pm     Reply with quote

Apparently you are doing an HID project ? Use the forum's search page
and search for:
Quote:
ex_usb_hid.c

You will find many suggestions on how to make it work. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=42690

With regard to Proteus, it's a simulator. It's an abstraction. It only
simulates a subset of the features of a complex interface, such as USB.
In the real world, the size of the filter cap on the Vusb pin of the PIC
makes a lot of difference. Does Proteus even care about the value,
or the type of capacitor on the Vusb pin ? Probably not. Here is the
thing: Don't believe Proteus is "godlike". It's just a program. It has
bugs, and limitations.
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Nov 28, 2010 2:50 pm     Reply with quote

Why blame the PIC software? As I see it, it only listens for either a 1 or a 2 to come from the PC. Hard to see how that can freeze the PC program. You say the PC software freezes. It can easily be the program you wrote to send the 1 or 2 when the button is pressed to the PIC, or the PC hardware, or conflicts with the other programs you're running on the PC.
Proteus is just another lamebrain simulator, NOT the real world, NEVER trust it !
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Sun Nov 28, 2010 10:11 pm     Reply with quote

8 bytes is the min for bulk transfers. Even if you are only sending 2 or 3 bytes the USB code handles that.

Code:

#define USB_EP1_TX_SIZE    8           
#define USB_EP1_RX_SIZE    8
caldera_



Joined: 21 Aug 2008
Posts: 3

View user's profile Send private message

PostPosted: Tue Nov 30, 2010 2:50 pm     Reply with quote

PCM programmer wrote:
Apparently you are doing an HID project ? Use the forum's search page
and search for:
Quote:
ex_usb_hid.c

You will find many suggestions on how to make it work. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=42690


temtronic wrote:
Why blame the PIC software? As I see it, it only listens for either a 1 or a 2 to come from the PC. Hard to see how that can freeze the PC program. You say the PC software freezes. It can easily be the program you wrote to send the 1 or 2 when the button is pressed to the PIC, or the PC hardware, or conflicts with the other programs you're running on the PC.
Proteus is just another lamebrain simulator, NOT the real world, NEVER trust it !


Its not a HID project. The main project is a minimized temperature control system. I will use 3 DS18B20s and fans etc. but I couldn't even send any temperature values to PC. Then I made this sample test circuit but it doesn't work properly either.

MikeP wrote:
8 bytes is the min for bulk transfers. Even if you are only sending 2 or 3 bytes the USB code handles that.

Code:

#define USB_EP1_TX_SIZE    8           
#define USB_EP1_RX_SIZE    8


Thank you MikeP for your advice. I made the changes you mentioned but it's still not working.
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Tue Nov 30, 2010 5:01 pm     Reply with quote

You need to find out if its the PC app or the PIC with the problems.

What happens if you kill the PC app and restarted it after the lockup? does it work again or do you have to do a power cycle on the pic hardware for it to work again?
caldera_



Joined: 21 Aug 2008
Posts: 3

View user's profile Send private message

PostPosted: Thu Dec 02, 2010 3:30 pm     Reply with quote

It doesn't work until I make a power cycle on the pic. What could be the problem?
MikeP



Joined: 07 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Thu Dec 02, 2010 11:41 pm     Reply with quote

What are you using for the PC code?
Can you post your PC app code?
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Fri Dec 03, 2010 9:09 am     Reply with quote

Looking at what is posted, what device class are you actually trying to use?.
You haven't posted PICUsb.h, which presumably (hopefully) contains your usb descriptor, so we have no hope of working out what the actual nature of the interface you are setting up is.... You are presumably trying to set up something like the test and measurement class?.
Your best bet, would be to get a USB 'sniffer' program, and see what is actually being sent, and how this relates to the class you are trying to use. Though the USB stack, is a lot more rugged than it used to be, it will still get confused if a device does not behave as it is meant to. Your problem has all the sounds of a USB descriptor, which is not valid for the class you are trying to use....

Best Wishes
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Fri Dec 03, 2010 8:41 pm     Reply with quote

For such a simple task, I would not bother using HID. Why don’t you use CDC? It will make it easy to debug (you can just use hyper term to view what the pic is sending) and you will not need to write any drivers for the device.

Have a look at ex_usb_serial.c for a good start point.

Mark
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