AT89S52 I can flash code through ISP but cannot run it

Discussion in 'Embedded Systems and Microcontrollers' started by Serhat Erdoğan, Jan 16, 2016.

  1. Serhat Erdoğan

    Thread Starter New Member

    Oct 10, 2015
    7
    0
    Hi,

    I tried to set up a circuit with a AT89S52 8051 microprocessor on breadboard. I programmed the chip with an Arduino through in system programming. I used an external clock which I connected to XTAL1 pin and I left XTAL2 pin not connected.

    Anyway, I was able to read the signature bytes, write bytes to memory and read them back for verification.

    However, when I pull the reset LOW to begin normal operation, microprocessor works randomly. I was trying to blink an LED. I searched the web and tried everything. I connected ground side of the LED to port1.0 and I try to write 0 to port1 to turn LED on. But it doesn't work.

    There shouldn't any problems with clock because if there were, ISP wouldn't have worked.

    I am controlling the reset pin through a digital pin of Arduino and I give a reset pulse when I restart the device. Vcc is connected to 5V supply and similarly ground is connected to Gnd of Arduino.

    I thought maybe the processor is damaged but then how is it possible to successfully program a damaged chip through isp. Maybe there is a problem with my breadboard setup.
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    isn't the RESET on an 8051 ACTIVE High??
     
  3. ScottWang

    Moderator

    Aug 23, 2012
    4,850
    767
    The reset pulse should be from Lo to Hi, and keep Hi about T = 0.69RC = 8.2K*10uF = 56.58 mS, and back to Lo, how is your pulse?

    Above is the values of RC that we normally used and didn't counting the internal resistor of reset pin.
     
  4. Serhat Erdoğan

    Thread Starter New Member

    Oct 10, 2015
    7
    0
    Thank you.

    yes I am giving a low-high-low reset pulse in the beginning. But I haven't used any capacitors or resistors.
    In fact I was just writing HIGH to the pin of arduino which is directly connected to RST pin of 8051 and after 100 ms I write LOW back.
    Should I still connect a capacitor and external resistor even if I control reset pulse through arduino?
     
  5. ScottWang

    Moderator

    Aug 23, 2012
    4,850
    767
    Yes, you should use the RC to try the reset of 89S52 to make sure its original situation is ok, and read the data from 89s52, try the power reset and manually reset.

    Could you attach the schematic.
     
  6. Serhat Erdoğan

    Thread Starter New Member

    Oct 10, 2015
    7
    0
    Schematic is on the attachment. I don't have any capacitors with me right now. But I will try resetting it with RC when I got a 10uF cap.
     
    • sch.png
      sch.png
      File size:
      302.8 KB
      Views:
      8
  7. DickCappels

    Moderator

    Aug 21, 2008
    2,647
    631
    Two thoughts:

    There is no power supply decoupling shown in the schematic. If there isn't any, it is a good idea to add some.

    When my code doesn't work I usually suspect the code rather than the hardware.
     
  8. ScottWang

    Moderator

    Aug 23, 2012
    4,850
    767
    When you do this, how is the /EA/Vpp pin?

    ------------------------------------
    /EA/Vpp:
    EA should be strapped to VCC for internal program executions.
    This pin also receives the 12-volt programming enable voltage (VPP) during Flash programming.
     
  9. Serhat Erdoğan

    Thread Starter New Member

    Oct 10, 2015
    7
    0
    OK, I will also try adding a decoupling capacitor.

    I also suspected that code might be wrong. I tried a variety of different codes but all resulted in random, unexpected behaviour.
    The last code that I've been trying is writing 0 to port1.

    Code (Text):
    1. BACK: MOV A,#0
    2. MOV P1,A
    3. SJMP BACK
    4. END
    5.  
     
  10. Serhat Erdoğan

    Thread Starter New Member

    Oct 10, 2015
    7
    0
    EA pin is connected to Vcc, which is 5 volts supply of Arduino. As far as I know during serial programming EA pin not used, 12 Volts Vpp is required only in parallel programming.
     
  11. Serhat Erdoğan

    Thread Starter New Member

    Oct 10, 2015
    7
    0
    I don't know if this is relevant but after I apply the reset pulse I usually observe that LED light alternates between bright and dim for a while as if the chip struggles to light up the LED but after a short time LED turns off completely. Normally, LED should continously light up. I learned that at89s52 is bad at sourcing current therefore I set up the circuit such that it sinks current, however still it doesn't work. Maybe power supply of Arduino can't supply 5V in a stable manner during startup?
    I hope it work when I add decopling and reset capacitors.
     
  12. ScottWang

    Moderator

    Aug 23, 2012
    4,850
    767
    If you have the O'scope then you can measuring the Pin 1 during it's working.
    You should reduce the values of R1, it is too high, the current counting for 80% of LED, LED 2V/20mA, R1 = 200Ω, LED 3V/20mA, R1 = 120Ω.
     
  13. absf

    Senior Member

    Dec 29, 2010
    1,490
    371
    You only turn on the LED but not turning it off.

    So the LED is permanent ON and not blinking.

    Allen
     
  14. absf

    Senior Member

    Dec 29, 2010
    1,490
    371
    Try this program. Might work for your mcu with 2MHz clock.

    Code (ASM):
    1.     org    0
    2. back:    mov    p1,#0
    3.     call    delay
    4.     mov    p1,#1
    5.     call    delay
    6.     sjmp    back
    7.  
    8. delay:    mov    r1,#255
    9. d1:    djnz    r1,d1
    10.     ret
    11.     end
    12.  
     
  15. ScottWang

    Moderator

    Aug 23, 2012
    4,850
    767
    It could be work if the hardware has no any problems.
     
  16. ScottWang

    Moderator

    Aug 23, 2012
    4,850
    767
    Maybe you can post the arduino c code and the code for 89S52, in a uC system when the problem occurs then check the hardware first to make sure the hardware has no any problems and then check the software.
     
  17. Serhat Erdoğan

    Thread Starter New Member

    Oct 10, 2015
    7
    0
    Thanks everyone,
    Today I have been able to get it to work, when I connected the capacitors. It seems there aren't any problems with the hardware.
     
Loading...