I've designed an RS232-to-TTL converter board based on TI's MAX232 IC that I plan to use to program a few custom Arduino boards that I have. However, I'm having trouble with the board and I'm hoping that someone can help me debug it.
First, let me show you my setup, below.
Here's a brief description of what's in the picture:
Target Board (A): it's a custom standalone ATmega328P board (a clock) that I intend to program using serial programming and the Arduino IDE. It's connected to the Board B through a FTD-like cable through Connector (H).
RS232-to-TTL Converter Board (B): it's the MAX232 based RS232-to-TTL converter board I designed and am trying to debug. It's the main topic of this question. It's connected to the Target Board (A) with the FTDI-like cable through Connector (G) and to the USB-to-RS232 Cable (C) through a Female DB9 Connector (F).
USB-to-RS232 cable (C): I don't have a proper COM port on my PC, so that's what I use to get a Serial Port instead. It's connected to the PC through an USB connector (D) and to the Board B through a Male DB9 Connector (E).
The schematics of Board B are below.
The programming header schematics on Target Board (A) is shown below.
First thing I realized is that the USB-to-RS232 Cable (C) is of the cheap kind. Instead of delivering RS232 standard signal levels in the -12V/+12V range, it delivers 0V/5V instead. I figured that using the following test: I connected the USB-to-RS232 Cable (C) to the PC and disconnected Male DB9 Connector (E) from the Converter Board (B) and probed pin 3 from the Male DB9 Connector (E) while I was sending a series of ASCII char 'A'
through the serial monitor. Below is the scope shot resulting of this test.
Incidentally, I've noticed that the various MAX232 IC's made by various vendors are designed to cope with this violation of RS232 signal levels and accept 0V/5V signals as well. Below are two scope shots that I used to prove it. In the first shot I applied a 0V/5V square wave into MAX232 pin 13 (while inserted and powered by my converter board) with my homemade function generator (noisy, yes) - that's the yellow trace - and checked the output of pin 12 (TTL level RX - green trace). To my surprise, TI's MAX232 respond with the correct TTL signals. The second shot is a correct RS232 -6V/+6V signal simulated by a square wave I inserted into the same pin. Both yield the same results.
I did some other measurements on my Converter Board (B) to the point I was satisfied with it. For example, pin 2 on MAX232 shows +9.5V while pin 6 shows -9.5V. The scope shows the voltage doubler and inverter are working fine as well, with a nice and steady 40kHz square wave in each case. I've also applied 0/5V square wave of about 68kHz to pin 10 of the MAX232 and scoped pin 7 of MAX232. I got a nice and clean inverted -6V/+6V RS232 signal (images not shown here).
Then I tested serial monitor echo shorting the TX/RX pins at various points. The results where:
- Without MAX232 IC in its socket I shorted pins 2 and 3 on DB9. Echo ok.
- Placed MAX232 IC on the board and shorted its pins 11 and 12. Echo ok.
- With ATmega328P off its socket, I shorted pins 2 and 3. Echo ok.
Then I connected the setup to program my ATmega328P Target Board (A). The avr-dude output is shown at the end of this post. Below is a summary with just the error message:
...
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
...
avrdude: stk500_cmd(): protocol error
During this programming attempt, I measured the signals below. The yellow trace is data being sent to the MCU while the green trace is data being received by it:
When I get the error, there's a sudden interruption in the communication. From one attempt to the next, the problem happens at different points during communication.
Finally, I replaced my MAX232 board with an older one that I have, that uses the transistor trick instead of the MAX232 IC, and all starts to work properly. With the old board I can get the target board programmed. Below is the scope shot showing the successful communication during programming of the target board in this case.
I'm certainly overlooking something, but I cannot tell what it is. So my question is: what's wrong with my setup? What else can I check or measure to figure out the problem?
Here's the Arduino IDE and avr-dude output:
Binary sketch size: 9.946 bytes (of a 32.256 byte maximum)
C:\Users\Ricardo\Documents\arduino-1.0.5\hardware/tools/avr/bin/avrdude -CC:\Users\Ricardo\Documents\arduino-1.0.5\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -carduino -P\\.\COM5 -b115200 -D -Uflash:w:C:\Users\Ricardo\AppData\Local\Temp\build2465731745810216807.tmp\DefusableClock_v2.cpp.hex:i
avrdude: Version 5.11, compiled on Sep 2 2011 at 19:38:36
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch
System wide configuration file is "C:\Users\Ricardo\Documents\arduino-1.0.5\hardware/tools/avr/etc/avrdude.conf"
Using Port : \\.\COM5
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: Send: 0 [30] [20]
avrdude: Send: 0 [30] [20]
avrdude: Send: 0 [30] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
AVR Part : ATMEGA328P
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : Arduino
Description : Arduino
avrdude: Send: A [41] . [80] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [83]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [81] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [84]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [82] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [04]
avrdude: Recv: . [90]
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
avrdude: Send: A [41] . [98] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [03]
avrdude: Recv: . [10]
Hardware Version: 131
Firmware Version: 132.1077487570
avrdude: Send: A [41] . [84] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [03]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [85] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [03]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [86] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [03]
avrdude: Recv: . [90]
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x90
avrdude: Send: A [41] . [87] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [03]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [89] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [83]
avrdude: Recv: . [10]
Vtarget : 0.3 V
Varef : 0.3 V
Oscillator : 921.600 kHz
SCK period : 142.2 us
avrdude: Send: A [41] . [81] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [04]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [82] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [04]
avrdude: Recv: . [10]
avrdude: Send: B [42] . [86] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] . [80] . [04] . [00] . [00] . [00] . [80] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: Send: E [45] . [05] . [04] . [d7] . [c2] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: Send: P [50] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: AVR device initialized and ready to accept instructions
Reading | avrdude: Send: u [75] [20]
avrdude: Recv: . [14] . [1e] . [95] . [0f] . [10]
################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f
avrdude: Send: V [56] . [a0] . [03] . [fc] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: V [56] . [a0] . [03] . [fd] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: V [56] . [a0] . [03] . [fe] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: V [56] . [a0] . [03] . [ff] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [90]
avrdude: stk500_cmd(): protocol error
Answer
Your question was way to long to read, but it seems you are having some problems with a MAX232-type of converter circuit. I have made what seems to be a very similar circuit using one of the TI variants of the chip, and even sell it as a product. Go to www.embedinc.com/products/rslink2 and you can see all the documentation, from a picture to the board layout to the schematic. Perhaps you can see what you are doing differently.
One thing I noticed while skimming your question is that you are using electrolytic caps. Double check that the polarity of each is correct. Another issue is that some COM ports, particularly USB to RS-232 converters, won't work without RTS/CTS, whether this is enabled in software or not. Note how I have pins 7 and 8 connected to each other on the DB9-F connector.
No comments:
Post a Comment