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...