How To Build A USB Device With A PIC 18F4550 or 18F2550
How To Build A USB Device With A PIC 18F4550 or 18F2550
How To Build A USB Device With A PIC 18F4550 or 18F2550
Electronicfr in english
Linux on Fujitsu stylistic 1200 How-to build a webserver for 30Euros with
ENC28J60
A little autonomous robot A new autonomous robot project (V2) How-to build a usb device a with 18F4550
or 18F2550
Electronicfr en francais
Overview
PIC 18F4550 and 18F2550 are powerful microcontrollers including a full-speed USB V2.0 compliant interface. With these MCU it's very easy for the hobbyist to design USB devices with very few components. In this page, I will describe how to use the CDC firmware from Microchip. It permits to emulate a serial port with a PC running Windows or Linux. It's also very easy to build HID devices.
Un petit robot autonome picbasic 3B Un nouveau robot autonome PIC Construire un priphrique USB avec un PIC
18F4550 ou 18F2550
www.policefr.com
The following schematic is very simple, only few components are needed. It's a self powered USB device. Please note I'm using the Olimex tiny-ICSD programmer, if you want to use another PIC ICSP programmer, you should remove D1 and D2 and change the connector
(You can click on the picture to get an high resolution picture) This device is compatible with the microchip USB bootloader Please note C5 is 470nF (the datasheet recommend 220nF but more is better) and should be low ESR (for example a multi-layer ceramic). Don't forget the 100nF decoupling caps. Here is a possible implementation
Click on the picture to get a 300dpi PCB You can look at the wire's colour of your USB cable: Black=GND, Red=+5V, Green=Data+, White=Data-
The software
You can download MCHPFSUSB_Setup on the Microchip website. It's a windows .exe :(. The firmware we will use is written in C (for the C18 Microchip compiler). This code is (royaltyes) free, but it's not a free software, so it's not possible to redistribute modified source code In this archive, you will find:
q q q
q q
The USB bootloader and its source code in C18 A windows utility for the bootloader The CDC firmware source code (serial emulation) in C18. It can be used with the USB bootloader without modification Another firmware for the HID device A windows driver for CDC (under linux CDC-ACM is natively supported)
Some tips for your prototypes: Source code is in the fw/cdc/MCHPUSB.mcw directory You should comment the following lines in usbcfg.h for a self powered usb device:
You can put your own code on user.c. For example, look at Exercise_Example() in user.c. Useful functions are getsUSBUSART() (get data) and putrsUSBUSART() (put data other the serial port) Don't forget to check mUSBUSARTIsTxTrfReady() before to send data. They are some examples in the exercise directory. For example, the following program (to put in user.c) toggle the LED number 4 when you press the key "1" in the terminal They are some examples in the exercice directory. For example, the following program (to put in user.c) toggle the LED number 4 when you press the key "1" in the terminal
If you don't want to use the bootloader, you must remove the vector remapping section in main.c and change the linker script (look at important.readme.txt in the sources directory)
PIC and USB - French version/Version franaise - Forum: Microcontrollers and usb
Electronicfr in english
Linux on Fujitsu stylistic 1200 How-to build a webserver for 30Euros with
ENC28J60
A little autonomous robot A new autonomous robot project (V2) How-to build an usb device with 18F4550 or
18F2550
Electronicfr en francais
Un petit robot autonome picbasic 3B Un nouveau robot autonome PIC Construire un priphrique USB avec un PIC
18F4550 ou 18F2550
www.policefr.com
The firmware
We will add some code for analog to digital convertion and temperature calculation in the file user.x
//Lets add includes for ADC and strings manipulations #include #include #include //[...] // We will write output data in this string char input_buffer[64]; // [...] void Exercise_Example(void) { int temp; // [...] else if(start_up_state == 3) { if(mUSBUSARTIsTxTrfReady()) { //A0 set in input TRISAbits.TRISA0 = 1; memset(output_buffer, '\0', 64); output_buffer[(6*5)] = '\r'; output_buffer[(6*5)+1] = '\n'; OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_0_TAD, ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011); SetChanADC(ADC_CH0); Delay10TCYx( 50 ); ConvertADC(); // Start conversion while( BusyADC() ); // Wait for ADC conversion temp = ReadADC(); // Read result and put in temp CloseADC(); // Disable A/D converter temp=temp/7; //Convert in centigrad degrees
// Convert to a
How to use a 18F2550 You can use the source code for 4550 with very few modifications. Just select the appropriate device in the MPLAB configure menu. Change the linker script, and set the configuration bits (like in this picture). Remove any references to port D in io_cfg.h. Here is a picture of a small prototype using PIC 18F2550:
Getting help
Ask your question to the electronicfr community http://www.electronicfr.com/forum/phpBB2/viewforum.php?f=1.
Disclaimer
ANY CONTENT ON THIS WEBSITE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Next
Soon, you will find a schematic for a USB to serial (RS232) converter.