AT89S52 I can flash code through ISP but cannot run it

Thread Starter

Serhat Erdoğan

Joined Oct 10, 2015
7
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.
 

ScottWang

Joined Aug 23, 2012
6,926
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.
 

Thread Starter

Serhat Erdoğan

Joined Oct 10, 2015
7
isn't the RESET on an 8051 ACTIVE High??
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.
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?
 

ScottWang

Joined Aug 23, 2012
6,926
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?
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.
 

Thread Starter

Serhat Erdoğan

Joined Oct 10, 2015
7
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.
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.
 

Attachments

DickCappels

Joined Aug 21, 2008
6,532
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.
 

ScottWang

Joined Aug 23, 2012
6,926
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.
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.
 

Thread Starter

Serhat Erdoğan

Joined Oct 10, 2015
7
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.
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:
BACK: MOV A,#0
MOV P1,A
SJMP BACK
END
 

Thread Starter

Serhat Erdoğan

Joined Oct 10, 2015
7
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.
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.
 

Thread Starter

Serhat Erdoğan

Joined Oct 10, 2015
7
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.
 

ScottWang

Joined Aug 23, 2012
6,926
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.
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Ω.
 

absf

Joined Dec 29, 2010
1,947
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:
BACK: MOV A,#0
MOV P1,A
SJMP BACK
END
You only turn on the LED but not turning it off.

So the LED is permanent ON and not blinking.

Allen
 

absf

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

Code:
    org    0
back:    mov    p1,#0
    call    delay
    mov    p1,#1
    call    delay
    sjmp    back

delay:    mov    r1,#255
d1:    djnz    r1,d1
    ret
    end
 

ScottWang

Joined Aug 23, 2012
6,926
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.
 

Thread Starter

Serhat Erdoğan

Joined Oct 10, 2015
7
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.
 
Top