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

ex_usb_mouse causes blue screen on PC side

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



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

ex_usb_mouse causes blue screen on PC side
PostPosted: Thu Dec 14, 2006 11:39 am     Reply with quote

Hello,
I am trying the USB mouse example source code. I have PIC 18F2455 and compiler v3.242.
When I plug the PIC in Windows shows me that a new device is connected. Then I can see a bubble in a TRAY about USB HID Mouse. In few seconds PC crashes with a Windows blue screen - a mesage about USBPORT.SYS.
I tried it on a PIC with and without a USB bootloader and both is the same:(
Does any1 know what is its reason?
Thank you very much
Code:
#include <18f2455.h>

#device ADC=10 // 10 bits return value from ADC
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN,NOPBADEN,WRTB,MCLR,NOCPD
#use delay(clock=48000000)// full speed USB device
#use rs232(baud=19200,xmit=PIN_C6, rcv=PIN_C7, PARITY=N, BITS=8, STREAM=RS232)

#include <pic18_usb.h>
#include <usb_desc_mouse.h>
#include <usb.c>
#define LED2 PIN_B0
#define LED3 PIN_B1
#define BUTTON PIN_B4
#define LED_ON output_high
#define LED_OFF output_low

void usb_debug_task(void);

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;
   set_tris_b(0x10);//B4 is input for button
   //LED_ON(LED1);
   LED_OFF(LED2);
   LED_OFF(LED3);

   printf("\r\n\nUSB Mouse Example");
   usb_init_cs();

   while (TRUE) {
      usb_task();
      usb_debug_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);
      }
   }
}
void usb_debug_task(void) {
   static int8 last_connected;
   static int8 last_enumerated;
   int8 new_connected;
   int8 new_enumerated;

   new_connected=usb_attached();
   new_enumerated=usb_enumerated();

   if (new_connected)
      LED_ON(LED2);
   else
      LED_OFF(LED2);

   if (new_enumerated)
      LED_ON(LED3);
   else
      LED_OFF(LED3);

   if (new_connected && !last_connected)
      printf("\r\n\nUSB connected, waiting for enumaration...");
   if (!new_connected && last_connected)
      printf("\r\n\nUSB disconnected, waiting for connection...");
   if (new_enumerated && !last_enumerated)
      printf("\r\n\nUSB enumerated by PC/HOST");
   if (!new_enumerated && last_enumerated)
      printf("\r\n\nUSB unenumerated by PC/HOST, waiting for enumeration...");

   last_connected=new_connected;
   last_enumerated=new_enumerated;
}

meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Sat Dec 23, 2006 1:44 pm     Reply with quote

really noone has tried this example source code?
Would anyone be so kind and compile it in different version of compiler in order to find out wheather problem is in the compiler?
thanks in advance
Ttelmah
Guest







PostPosted: Sun Dec 24, 2006 3:59 am     Reply with quote

What is your crystal rate?.
Your fuses don't quite make sense to me.
You have HSPLL selected, which means that the CPU is feeding off it's own PLL/divider. Then CPUDIV1, which means that the feed is direct to the CPU clock. You have the CPU clock rate specified as 48MHz, but then have the USB divider specified as PLL1. This would feed 48MHz, into part of the circuit designed to accept 4Mhz (if your CPU settings are right), or would run the CPU at only 1/12th the specified frequency.
I think your fuses are almost certainly wrong.

Best Wishes
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Mon Dec 25, 2006 3:55 pm     Reply with quote

Hello, thank you for replying me.
I am getting confused a little bit right now.
I use 4Mhz crystal.
For example the following code works well (interrupt every 1 second):
The fuses are the same as in previuous code. In case the fuses are not correct (I mean the oscillator and its settings), this should not work, right?
Also as I mentioned in previous post I can see a tray notification about connected USB mouse (CCS mouse) - If the fuses are incorrect nothing (including USB descriptors) will be transfered from the device to a PC.
Its just mine opinion, but I am a newbie.
Thank you and Merry Christmas to everyone. BR M.

Code:

#include <18f2455.h>

//#include "main.h"
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN,NOPBADEN,WRTB,MCLR,NOCPD,NOWRTC
#use delay(clock=48000000)// full speed USB device
#use rs232(baud=19200,xmit=PIN_C6, rcv=PIN_C7, PARITY=N, BITS=8, STREAM=RS232)

// START OF bootloader definition
#define LOADER_END   0x7FF
#define LOADER_SIZE   0x6FF
#build(reset=LOADER_END+1, interrupt=LOADER_END+9)
#org 0, LOADER_END {} // nothing will replace the bootloader memory space
// END OF bootloader definition

#define TICKS_PER_SECOND 183 //183 how often per second is timerirq routine called

byte timing = 0;

#int_rtcc
void timerirq()
   {
      if(++timing==TICKS_PER_SECOND){fprintf(RS232,"irq2\r\n");
      timing=0;output_toggle(PIN_B0);}
   }

void main()
   {
      fprintf(RS232,"load\r\n");
      output_low(PIN_B0);
      set_timer0(0);
        setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
      enable_interrupts(INT_RTCC);
      enable_interrupts(GLOBAL);
      while(1);
         
   }
Ttelmah
Guest







PostPosted: Tue Dec 26, 2006 3:35 am     Reply with quote

OK.
First comment. If there was an existing thread, which led to the same problem, post your question on this, rather than starting a new thread. I have no idea, what settings, and answers were posted on other threads. Unlike you (the originator) I do not 'string' seperate threads together...
Now, the point about your settings, is that a couple of the fuses 'disagree', which worried me.
There are three actual 'clock routes' through the chip, to the USB driver, and a seperate pair to the 'master' CPU clock, and then two more that can be selected to feed the CPU itself. Now the CCS fuse settings, give no mention of the FSEN fuse, so hopefully this is being set automatically, when you select USBDIV, otherwise the clock selection as given, will actually be taking the CPU clock, not the required USB clock.
Then the master oscillator selection is wrong. At 4MHz, you should select 'XTPLL', not 'HSPLL'.
Now, on your 'blue screen', one comment leaps to mind. Are you sure that you are using the same 'generation' compiler, as the code you are using?. At odd times in the past, some of the demo codes have changed a little, and caused problems if loaded with a different compiler. The code certainly did run with the 'late' 3.2xx compilers, however I have not tried 3.242 (do you have 3.249?).
Have you tried with the example as given?. Your version, does not show the USB endpoint size defintins etc.. If you just use the supplied example, editing just the fuse selection line from the PIC18 20Mhz version, switching to XTPLL, and PLL1, this is all that should be needed to make it work.

Best Wishes
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Tue Dec 26, 2006 6:27 am     Reply with quote

The fuses are almost the same as in USB examples from CCS are (I mean files ex_usb_mouse.c, ex_usb_hid.c, ex_usb_kbmouse.c).
Therefore I think it is correct (except HSPLL=>XTPLL).
The only one version of the compiler, I have, is 3.242. All the examples came with the compiler and are in it's folder (C:Program Files\PICC\Examples).
I can't try it now, because I am away from my hardware. I will do so in January.
Anyway thank you very much for helping me out. Happy New Year, M.
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Mon Jan 15, 2007 4:02 pm     Reply with quote

ok, i investigated a little bit in HW layout and fixed some problems.
Then I tried to use the usb mouse example again with following results :
If I try a desktop pc and connect a PIC, it works (circles on a screen), but just for few seconds and then it disconnects. It sends following data to a serial line:
USB connected, waiting for enumaration...
USB enumerated by PC/HOST (circles are made in this step)
USB unenumerated by PC/HOST, waiting for enumeration...
USB disconnected, waiting for connection...

And if I connect a PIC to my notebook it does not work, just this being sent very fast:
USB connected, waiting for enumaration...
USB disconnected, waiting for connection...
USB connected, waiting for enumaration...
USB disconnected, waiting for connection... etc..

I also tried 24Mhz crystal with PLL6 fuse, but with no success:(
Does any one have clue what is the cause of it?
thank you very much, Best regards M.
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Fri Jan 26, 2007 4:13 pm     Reply with quote

Does anybody have any suggestion?
I am really crazy about the CCS compiler, because Microchip USB bootloader works well (I can read and write a hex into a PIC and after reset it works). But any USB device written in CCS C does not. I have already tried USB serial port example.
I have tried the source codes with/without the USB booloader. It is still the same.
Therefore I am pretty sure that problem is in CCS C compiler. As I wrote I have version 3.242 only.
Would anyone be so kind and help me to find out whether the problem is really in the CCS C compiler?
It would be great if someone compiles any of the USB examples (mouse/serial port) for a PIC 18F2455 (crystal 24MHz) in a higher version of the compiler and send it to me.

I really have no clue how should I continue.
Thank you very much,
Best regards Miroslav
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 26, 2007 4:34 pm     Reply with quote

I haven't done any USB projects yet on the PIC. I've have done USB
projects using a Philips USB hub chip and an Asix USB to Ethernet chip.
But neither of those chips required me to write any code. (Hint Mr. Green)

It's possible that I could try the CCS examples on Sunday. I have a
18F4550 and a PicDem2-Plus board which I could modify by adding a
USB connector to it.

What O/S are you using ? I only have Win98SE and Win2000 SP4.
If your "blue screen" problem is related to some PC driver issue
with XP or something like that, then I won't be able to test it.

All I can really do is, wire up my proto board, install PCH vs. 3.242,
compile and test the CCS examples.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sat Jan 27, 2007 8:07 am     Reply with quote

This is most likely a PC driver issue ( possibly the result of a bad descriptor being sent)
The descriptor sent when the PIC usb device is plugged in ( this assumes the hardware interface is correct D- D+ connections etc) cause the PC OS to go to the registry and look up the appropriate driver that is associated with that USB descriptor. The blue screen will often be a failure in loading the driver.
Drivers often will have debug and error information used during PC driver development that unless removed may cause freezes if the catch all error is triggered on another PC.
Look under device manager Universal Serial Bus Controllers
USB device and see if you have a caution flag.
Look in the registry to see if the descriptor you are using is registered.
Snoopy pro is a free usb packet sniffer take a look at the data exchange on the version and PC that you have working it might shed light on what is missing in your non working issues.
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Sun Jan 28, 2007 6:03 am     Reply with quote

Thanx to both for reply.
Sorry, I didnt mention in my post from Tue Jan 16, 2007 12:02 am.
After changing HW layout, I dont have the blue screen anymore.
But all simulated devices (USB mouse, USB ser. port) are disconnected as I wrote.
USB mouse works for few seconds and device is disconnected afterwards, on my notebook it doesnt work. USB serial port doesnt work on any PC.
I always get error debug messages (over rs232) as in the post from 16th Jan.
PCM programmer : it would be great if you try it for me. Would it be possible if you compile the USB mouse example in a different version of compiler (for 24MHz osc) and send it to me?

Thank you very much,
Have a nice sunday. M.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 28, 2007 9:37 am     Reply with quote

I don't want to email code to people. The only contact I want to have
is through the forum.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 28, 2007 5:42 pm     Reply with quote

I tried the ex_usb_mouse.c example. I used a 18F4550 on a PicDem2-
Plus board, and I added the resistors as shown in the example file.
It didn't work. I tested it with Windows 2000 SP4. I used PCH vs. 3.249.

When I plug it into the PC's USB connector, it displays a message box
that says:
Quote:

Found New Hardware
Unknown Device
Installing...

Then it displays a dialog box that says:
Quote:

Found New Hardware Wizard
Completing the Found New Hardware Wizard

USB Device

An error occurred during the installation of the device.
The installation failed because a function driver was not
specified for the device instance.

To close this wizard, click Finish.

According to CCS, this example is supposed to work "out of the box".
I suspect that they didn't test it on Win2000 SP4. I don't want to spend
any more time on it.
amcfall



Joined: 20 Oct 2005
Posts: 44

View user's profile Send private message

PostPosted: Mon Jan 29, 2007 8:44 am     Reply with quote

I have used the kbmnouse demo on 2K SP4 without any problems once I got the fuses set right. I vbelieve this was what I was using for a 4Mhz input w/ 48Mhz intertnal:

Code:
    #fuses XTPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN
    #use delay(clock=48000000)


Avery
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Tue Jan 30, 2007 8:49 am     Reply with quote

PCM : thank you for spending time and confirming my suspicion. Your posts help everytime (I dont mean just this thread). I use WinXP and the problem is the same.
I have just tried Microchip USB mouse example and it is enumerated correctly.
Therefore I am not ashamed to blame CCS for all the USB examples.
I spent many and many hours on finding out and debuging where could have been a problem. Now I know and I am disappointed.
Thank to everyone who participated.

CCS Technical Support does not monitor this forum on a regular basis. Please do not post bug reports to this form. All bug reports should be emailed to [email protected]. Thank you.
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