What's all this USART/RS232/USB Mumbojumbo?

Thread Starter

blah2222

Joined May 3, 2010
582
Hi,

In the past month I have covered the majority of the basic functions and utilities of my PIC18F45K20 and how to compile and program with the C18 compiler and MPLAB respectively, but I have yet to understand how communication works.

I bought the PICkit3 Debug Express development board and it has been a great help with learning how the PIC works, but it lacks any means of data transmission. I have read the datasheet and searched online for a nice and easy place to start with sending data between my PIC and my laptop, (MacBook Pro w/ Windows XP on VMWare Fusion), but all the types and protocols just confused me.

So I guess my main questions are:

1. What are USART/RS232/USB and how are they related or used together?
2. Am I able to just use C18 libraries for this?
3. What kind of components and hardware will I need if I would like to communicate with my laptop via its USB port?
4. Where can I find and extract this data coming into the laptop USB port? Do I need to use a program such as MATLAB?
5. And finally, is the process of sending data from the laptop through the USB to the PIC of the same difficulty?

I really appreciate the help!
JP
 

ErnieM

Joined Apr 24, 2011
8,377
So I guess my main questions are:

1. What are USART/RS232/USB and how are they related or used together?
2. Am I able to just use C18 libraries for this?
3. What kind of components and hardware will I need if I would like to communicate with my laptop via its USB port?
4. Where can I find and extract this data coming into the laptop USB port? Do I need to use a program such as MATLAB?
5. And finally, is the process of sending data from the laptop through the USB to the PIC of the same difficulty?
1:
A USART is the hardware that makes up a serial data stream, both outgoing and incoming. That stream is on the PIC output pin, and while the correct data, it is not the correct voltage levels for RS-232. You would need to add an IC to do that conversion.

USB is something separate altogether. The PIC can generate USB signals directly, so all you need is the proper connector (B type) hung on your PIC. MC provides free libraries for many USB functions that you can use to get up and running fast.

2: Yep. (That was easy)

3: See #1. Depending on the PIC you may also need a resistor, and your clock needs to be fairly accurate. While I have used successfully used resonators for this in the past a crystal is recommended for any "real" product.

4: That depends on how your device will look to the PC. Think of all the things you can plug into a USB: thumb drives, mice, keyboards, serial port emulators, etc. Each needs a driver on the PC end, but many of these types that drive ships inside of Windows.

A serial port on a PC connects to an RS-232 device. Now that these ports are getting left out of PC and laptops it is common to replace them with a USB device. Good news here is Microchip has an example application to make the PIC look like a serial port. Windows has that driver, it even has the program (Hyperteminal) to view data, but there are better and free programs out there.

Just about any windows programming language can use a serial port; VB, VC (now both free downloads), Labview, and the like.

5: Nah, it's easy.
 

Thread Starter

blah2222

Joined May 3, 2010
582
Thanks for the replies!

Ernie, I remember you told me about this serial/USB demo that Microchip had. I downloaded that package off the website, but I'm not really sure what to do with it. Were you talking about the MCHPFSUSB v2.9?

It seems like the Library Help guides you partially through the demos, but they specify that they want you using a PIC-USB development board. Do you have any recommendations for which would be a good investment, or is there a way I could just wire up my PIC18F45K20 development board to a USB socket?

Thanks again,
JP
 

ErnieM

Joined Apr 24, 2011
8,377
It's part of the Microchip Application Libraries. Look for the "Device - CDC - Serial Emulator" project. That one sets up the USB and the UART so the PIC looks like a USB to the computer but an RS-232 to the outside world.

Now on first appearance the project seems HUGE. Well, it is, but you don't have to be familiar with most of it. Just look inside the main(void) function> there lives InitializeSystem() and ProcessIO() function calls, and it is within those two functions you can do all your custom stuff.

That app also flashes some LEDs you may not have. I added them once and it gives me a warm fuzzy when debugging.

Unfortunately, the PIC18F45K20does not have a USB function.

I have a breadboard here I built just to check out some USB to serial stuff using two PIC18F14K50. You send stuff to one and it came back on the other, and vice versa. The parts on it are just:

2x PIC18F14K50
2x 20 pin DIP sockets
4x caps (2 for bypass, 2 for USB voltage on chips)
2x resistor (USB pull ups)
2x 12MHz resonators
2x USB mini B connectors
1x 6 pin connector (for PicKit) (only 1 socket was programmable so I would switch em over)

Power came over the USB.

USB is really simple on these things, hardware and software.
 

Thread Starter

blah2222

Joined May 3, 2010
582
Cool, I'll check out that PIC. So does that mean that there is no way to transfer information through a USB a laptop through my 18F45K20?
 

ErnieM

Joined Apr 24, 2011
8,377
Yes there is, just not directly. It will need some more hardware. I can think of 2 ways offhand. Both ways use the USART that your PIC has to send & receive data.

First is to use an external RS-232 to USB translator (one example). But to drive this you need an RS232 transceiver chip to convert the logic levels to RS232 levels. Either build your own or you can get a prebuilt module from someone (one example).

Other way is to build your own RS-232 to USB translator similar to what I did with the PIC18F14K50. That way you don't need the RS232 transceiver as you are taking a short distance in logic level signals.
 
Top