AnsweredAssumed Answered

SPI SPIF flag not getting (Read) set in S12XDP512

Question asked by santhosh sl on Oct 10, 2013
Latest reply on Oct 11, 2013 by santhosh sl

Hello All,

 

I am trying to interface an external SRAM from Microchip to S12XDP512 controller. And the interface is through SPI.

I am using SPI 1 of my controller for this purpose. The procedure to access this SRAM is straight forward. But I was not able to read data from the Device.

So I would like to get your help to review if my SPI read and Write are functions are correct. Please find the functions as below

 

void SPI1_Initialization(void)

{

   //initialize pins, mosi-0, sck/clr/ld/cs - 1

   SPI_MOSI = 1;

   SPI_MISO = 0;

   SPI_SCK = 1;

   SPI_CS = 1;

 

   SPI1BR = 0x07;//0x05;    //Clk rate=bus clock/256  , so Clk rate = 8000000/256 = 31250

   SPI1CR1 = 0x54;  // enable SPI, Master Mode,CPHA=1,CPOL=0, select clock polarity/phase

   SPI1CR2 = 0x00;     //Normal mode of operation

}

 

unsigned int SPI_Send(unsigned char Data)

{

unsigned int Test0;

    SPI_CS = 0;

    Test0 = SPI1DR;

    while( (unsigned char)(SPI1SR & 0x20) != 0x20); /* Wait SPTEF */

    SPI1DR = Data;                         //data stored in buffer and waiting for SCK

 

    SPI_CS = 1;

    return(1);

}

 

unsigned int SPI_Read(void)

{

   unsigned int temp_data, max_count, temp;

   max_count = 0xffff;

   SPI_CS = 0;


   while( ((unsigned char)(SPI1SR & 0x80) != 0x80) && (--max_count) ) ; // wait for End of Transmission

   temp_data = SPI1DR;

   SPI_CS = 1;

   return temp_data;

}

 

Can some one help me with this issue.

 

Thanks

Santhosh S L

Outcomes