For some of my PIC projects I need a serial (RS232) interface to print some messages on the screen of my computer. I still have a desktop computer that has one RS232 interface but nowadays most computers have a USB interface instead. You can buy devices that convert – TTL – RS232 signals to USB for which several projects have already been published on Instructables but I decided to build one myself. The reason for that is that I like building stuff but also that this version does not need a special driver for Windows 10 since it uses a standard Microchip device descriptor which is already supported by Windows 10.
As you may know you cannot use TTL signals to drive an RS232 interface so I also created an RS232 board based on the MAX232 chip that converts the signals to the right level. In this Instructables I have also posted the schematic diagram of the RS232 board since I used it for testing my USB to Serial TTL converter.
I used a PIC 16F1455 as device to control the USB port and transfer all data from USB to serial using the JAL programming language.
Step 1: The Electronics
You need the following electronic components for this project:
- 1 PIC microcontroller 16F1455 with socket
- Ceramic capacitors: 1 * 470 nF, 1 * 100nF, 2 * 22 pF
- 1 crystal 12 MHz
- 1 Electrolytic capacitor of 10 uF/25V
- Resistors: 2 * 10k, 3 * 330 Ohm, 2 * 22 Ohm
- LEDs: 1 Amber, 1 Yellow, 1 Green
- 1 USB connector
- 2 Jumpers
- 1 header, 4 pins
You can build the circuit on a breadboard, as shown in the picture. The circuit is powered by the USB connection. I used the USB 5 Volt for powering the RS232 board.
Step 2: The Software
The software performs the following tasks:
- Handling the USB interface. For this I used a standard JAL USB serial library
- After the USB to Serial TTL converter is configured, the yellow LED will be turned on
- When a character is received from the USB it is copied to the serial interface
- When a character is received from the serial interface it is copied to the USB
- Each time a character is received from either side, the green LED is turned on shortly to indicate data is transfered
- Set the baudrate of the serial interface using the jumper settings. The baudrate can be changed at any moment
Before the USB interface can be used it has to be configured by the host computer. This is done by setting the right serial parameters in the terminal emulator program on the PC and enabling RTS/CTS flow control. The baudrate of the USB interface can be set to any value while the baudrate of the serial interface is determined by the jumper settings. Note that both baudrates do not need to be the same.
The JAL source file and the Intel Hex file for programming the PIC are attached.
Step 3: The Final Result
For this demo I connected the USB to Serial TTL converter to my RS232 board. Reason for that is that I can then show the operation on my desktop computer that has both a USB port and an RS232 port.
In the video you see 2 terminal emulator windows open. The left window shows the data on the RS232 port while the right window shows the data on the USB port. For the RS232 port no flow control is needed. For the USB port, the USB to Serial TTL converter is configured by enabling the RTS/CTS flow control after which the yellow LED will turn on.
Note that for this demo I used a baudrate of 9600 baud for the RS232 port and a baudrate of 115200 if the USB port.
Read more: USB to Serial TTL