Atmega8 USB TTL-Serial Converter
This is yet another software/firmware pair for my basic Atmega8 USB board.
It provides serial communication at TTL levels over USB. Unlike other
converters, it doesn't register as a serial device with the operating
system.
I made this for two reasons. First, I needed one and shipping takes
too much time for me. So, I just made it in like half a day.
Second, the Linux kernel can't handle the bit rate 76800 over a serial
link. The corresponding ioctl value is simply missing from the system
headers. Maybe there is some other way to do it, but I can't find it.
This bit rate is important for me since it's used by ESP8266 to display
boot messages. This chip (usually, depending on the firmware on it)
starts up and displays boot messages at this bitrate (some people say
it's 74800 but that's just an approximation to 76800, using a 12Mhz clock
for USB). After that, it
switches to 115200 bps or whatever you have set previously with the
AT+CIOBAUD command.
The boot messages are useful for two things: they contain the cause
of the reset (useful for identifying power problems) and the boot mode.
The boot mode tells us whether the settings on other pins such as GPIO0
etc are correct. If they are not correct, the module boots up in
firmware programming mode, which is not what I want.
Anyway, the module works with a special software called serterm.
That is explained below.
The Host Program: serterm
This program simply copies whatever you type to the board, which
then sends it out from the serial TX pin. This is a line based
program, it doesn't do anything until you end the line with
the enter key.
You can also give commands to the terminal program or the USB device.
If a line starts with the character '#', then the next character is a
command code. The following commands are recognized:
- Q
- Quits the program cleanly. This is the only way to do it
properly.
- L<linecode>
- Changes the end of line characters sent
to the device: d(OS) = \r\n, u(NIX)= \n and w(EIRD) = \r.
- ?
- Displays the serial comm settings.
- B<rate>
- Changes the bitrate for serial communication.
- P<parity>
- Changes the parity setting for serial comm.
0= none, 1= odd, 2= even.
- M<stopbits>
- Sets the number of stop bits. Can be 1 or 2.
- H
- Turns on hexadecimal mode. In this mode, received data
is immediately displayed in hex format, without buffering.
- h
- Turns off hexadecimal mode.
should reply immediately with the string "UsbTErm".
- S
- Displays the queue pointers on the USB device. I used
it for debugging, but left it in place.
- R
- Empties all buffers on the USB device, in case it goes
haywire.
- K
- Displays all buffered data received from the MCU.
Normally the application buffers data until it receives a newline
character ('\n'), then the whole line is displayed at once. This
command displays the data buffered so far, but doesn't flush the
buffer.
- T
- Sends a test command to the board. The response
should be "UsbTErm". This is useful for testing the USB connection
if the board seems to stall.
- X
- Turns on high-bit stripping mode. I used it for
debugging, but left it in place.
- x
- Turns off high-bit stripping mode.
The Firmware
This is a pretty straightforward implementation based on V-USB.
The device simply forwards data back and forth over the USB and
serial interfaces. There is nothing special really.
Downloads
Here is the source code:
- 1.0
- The initial version.
See my page about
usbterm for more information
about the circuit and how to use it under Linux.