The serial programmer you are using is using serial port to connect to computer, but not the standard RS232 protocol! Take a closer look at the schematic:
- pin 4 (DTR) is assigned to MOSI. On a true motherboard serial port this pin can be toggled high and low, thus emulating a bitbang mode
- pin 6 (DSR) and 7 (RTS) are asigned to SCK. As DTR, RTS can be set either high or low, thus along with DTR allowing software implementation of custom synchronous serial protocols
- pin 8 (CTS) is an input pin assigned to MOSI. Its value is read on SCK toggle.
DTR and RTS are the only pins of the serial port that can be bitbanged. But there is the need for a reset signal. The designer of that adapter uses a trick. He sends a 0x00 character with no stop bits over standard RS232 TX, thus creating a short reset pulse (which for some MCUs need to be inverted).
The actual data on a standard serial RS232 communication is actually sent only via Rx/Tx lines. All the others are accessory lines used by devices to signal different states of operation or to signal data availability or transfer termination.
This is the problem with USB-serial adapters. Most of them can only use Rx/Tx lines and of course, only serial RS232 (asynchronous) protocol, which is by no means compatible with AVR programming protocol (SPI, synchronous). So the only way to communicate via serial port by SPI is to use alternate lines and emulate the protocol in software.
You can see on this forum that in some cases it works with USB-serial adapters, but in most situations it doesn't.
I thought most or all of the microcontroller of ATmega series microcontrollers are without usb support.
What do you say about: ATmega 8U2, 16U2, 16U4, 32U2, AT90USB1286, AT90USB1287, AT90USB162, AT90USB646, AT90USB647, AT90USB82. Full list from here.
But USBasp is not using one of those MCUs! Looking at its schematic we can see that it uses a pull-up resistor on the D- line, which means it signals the PC that it is a low speed device (1.5 Mb/s). And it software emulates USB bus over a general use I/O port (can be seen in AVR firmware source code - file usbconfig.h
):
#define USB_CFG_IOPORTNAME B
/* This is the port where the USB bus is connected. When you configure it to
* "B", the registers PORTB, PINB and DDRB will be used.
*/
#define USB_CFG_DMINUS_BIT 0
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
* This may be any bit in the port.
*/
#define USB_CFG_DPLUS_BIT 1
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
* This may be any bit in the port. Please note that D+ must also be connected
* to interrupt pin INT0!
*/
#define USB_CFG_CLOCK_KHZ 12000
/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
* The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
* deviation from the nominal frequency. All other rates require a precision
* of 2000 ppm and thus a crystal!
* Default if not specified: 12 MHz
*/
if the bits flow is:
...0111100001111000011110000...
how will my device know it's byte1=11110000 and not byte1=01111000 ?
That's not the full picture. Each Byte is 'framed' with a Start bit (0) and a Stop bit (1). The UART syncs by looking for the 1 to 0 transition when going from Stop to Start.
Most devices do not send data continuously, and any gap longer than 9 bits should be enough to get into sync. MIDI baud rate is 31250 bps, so if the timing clock is a single Byte repeated 48 times per second there should be a large gap between Bytes. The actual bit flow should look like this:-
...011110000111111111111111111111111...1111111111111111110111100001....
^Byte-1^ ^Byte-2^
Best Answer
I have used Com0COM
But, there is nothing wrong with getting two USB serial adaptors and connecting them with a null-modem plug. (from the same place that sells the usb-serial). The Com0COM / Virtual serial port can take 10x longer to actually get working sometimes, and you just wish you had used wires (which are also a cross-platform solution)
If you are using binary data, Realterm may be more useful than hyperterm. It is good for sending your test data, and displaying binary data.
If your task is along the data collection lines, then you might consider making your program capture serial data to file, and process data from the file. This makes development very easy, and when there are problems, it is very easy to debug as the serial comms has always been captured in a file.