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.

at89s ISP programming

Status
Not open for further replies.

freakkaito

Member level 1
Joined
May 11, 2008
Messages
37
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,595
hey bro, i want to program an at89s via ISP, not from computer but i want to use avr as master:




AVR (ATmega32) <==ISP==>AT89S



MASTER ........................................................SLAVE
ATMEGA32......................................................AT89S

MOSI | <----------------------------------------> | MOSI
MISO | <----------------------------------------> | MISO
CLK | <------------------------------------------> | CLK



what should I do, i've send the enabled data but i never get the respon. can anyone help me
 

what about reset pin of 89s52?

nandhu
 

    freakkaito

    Points: 2
    Helpful Answer Positive Rating
Hi,
You have to put S51 in reset mode. Select an SCK clock slower than 1/16 th of S51 clock. Keep SCK low for atleast 64 clock cycles before issuing the commands. And use mode 0 SPI master. I think with these, you should be able to program S51.

Regards,
Laktronics

Added after 2 hours 33 minutes:

Hi,
Also use MSB first logic.
Regards,
Laktronics
 

    freakkaito

    Points: 2
    Helpful Answer Positive Rating
by your sugest, i've made this source. my ATmega32 clock is 4Mhz and AT89s 16Mhz so i can using 1Mhz transfer clock (1/16 at89s clock). reset is set on high position.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>


#include "global.h"
#include "lcd.h"

#define SPI_USEINT

int targetInit(void);
void targetClear(void);
uint8_t spiTransferByte(uint8_t data);
volatile u08 spiTransferComplete;
void spiInit(void);



int main (void)
{

#ifdef SPI_USEINT
SIGNAL(SIG_SPI)
{
spiTransferComplete = TRUE;
}
#endif


lcd_init(LCD_DISP_ON);
spiInit();




start:
if(!targetInit())
{
lcd_gotoxy(0,1);
lcd_puts("Target Error");


delay1s();
goto start;
}
else
{
lcd_clrscr();
lcd_puts("target ok");
}

targetClear();
_delay_ms(100);
spiTransferByte(0xAA); //write 0xAA to target
}




int targetInit(void)
{
spiTransferByte(0xac);//send first byte
spiTransferByte(0x53); //send second byte
spiTransferByte(0); //send 3rd byte
if(spiTransferByte(0)==105) //the respon should be 105 decimal or 69 hex
{
return(1);
}
else
{
return(0);
}
}

void targetClear(void)
{
spiTransferByte(0xac); //target clear instruction
spiTransferByte(0x80);
spiTransferByte(0);
spiTransferByte(0);
}




uint8_t spiTransferByte(uint8_t data)
{

#ifdef SPI_USEINT

spiTransferComplete = FALSE;
outb(SPDR, data); // send data

while(!spiTransferComplete);
#else

outb(SPDR, data); // send data

while(!(inb(SPSR) & (1<<SPIF))); // wait until finish
#endif

return inb(SPDR); // get the return data
}


void spiInit(void)
{


sbi(PORTB, 7); // set SCK hi
sbi(DDRB, 7); // set SCK as output
cbi(DDRB, 6); // set MISO as input
sbi(DDRB, 5); // set MOSI as output
sbi(DDRB, 4); // SS must be output for Master mode to work


// setup SPI interface :

sbi(SPCR, MSTR); // master mode

cbi(SPCR, SPR0); // clock = f/4 ------> 4/4=1Mhz
cbi(SPCR, SPR1);

cbi(SPCR,DORD); // MSB first

sbi(SPCR, SPE); // enable SPI




inb(SPSR);


// enable SPI interrupt

sbi(SPCR, SPIE);

}

but i never get the response. or my programe code is wrong?. i use lcd 16x2 as a display and winavr as compiler.
 

Hi,
1. How do you put 89S51 in Reset mode?
2. How are you setting Mode0 In SPI?
3. You have set SCK high to start with, in mode zero, idle state of SCK has to be low
After putting S51 in reset, you have to wailt for about 64 CPU clock cycles before giving commands. I am sorry, I will not be able to help you with coding.

Regards,
Laktronics
 

oh yeah, that's my old code. this the new one:

cbi(PORTB, 7); // set SCK low
sbi(DDRB, 7); // set SCK as output
cbi(DDRB, 6); // set MISO as input
sbi(DDRB, 5); // set MOSI as output
sbi(DDRB, 4); // SS must be output for Master mode to work


// setup SPI interface :

sbi(SPCR, MSTR); // master mode
cbi(SPCR, SPR0); // clock = f/4 ------> 4/4=1Mhz
cbi(SPCR, SPR1);
cbi(SPCR,CPHA); //transmision mode 0
cbi(SPCR,CPOL);
cbi(SPCR,DORD); // MSB first
sbi(SPCR, SPE); // enable SPI
inb(SPSR);
sbi(SPCR, SPIE); // enable SPI interrupt

that the spi init code, answering your question:

1. i put the AT89s always in reset, from the biginning the reset pin is connected with vcc, coz the project board only for external programing so i think that's not a problem.

2. mode 0 SPI, i set the CPHA and CPOL register by zero.

3. yeah my first code show that i put the sck on high, that's my mistake.

by the way even i already fix the code, i not get the response.
my friend sugest me to use ordinary I/O port coz the tranfser logic only using sift register, and we make this code:

uint8_t spi_transfer (uint8_t data)
{
unsigned char tempA,tempB,temp1,temp2,count;
unsigned char data_transmit, data_recieve,recieved;

data_transmit=0;
data_recieve=7; //MSB first
recieved=0;
tempA=0;
tempB=0;
temp1=0;
temp2=0;

cbi(DDRD,0); // set PORTD0 as miso input
sbi(DDRD,1); // set PORTD1 as mosi output
sbi(DDRD,2); // set PORTD2 as SCK
cbi(PORTD,2); // set SCK low

for(count=8; count>0; count--)
{
tempA=data;
tempB=(tempA<<data_transmit);
if((tempB)&0x80==80)
{

sbi(PORTD,1);

}
else
{

cbi(PORTD,1);

}

sbi(PORTD,2); //sck high

delay_ms(50); //wait for some times

cbi(PORTD,2); //sck low

temp1=PIND; //get the response bit
temp1=temp1&0x01;
temp2=(temp1<<data_recieve);
recieve=temp2 | temp1;

data_transmit++;
data_recieved--;
}

return recieve;
}

and when i send the enabled data i not get the response too. what must i do? is there anyone could help me with some code, coz i stil newbie here...
 

freakkaito

atmega 32 port pins have stronger pullups. I think 89s dont have power to pull it down please check it out

Nandhu
 

Hi,
In your code, you have to pick up MISO bit when clock is high. Please see below a suggested SPI code. You should be able to take care of all coding requirements. I am not a dependable source for codes.

uchar spi_transfer(uchar data)
{

// change the following bit definitions as per your compiler requirements
sbit miso = (PortD,0);
sbit mosi = (PortD,1);
sbit sck = (PortD,2);
cbi(DDRD,0); // set PORTD0 as miso input
sbi(DDRD,1); // set PORTD1 as mosi output
sbi(DDRD,2); // set PORTD2 as SCK
cbi(PORTD,2); // set SCK low
unsigned char count;

for(count=8; count>0; count--)
{
If(data&0x80)
MOSI = 1;
Else
MOSI = 0;
data<<1;
sck = 1;
delay();
If (miso)
data = data+1;
sck = 0;
}
return data;
}

Regards,
Laktronics
 

    freakkaito

    Points: 2
    Helpful Answer Positive Rating
freakkaito said:
hey bro, i want to program an at89s via ISP, not from computer but i want to use avr as master:

AVR (ATmega32) <==ISP==>AT89S

MASTER ........................................................SLAVE
ATMEGA32......................................................AT89S

MOSI | <----------------------------------------> | MOSI
MISO | <----------------------------------------> | MISO
CLK | <------------------------------------------> | CLK

what should I do, i've send the enabled data but i never get the respon. can anyone help me

Perhaps the SPI mode you have set up with the avr is incorrect.
Check the datasheet for the 89S51.

I have done this with another 89S51 (as master) using bit-bang spi routines in the 89S51.

Look here:


it may give you some ideas.

I do have some parts of this programmer done with avr code, however it is not complete.

Good Luck
 

    freakkaito

    Points: 2
    Helpful Answer Positive Rating
thank you very much guys, you realy help me this time. I'll try to fix my source and use Laktronics source, i hope it's can work.

and for ctownsend, i already have your code, i not really great with asembly but thank's very much that realy great project.

wish me luck ok!
 

hey guys, i did it!!!!!! i get the response....

Laktronics thank you very much, you right i have to read miso pin when the clock still high.

horeeeee
 

Hi,
Thanks for the feedback and congrats. You can now try programming the chip.

Regards,
Laktronics
 

    freakkaito

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top