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

I need your advices about USB

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



Joined: 20 Feb 2008
Posts: 33

View user's profile Send private message

I need your advices about USB
PostPosted: Fri Apr 18, 2008 5:54 am     Reply with quote

A person gives me a circuit board using microcontroller 18f2550, its task is display the variable voltage on LCD, it 's ok, now he let on it a USB gate also and ask me to display those voltage value on computer screen.
If you in this case, what is the sequence of your solve way ?
What is the information that I must note for my job ???
Thanks so much !!!
Matro
Guest







PostPosted: Fri Apr 18, 2008 6:30 am     Reply with quote

- Globally understand USB communications
- Read and understand USB HID specifications.
- Implement USB HID communication on PIC (examples exist on the web)
- Implement the host application (in .NET - VB or C++ ; there are some libraries implementing USB HID that you can download for free on the web)

Matro.
smiles



Joined: 20 Feb 2008
Posts: 33

View user's profile Send private message

PostPosted: Sun Apr 20, 2008 8:07 am     Reply with quote

USB drivers are for familiar devices like keyboard, mouse ... do I need to write a new driver for my circuit board ?
If yes, how can I do it Confused
Thanks !!!
Matro
Guest







PostPosted: Mon Apr 21, 2008 1:29 am     Reply with quote

smiles wrote:
USB drivers are for familiar devices like keyboard, mouse ... do I need to write a new driver for my circuit board ?
If yes, how can I do it Confused
Thanks !!!


The best is definitely to use the HID driver that is some kin of a "universal" one.
It basically contains a parser and a report formater that are able to understand every kind of communication since that it's you that describe it.
For information, keyboards, mouses, ... uses the same driver that is the HID driver.
Have a look at the specific HID specification and see if it fits with what you need (I think it does).

Matro.
Ttelmah
Guest







PostPosted: Mon Apr 21, 2008 2:10 am     Reply with quote

The easiest to program, and probably the commonest (provided you don't need large amounts of data), is to use the CDC class, and make the device emulate a serial port. Examples of this are in the CCS code, together with the needed .inf files for the PC end, and then the code at the PC, can just talk to it as a com port.

Best Wishes
smiles



Joined: 20 Feb 2008
Posts: 33

View user's profile Send private message

PostPosted: Fri Apr 25, 2008 9:36 pm     Reply with quote

Thanks both, I got your ideas.
Uhm ... I wonder what is the difference of transfering data via USB port and vituarl COM port Confused
And which mode should I choose:
• Isochronous: This type provides a transfer
method for large amounts of data (up to
1023 bytes) with timely delivery ensured;
however, the data integrity is not ensured. This is
good for streaming applications where small data
loss is not critical, such as audio.
• Bulk: This type of transfer method allows for large
amounts of data to be transferred with ensured
data integrity; however, the delivery timeliness is
not ensured.
• Interrupt: This type of transfer provides for
ensured timely delivery for small blocks of data,
plus data integrity is ensured.
• Control: This type provides for device setup
control.
Thanks !!!
Matro
Guest







PostPosted: Sat Apr 26, 2008 10:33 am     Reply with quote

If you choose to use HID then the transfer will be in interrupt mode.
The control mode is mainly used for endpoint 0 that is mandatory with each USB device.

Matro
smiles



Joined: 20 Feb 2008
Posts: 33

View user's profile Send private message

PostPosted: Sun Apr 27, 2008 8:58 am     Reply with quote

Thanks ... but I just test the circuit, connect USB cable between that circuit and USB port of PC but the "Add new hardware" dialog doesn't appear Confused (instead, texts on LCD appear, my circuit use power supply of PC via USB port)
Is the problem lie in pic18f2550 ? I mean that PIC at the moment just contain code to display text on LCD, does it lack firmware ?
Thanks !!!
Ttelmah
Guest







PostPosted: Sun Apr 27, 2008 10:20 am     Reply with quote

Yes.
You won't get 'add new hardware' displayed, till the PIC contains USB code. Read some basic USB books. Basically, the hardware (programmed by the two resistors on the USB lines - you can use external ones, or there are some already in the PIC, that have to be enabled), programs what speed is to be used. Then the Master device effectively asks 'who are you', and the code in the device, has to reply, giving a packet describing itself. The data in this packet, is what the USB stack, uses to search it's drivers for a suitable 'fit'. The 'add new hardware' message, only appears after this transaction has been completed. You have to have a working USB device, for it to be seen.

Best Wishes
smiles



Joined: 20 Feb 2008
Posts: 33

View user's profile Send private message

Setup for USB interfacing
PostPosted: Sun Apr 27, 2008 11:19 pm     Reply with quote

Hi do a search and read
http://ccsinfo.com/forum/viewtopic.php?t=29978&highlight=full+speed&sid=51b1db13c53afeac5e44386e5896f1cb
http://ccsinfo.com/forum/viewtopic.php?t=31879&highlight=usb+pic18f2550&sid=3d48231c1a4001f14bf74487441579d1

My circuit use 12Mhz external crystal, VUSB pin connect via 10uF to ground, D+ and D- have no connect to 1.5kOhm to Vcc then I think I must setup it inside Pic
I delete all the code that make texts appear on LCD, leave code for USB only (I mimic ex_usb_serial.c) Smile

Code:

//set to 1 to use a PIC's internal USB Peripheral
//set to 0 to use a National USBN960x peripheral
#define __USB_PIC_PERIF__ 1
#if !defined(__PCH__)
 #error USB CDC Library requires PIC18
#endif
#if __USB_PIC_PERIF__ && defined(__PCH__)
 #define USB_CON_SENSE_PIN PIN_B2
#endif
#include <18F2550.h>
#fuses HS, PLL3, CPUDIV1, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=48000000)
//Here is what I read from above links :
//if you want to use integrated USB your cpu should
// run at 24MHz(low speed) or 48Mhz(high speed).
//I use 12Mhz crystal, PLL3 -> 4Mhz than multiply to 16 = 96MHz
//(4x16=96 ???)
// USBDIV -> 48Mhz
//CPUDIV1 -> 48MHz then we have delay(clock=48000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <usb_cdc.h>
void main()
{
   setup_adc_ports(ALL_ANALOG|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_16);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_oscillator(False);
usb_init_cs();
while (1)
{
}
}

It warns: Interrupt disabled during call to prevent re-entrancy (usb_token_reset)
and variable never used USB_CLASS_DESCRIPTOR
and no "add new hardware" appears Confused
Where I am wrong ?
Thanks !!!
Matro
Guest







PostPosted: Mon Apr 28, 2008 1:31 am     Reply with quote

Of course! "Add new hardware" will appear after some data exchange between device and host. The device has to be enumerated correctly for that.
You will need at least some code concerning USB communication to see the "Add new hardware" popup.

Matro.
smiles



Joined: 20 Feb 2008
Posts: 33

View user's profile Send private message

PostPosted: Mon Apr 28, 2008 7:01 pm     Reply with quote

hum ... I test it but not work, I know my coding is completely new to USB part so error is certainly, I need to read the datasheet as much as possible Rolling Eyes
Now I want to ask, if you use external crystal 12MHz, what is the meaning of this declaration: #use delay(clock=48000000) , does it concern to 12MHz
I seem to be confused between these two frequency Confused
Thanks !!!
Ttelmah
Guest







PostPosted: Tue Apr 29, 2008 2:47 am     Reply with quote

The way the oscillator works on these PICs is complex...
Basically, there is an internal *12PLL, which is fed from the external crystal, _after_ the first programmable divider stage. You correctly have this set to /3 (PLL3), which gives the 4MHz into this. The resulting frequency, is divided by two, and fed to the USB (this is done to ensure that both half cycles are symmetrical), and to the CPU divider. Your frequency setups are OK.
What is 'missing', is the voltage to drive the USB. You _either_ need an external 3.3v regulator, or the VREGEN fuse (which turns on the internal regulator). You also _must_ have the smoothing capacitor present on the Vusb output pin.

#fuses HS, PLL3, CPUDIV1, NOWDT, PUT, BROWNOUT, NOLVP, VREGEN, USBDIV, PUT, NOXINST

The last couple, are just to help the chip wake up reliably, and ensure the extended instruction mode is disabled.

Best Wishes
smiles



Joined: 20 Feb 2008
Posts: 33

View user's profile Send private message

PostPosted: Thu May 01, 2008 9:27 am     Reply with quote

Hi I found this in datasheet, I see the order to get 48Mhz has HSPLL, you use HS,PLL3, are they the same ? and does CPUDIV1 in CCS mean CPUDIV1:CPUDIV0 = 0:0 Rolling Eyes
Thanks !!!
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