static WORD spiSD_Init(WORD j)
{
WORD aFreq= SPISD_BRATE_PINDEFAULT;
BYTE i, Y= 0xFF;
BYTE idle[6] = {0x40,0x00,0x00,0x00,0x00,0x95};
unsigned int retry;
SetBit(SPI_CS_PORT, SPI_CS_PIN); // SPI CS pin: inactive
ClrBit(SPI_CS_ODP, SPI_CS_PIN); // : push/pull mode
SetBit(SPI_CS_DP, SPI_CS_PIN); // : output
SetBit(SPI_DATAOUT_PORT, SPI_DATAOUT_PIN); // SPI MTSR: 1
ClrBit(SPI_DATAOUT_ODP, SPI_DATAOUT_PIN); // : push/pull mode
SetBit(SPI_DATAOUT_DP, SPI_DATAOUT_PIN); // : output
SetBit(SPI_CLK_PORT, SPI_CLK_PIN); // SPI SCLK: 1
ClrBit(SPI_CLK_ODP, SPI_CLK_PIN); // : push/pull mode
SetBit(SPI_CLK_DP, SPI_CLK_PIN); // : output
SetBit(SPI_DATAIN_PORT, SPI_DATAIN_PIN); // SPI MRST: 1
SetBit(SPI_DATAIN_ODP, SPI_DATAIN_PIN); // 1: open drain, does not matter
ClrBit(SPI_DATAIN_DP, SPI_DATAIN_PIN); // : input
_nop();
// make sure to have '1' at the line
for ( i= 0; i< 10; i++ )
spiSD_Write((BYTE *)&Y, 1);
//sprintf(cTextOutput, "Ver: %s Build: %s %s\r\n", FirmwareVersion, __DATE__, __TIME__);
//LowLevelDebug_SerialPrintStr(cTextOutput, strlen(cTextOutput));
do
{
spiSD_Write(idle,6);
SPI_DELAY();
spiSD_Read(&response,1);
if(retry++ > 150) break;
}while(response != 0x01);
if (response != 0x01)
{
sprintf(cTextOutput, "IDLE State Error : %d\n\r",response);
LowLevelDebug_SerialPrintStr(cTextOutput,strlen(cTextOutput));
}
else
{
sprintf(cTextOutput," IDLE State Successful");
LowLevelDebug_SerialPrintStr(cTextOutput,strlen(cTextOutput));
}
return(j);
}