Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/07/04 05:39
Read: times


 
#82672 - code and schematic
Responding to: ???'s previous message
As I had already told that I had tried various code but all dosn't work so I want you to help me not by just sending the code but by helping me to understand to execute SPI. I am putting my modified code. Although I had tried the suggestion given by you but the code doesn't work.



#include <AT89S8252.H>

void main()
{
void SPI_out(int send,int l_add,int u_add);
void chip_command(int);
int i;
P1 = 0xFF;
SPCR = 0x53; /* SPI interrupt enable with micro as master and 1MHz data transfer rate */
SS = 0;
chip_command(0x06); /* Write Enable for external EEPROM */
SS = 1;
P1 &= 0xF0;
for(i = 0;i < 30000;i++);
SS = 0;
SPI_out(0x55,0x00,0x04); /* Send data, lower address and higher address */
SS = 1;
P1 |= 0x0F;
for(i = 0;i < 30000;i++);
SS = 0;
chip_command(0x04);
P1 = 0xFF;
}

void SPI_out(int send,int l_add,int u_add)
{
DPH = u_add;
DPL = l_add;
SPDR = 0x02;
while(SPSR != 0x80);
ACC = DPH;
SPDR = ACC;
while(SPSR != 0x80);
ACC = DPL;
SPDR = ACC;
while(SPSR != 0x80);
ACC = send;
SPDR = ACC;
while(SPSR != 0x80);
}

void chip_command(int command)
{
ACC = command;
SPDR = ACC;
while(SPSR != 0x80);
}


My circuit is like this.

1. There is a Vcc connected to 40th pin of micro AT89S8252 and GND to 20th pin.
2. RST connected to a switch. On power up I push the switch to reset micro.
3. Four pins of Port1 1.5-1.8 CS, MOSI, MISO, SCK respectively are connected to ST EEPROM M95256 respective pins.
4. There is no other connection to micro.

When I run the program on micro it seems that clock of micro doesn't run and hence it can't transfer data.

Please try to resolve my problem ASAP.

List of 20 messages in thread
TopicAuthorDate
has anybody used SPI            01/01/70 00:00      
   more details please            01/01/70 00:00      
      details            01/01/70 00:00      
         missing code?            01/01/70 00:00      
         How to post code            01/01/70 00:00      
   The story so far?            01/01/70 00:00      
   no solution            01/01/70 00:00      
      all is replied above            01/01/70 00:00      
      So you want a solution?            01/01/70 00:00      
         code and schematic            01/01/70 00:00      
            unconnected reset?            01/01/70 00:00      
            How about some clocking ??            01/01/70 00:00      
            Code still illegible!            01/01/70 00:00      
            is it C-language?            01/01/70 00:00      
               reply of queries            01/01/70 00:00      
                  complaining            01/01/70 00:00      
                  Do you want to be helped?            01/01/70 00:00      
                     Watch window in Keil            01/01/70 00:00      
                        Registers window in Keil            01/01/70 00:00      
   EA            01/01/70 00:00      

Back to Subject List