Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[51] ISP programmer issue

Status
Not open for further replies.

praveenrpk92

Newbie level 6
Joined
Dec 28, 2015
Messages
11
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
98
Hi, I'm trying to design an ISP programmer for AT89S52. I'm using 2 Microcontrollers, controller 1 has chip erase code in it & I have successfully erased controller 2. Although I'm not able to read the MISO pin which should give the value 01101001 during byte 4 cycle of programming enable sequence.

Here's the code in controller 1:

Code:
#include <REGX52.h>
#include <intrins.h>

sbit RST=P2^0;
sbit MOSI=P2^1;
sbit MISO=P2^2;
sbit SCK=P2^3;

unsigned char bit_i=0;
bit txbit,rxbit,flag;
unsigned char a,b,c,d;
unsigned int i=0;
unsigned char rx,tpx;
void delay_us(unsigned int d);
void send(unsigned char x);
void sendbyte(unsigned char spibyte);

void main(void)
{ 
delay_us(32000);
	MISO=1;
	RST=0;
	SCK=0;
	TMOD=0x20;
PCON=PCON | 0x80;
	TH1=0xFF;
	TL1=0xFF;
SCON=0x50;
	TR1=1;

	
	RI=0;
	TI=0;
	
  send('M');
	delay_us(1000);
	
	send('C');
	
	SCK=0;
	//RST=0;
	
	for(i=0;i<500;i++)
	{P1_3=1;delay_us(1000);P1_3=0;}

//=======Program enable===========
	a=0xac;
	b=0x53;
	c=0x00;
	d=0x11;
	sendbyte(a);
	sendbyte(b);
	sendbyte(c);
	sendbyte(d);

//==========Erase==================
	a=0xac;
	b=0x82;
	c=0x12;
	d=0x13;
	sendbyte(a);
	sendbyte(b);
	sendbyte(c);
	sendbyte(d);
	
	for(i=0;i<1000;i++)
	{P1_3=1;delay_us(1000);P1_3=0;}
 send('E');
	
	
	
		
while(1){
P1_3=1;

	for(i=0;i<2500;i++)
	{P1_3=1;delay_us(1000);P1_3=0;}

P1_3=0;
  }
}


void delay_us(unsigned int d)
{
   unsigned int i, limit;
   limit = d/15;

   for(i=0;i<limit;i++);
	
}

void send(unsigned char x)
{
SBUF=x;
while(TI==0);
	//delay_us(10000);
	TI=0;
}

void sendbyte(unsigned char spibyte)
{
   rx=0x00;
	if(spibyte==0x11){flag=1;}else{flag=0;}
	for(bit_i=0;bit_i<8;bit_i++)
	{P1_3=1;
		txbit=spibyte/128;
		spibyte=spibyte<<1;
		MOSI=txbit;
		delay_us(1000);
  	_nop_();
	  SCK=1;
	  delay_us(1000);
	  _nop_();
		if(flag)
		{tpx=MISO;send(tpx);
	 	rx= rx | (tpx<<(7-i));}   
		 SCK=0;
		 P1_3=0;}
	if(flag)
	{send(':');
	 send(rx);
	 send(';');}
}

Here's what received in hyperterminal:
HT.JPG

I'm getting these weird smiley symbols. I tried to read the value of MISO pin in while loop and I'm getting 1's and 0's properly. Please help.

Update : I replaced send(tpx) with send(tpx+48) and got the 01101001 sequence in hyperterminal. So, rx should be 0x69 which should display 'i' in hyperterminal but I'm getting nothing for that send instruction alone.
 
Last edited:

Hi,

I'm confused.
SPI is a synchronous serial interface. The timing is forced by the clock signal.
Hyperterminal is for UART style. UART has no clock signal. Timing is forced by the setup for a baud rate.

I can't find a baud rate setup in your code...

Please describe mor detailed.

Klaus
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top