|
|
View previous topic :: View next topic |
Author |
Message |
L.Belanger Guest
|
Tricky USB code (CCS RS232 DEMO) |
Posted: Fri Sep 21, 2007 4:38 am |
|
|
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
|
|
Posted: Fri Sep 21, 2007 4:53 am |
|
|
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
|
|
Posted: Fri Sep 21, 2007 4:57 am |
|
|
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
|
|
Posted: Fri Sep 21, 2007 6:18 am |
|
|
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
|
|
Posted: Fri Sep 21, 2007 6:39 am |
|
|
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
|
|
Posted: Fri Sep 21, 2007 9:08 am |
|
|
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
|
|
Posted: Fri Sep 21, 2007 12:44 pm |
|
|
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
|
|
Posted: Fri Sep 21, 2007 1:26 pm |
|
|
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 ?? |
This allocates storage for 6 chars - so if you want to store a string of 6 chars length you need
as Ttelmah is trying to tell you
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
|
|
Posted: Fri Sep 21, 2007 1:31 pm |
|
|
oh i see... thx for the clarification SET
corrected right away!! |
|
|
Ttelmah Guest
|
|
Posted: Fri Sep 21, 2007 2:45 pm |
|
|
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 |
|
|
|
|
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
|