Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C++ Builder and USB<->RS232

Status
Not open for further replies.

Sling

New Member
Hi I am trying to make an application with C++Builder which communicates with a PIC16F877A which has a RS232 interface. Unfortunately my computer only has USB ports so I have bought a USB to RS232 converter cable.

Well I am a complete beginner to C++ Builder so really at this point I don't even know it will be possible to do this... Any help and advice would be really appreciated.
 
You use a UART-USB FTDI cable (yours might be similar, I don't know). ANd just program the PIC like you would normally using a UART. THe PC needs virtual COM drivers which make a USB appear as an RS-232 port and program the PC software the same way.

So basically you're really using a USB cable but it looks like you're using a UART/RS232 from the PC and the PIC.
 
So to code it, I do the same as if my computer has an RS232 connection?

Thanks dknguyen.

BTW I don't suppose anyone knows of a good tutorial for this type of application? I can find plenty of snippets of code on the internet but I'm not completely sure how to apply them and I'd like to understand them better anyway.
 
Last edited:
Pretty much. Just make sure you have the USB driver installed for the cable that makes the USB port appear as a Virtual COM port (RS-232). On the PIC side it's just a UART so you just program the PIC firmware with that.
 
What tutorial are you looking for?
I see no problem you have to face in your setup. The PC SW will know nothing about nature of RS232 port it will use. It can be a real RS232 or Virtual one via USB adapter unless you are using real time bit banging with pins of RS232 port. If you are just sending data bytes there should be no difference between UART based or Virtual COM port.
 
I need a tutorial for this specific task for beginners. I still don't really know how to even get started with this. I can write in C (even better in Verilog) but I'm completely new to C++ Builder and working with GUI's.

I've considered using a component to make life easier, such as a trial of Comport v3.4 by Winsoft, but I have no idea how to use it. I only know how to drag it to the form and sit there looking at it lol. I've also tried Tcomport but it wouldn't install correctly, not that I'd know how to use it anyway.

The problem is this isn't covered in any books or tutorials. I have been searching the internet for days, I've bought a book and gone to the library but I can't find anything that helps me.

It's easy enough to write an application that does something for which there a chapters in every book you buy for C++Builder, or on every website, but unfortunately this task isn't in that category I've found.
 
Last edited:
Hi,
I still do not get what is the task and what is the final goal of your project?

Is it communicating with PIC from PC via RS232?
In this case why should it be C++ Builder and why should you write any SoftWare at all?
 
Hi,
I still do not get what is the task and what is the final goal of your project?

Is it communicating with PIC from PC via RS232?
In this case why should it be C++ Builder and why should you write any SoftWare at all?

I need a GUI that communicates with the PIC via RS232, yes. Basically it's for an experimental control system for a test wind turbine. Two-way communication between the PIC and the GUI will be necessary as the final design will involve a database display and actuators.

There's no reason why it has to be C++Builder I suppose, and if there is an easier way to get this working I'm all ears.
 
Last edited:
Here is the easier way:
SUB-20 Multi Interface USB Adapter USB to I2C SPI GPIO RS232 RS485 Ir

This board is USB to RS232 (and SPI,I2C,...) adapter.
You connect it to the PC USB port and take it's RS232 output and connect it to PIC.
SUB-20 software has a GUI utility to send and receive data via RS232

BTW there is a chance you will not need PIC at all. Look over SUB-20 interfaces and perhaps it will totally suite your needs.
All of the interfaces are controlled via GUI application.
 
is it possible to have a link to the cable you brought. When you plug it in you computer will make a noise saying its plugged in. If you go to the device manager in windows under COM/LPT ports your device should be there as a COM port. You will probably want to write down the COM port number so you can remember it at a later date. I cannot help you further along the host application writting more than the fact that your device will now appear as a COM port just like any other Serial port.

To test out your device open up hyperterminal in the communication sub-directory of accesories and open up a connection with the COM port that came up in device manager. set the vales to 8 bits, no parity, no hardware flow control, and 9600bps. get a wire and short pins 2 and 3 of the COM port and start typing data into the window. what you typed should now be on the window. just to check take out the wire and the data should stop comming on your screen. I however am not responsible for you accidentally plugging in the wire into the wrong pins and frying it. it shouldnt happen anyway.

The PIC'S RS232 port is only 5v tolerant but the adapters port will be +-10v. you will need to build a logic level converter using either a **broken link removed** or one of these right down at the bottom. this will convert the levels so the PIC can communicate with the adapter you have brought

Look into google for pinouts of the serial port and also there are many schematics on how to connect your device to the serial port.

Dave
 
Yes, it's just a cheap one, a Logilink AU0002B.

**broken link removed**

Some very good suggestions there, thanks for that. Well I'd already got the converter working to program a PIC with Tinybootloader, so the cable itself seems to work ok. I'll keep your debugging procedure in mind if I get any problems though.

My bigger concern was how to program the GUI so that it will communicate with the PIC correctly - this area is all new to me and I didn't know how if I'd need to program it differently due to the converter. Anyway, after further research I've decided to use an MFC application with Visual Studio in C++ which I have installed at my university computer. Along with this for the serial connection :

CSerialPort v1.03 - Serial Port Wrapper - CodeProject

And as I'm now going to use the university computer I don't actually have to worry so much about the converter, as that desktop has an RS232 connection.

Still, I love the idea of shorting the RS232 pins to test whether it's working. Yeah would have to be careful not to connect the wrong pins though lol.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top