Hi,
Ya i have refereed SPI specification before writing the program. Based on SRAM timing requirement i developed my code like as follows and please what are the wrong in my code and if any changes is there please give me the solution.
1. Enabled GPIO pin as MOSI, MISO, CLK, CS
2. CS=0
CLK=0
CS=1
To write to SRAM
3. SPIWRITE(WRD_INSTR)
4. SPIWRITE(0x00)
5. SPIWRITE(0x00);
6. SPIWRITE('A')
7. CS=0
MOSI=0
CLK=0
CS=1
To read data from RAM
8. SPIWRITE(READ_INSTR)
9. SPIWRITE(0x00)
10. SPIWRITE(0x00)
11. data=SPI_READ()
12. CS=1
SPIWRITE( unsigned char b)
{
unsigned char m, i;
for(i=0;i<8;i++)
{
if(b!=0)
MOSI=1
else
MOSI=0;
CLK=1
CLK=0
b=m<<1;
} m=b;
}
unsigned char SPI_READ()
{
unsigned char i;
for(i=0;i<8;i++)
{
if(MISO)
b1=(b1 | 0x01);
else
a1=b1;
b1=b1<<1;
CLK=1
CLK=0
}
return a1;
}
Thank youi