[Solved] Downloading FLASH from AT89S52 with ArduinoISP

Hi there folks!

I have noname device wich is controlled by AT89S52. I've been trying to "use it" somehow, but with no luck, so I decided to try to download FLASH and try to recompile it. It is first time for me at all (to download flash), so i do not have any programmer - so i used original Arduino UNO.
I've programmed it as ArduinoISP.

Then I've found another problem - there is no (easy way) to "connect" to it to program.

So ironed wires. There are three things connected directly to those legs of our interest:
7705 (gives RESET HIGH when there is Voltage lower than 4.55 (http://www.ti.com/product/TL7705A#) - I've wired wire here. (D10 on arduino UNO)
7805 - Voltage regulator of 5V - I've wired there 5V Arduino UNO output.
ULN2003 - High Voltage, High Current Darlington Transistor Arrays (there might be a problem, isnt?), datasheet: https://www.onsemi.com/pub/Collateral/ULN2003A-D.PDF . One of those is connected to MISO, MOSI and SCK outputs. I've wired there wires of D11-13 from arduino.

I've read some about downloading flash (topics from here and some websides about FLASHING AT89, and there is my avrdude command(s):

avrdude -C F40R96CIUSLFZFP.conf -c stk500v1 -P /dev/ttyACM0 -p 89s52 -b 19200 -D -Uflash:r:program.bin:r

avrdude -C F40R96CIUSLFZFP.conf -c avrisp -P /dev/ttyACM0 -p 89s52 -b 19200 -D -Uflash:r:program.bin:r

Gives:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

Forcing FLASH read by -F gives me 8k file filled with zeros.

While:

avrdude -C F40R96CIUSLFZFP.conf -c arduino -P /dev/ttyACM0 -p 89s52 -b 19200 -D -Uflash:r:program.bin:r 


avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x01
avrdude: stk500_initialize(): (a) protocol error, expect=0x14, resp=0x10
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: stk500_disable(): unknown response=0x12

avrdude done.  Thank you.

I've checked all connections with multimeter - seems to be solid. Created test program, and put in on UNO (digitalWrite(x, HIGH) for each of 10-13 ports) and multimeter shows 5V there - while connected.

I have no more idea what can be wrong...

My F40R96CIUSLFZFP file starts with:

part
    id               = "89s52";
    desc             = "AT89S52";
    stk500_devcode   = 0xE1;
    signature        = 0x1e 0x52 0x06;
    chip_erase_delay = 500000;
    reset            = dedicated;
    pgm_enable       = "1 0 1 0  1 1 0 0    0 1 0 1  0 0 1 1",
                       "x x x x  x x x x    x x x x  x x x x";

    chip_erase       = "1 0 1 0  1 1 0 0    1 0 0 x  x x x x",
                       "x x x x  x x x x    x x x x  x x x x";

    memory "flash"
        size            = 8192 ;             # bytes
        read            = "0 0 1 0 0 0 0 0  x x x a12 a11 a10 a9 a8",
                          "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o";
        write           = "0 1 0 0 0 0 0 0 x x x a12 a11 a10 a9 a8",
                          "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i";
        ;
    memory "signature"
        size            = 3;
        read            = "0 0 1 0 1 0 0 0  0 0 0 0 0 0 a1 a0",
                          "0 0 0 0 0 0 0 0  o o o o o o  o  o";
        ;
  ;
part parent "89s52"
    id = "89s51";
    desc = "AT89S51";
    signature = 0x1e 0x51 0x06;
    memory "flash"
        size            = 4096 ;             # bytes
        read            = "0 0 1 0 0 0 0 0  x x x x a11 a10 a9 a8",
                          "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o";
        write           = "0 1 0 0 0 0 0 0 x x x x a11 a10 a9 a8",
                          "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i";
      ;
    ;

To be sure - my connections are (TQFP package):

PIN1 (MOSI) - D11
PIN2 (MISO) - D12
PIN3 (SCK) - D13
PIN4 (RST) - D10

PIN38 (5V) - 5V
PIN17 (GND) - GND

The crystal onboard is 12M (i think)

I've tried with second panel - same thing.

My understanding is that the 89s52 chips have a reset pin that is active high, rather than the active low of avrs. This may require mods to arduinoisp.

According to 7705 info (underlined negative outputs):

The TL77xxA family of integrated-circuit supply-voltage supervisors is designed specifically for use as reset controllers in microcomputer and microprocessor systems. The supply-voltage supervisor monitors the supply for undervoltage conditions at the SENSE input. During power up, the RESET output becomes active (low) when VCC attains a value approaching 3.6 V. At this point (assuming that SENSE is above VIT+), the delay timer function activates a time delay, after which outputs RESET and RESET go inactive (high and low, respectively). When an undervoltage condition occurs during normal operation, RESET and RESET go active.

In my device RST (AT89) is connected to RESET (6) which is not negated. No such info in 89's datasheet also.
I assume it is not the case, but I'll check tomorrow.

Yes, 89s52 have not-negated RST, but avrs (and the arduinoisp sketch) have /RST (negated) reset.

This version of the ArduinoISP uses an inverted reset

http://forum.arduino.cc/index.php?topic=72919.0

Some notes regarding AT89S52:

http://ernstc.dk/arduino/at89s.html

Thank You both!
It helped. One of the chip does not respond but second does.

Now i disassembled source code and i'm trying to understand assembler. Hard thing, but, hey, what fun %)
Many thanks.