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

Tricky USB code (CCS RS232 DEMO)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
L.Belanger
Guest







Tricky USB code (CCS RS232 DEMO)
PostPosted: Fri Sep 21, 2007 4:38 am     Reply with quote

Hi,

it's me again =)!! , ok now with the help of Ttelmah in the past see topic
w w w.ccsinfo.com/forum/viewtopic.php?t=32135

now i've got a bigger problem , believe it or not ... my USB device / Code stopped working today (after 3 day) for unknown reason. i'm now getting the usb device not recognized error in XP. So i had thought that maybe my 2550 is dead... changed for another then flashed it ... worked !!! then after a code change (nothing big ... just adding fprint sentences) i've got the same error in XP ... so i reverted the code ... then reflashed it to test ... nothing good ... tryed another 2550 , then another ... i decided to port the code to a 4550 ... same error... changed the Xtal (maybe something happened) nothing so far !! :( Please help

here's the current code:


Code:


#include <18F2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL3,CPUDIV1,VREGEN
#use delay(clock=48000000)
#use  standard_io(A)

#include <usb_cdc.h>

char string[6];

void main(void) {


usb_cdc_init();
usb_init();


while (TRUE)
   {
   usb_task();
   if (usb_cdc_kbhit())
      {
      get_string_usb(string,6);
        if (string[0] == '1' )
            {
            printf(usb_cdc_putc,"\r\nIt WORKS!");
            }
        else
            {
            printf(usb_cdc_putc,"\r\nWrong Command: %s",string);
            }
      }
   }
}


Xtal = 12mhz
MCLR = 10K pull up
vUSB Cap = 330nF (tryed 430nF also ... same thing) @ 3.29V


Note: tryed with a delay_ms(1000); before
usb_cdc_init();
usb_init();
to see if it helped ... not really :(


Spend nearly the whole day to trying to debug the device

i heard the usb is very hard correct problems & very tricky before... know i understand what they had meant grrrrrr lol

Also tryed multiple ports + changed computer to see ,,, same thing :'(
Checked cables & wirings many times ... tryed around 6 2550's & 1 4550
Double verified with 2 device programmer (Winpic800 + Win Pic) all OK.

L.Belanger
L.Belanger
Guest







PostPosted: Fri Sep 21, 2007 4:53 am     Reply with quote

Ok now tryed with this code

the led flash like it suposed to be

BUT when the usb was working (few days ago).. i tryed exactly the same code as above... the usb was initialized but the led hang at the line
Output_HIGH(PIN_A0);

so normaly the code should hang at Output_HIGH(PIN_A0); ??? no

/me confused !!!

Code:

#include <18F2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL3,CPUDIV1,VREGEN
#use delay(clock=48000000)
#use  standard_io(A)

#include <usb_cdc.h>

char string[6];

void main(void) {


usb_cdc_init();
usb_init();


while (TRUE)
   {
   usb_task();
   Output_HIGH(PIN_A0);
   Delay_ms(500);
   Output_LOW(PIN_A0);
   Delay_ms(500);
   }
}
L.Belanger
Guest







PostPosted: Fri Sep 21, 2007 4:57 am     Reply with quote

maybe its the PCWH C Compiler that decided give me hard time ... seriously i don't where to start looking for problems :S
L.Belanger
Guest







PostPosted: Fri Sep 21, 2007 6:18 am     Reply with quote

Now i'm tired ... putted a big Low-ESR capacitor (Samxon good quality) 1500uF 6.3V on the 5V usb power ... OMFG it works !!! for the moment :P
Guest








PostPosted: Fri Sep 21, 2007 6:39 am     Reply with quote

Man.. you are acalling usb_task() once every second with the code above... I would be surprised if it worked. Use a timer to blink the led. You must understand the limitations of the code.
Ttelmah
Guest







PostPosted: Fri Sep 21, 2007 9:08 am     Reply with quote

Aargh.
First comment. You are still making the same mistake about string lengths...
You _must_ have one more character of storage assigned in the string declaration, than the number of characters you allow usb_cdc_get to fetch.
Second comment. Try ignoring the USB. Can you flash the LED reliably then?. If not, look at how the LED is connected (what value are you using for the current limiting resistor, what supression have you got on the PIC's own supply?).

Best Wishes
L.Belanger
Guest







PostPosted: Fri Sep 21, 2007 12:44 pm     Reply with quote

1.
Quote:
4) You are assigning 4 characters of storage for the 'string'. This is not enough. A 4 character 'string', requires _5_ characters of storage (one extra for the terminating '\0'). This will result in overflows.


i'm using only 1 character of 7 ... i thought that would give me enough space to store extra characters (those invisibles) seriously ... i can't see whats needing more than 7 char for a 1 char command ??

2.Yes it was the usb only , i was able to flash the famous LED :P
used 1K for a 2.7V led more than enough to be safe ;)

Code:
what supression have you got on the PIC's own supply?


nothing really it was straight plugged from the USB +5V Rail (i knew it wasn't good but at start i was worried about putting a too big caps that would keep the pic running when i unplug the usb & replug for 2-3 seconds)

have a good day

l.Belanger
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Sep 21, 2007 1:26 pm     Reply with quote

Quote:
i'm using only 1 character of 7 ... i thought that would give me enough space to store extra characters (those invisibles) seriously ... i can't see whats needing more than 7 char for a 1 char command ??

Code:
char string[6];

This allocates storage for 6 chars - so if you want to store a string of 6 chars length you need

Code:
char string[7];


as Ttelmah is trying to tell you Smile
So your call to
Code:
get_string_usb(string,6);

will overwrite something in memory - maybe not a problem now but will be when you add more variables!
L.Belanger
Guest







PostPosted: Fri Sep 21, 2007 1:31 pm     Reply with quote

oh i see... thx for the clarification SET Embarassed
corrected right away!!
Ttelmah
Guest







PostPosted: Fri Sep 21, 2007 2:45 pm     Reply with quote

Add some suppression at the PIC. A 0.1uF capacitor, right close by the chip, and perhaps something like 1uF where the USB supply comes onto the board. You are not looking for caacitance to hold the rail up for a long time, but something to suppress the tiny short spikes that the PIC itself will generate, as things like the LED are switched on/off.
I see SET has already answered the other bit.

Best Wishes
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