Application: SPI Function
// Master send 0x90 and recevie 0x4E
// Master send 0x01 and recevie 0x55
// Master send 0x02 and recevie 0x56
// Master send 0x03 and recevie 0x4F
// Master send 0x04 and recevie 0x54
//
// Master recevie 0x4E and 0x4F form slave after transmitting
//
// Output : P1.4 & P2.1 flash when SPI pass
// UART show result on hyper-terminal
// P0.7 flash when SPI error
void SPI_Error(void)
{
printf ("\nSPI error.\n");
while(1) // SPI error and P0.7 flash/
{
P07 = 1;
Timer0_Delay1ms(500);
P07 = 0;
Timer0_Delay1ms(500);
}
}
void Start_Sending_SPI(UINT8 *pu8MID,UINT8 *pu8DID)
{
SS = 0;
SPDR = 0x90; // Send 0x90 to Slave
PCON |= SET_BIT0; // Enter idle mode
if(SPDR != 0x4E) // Receive slave 1st DATA
SPI_Error();
printf ("\nSlave Return %c!\n",SPDR);
SPDR = 0x01; // Send 0x01 to Slave
PCON |= SET_BIT0; // Enter idle mode
if(SPDR != 0x55) // Receive slave 2nd DATA
SPI_Error();
printf ("\nSlave Return %c!\n",SPDR);
SPDR = 0x02; // Send 0x02 to Slave
PCON |= SET_BIT0; // Enter idle mode
if(SPDR != 0x56) // Receive slave 3rd DATA
SPI_Error();
printf ("\nSlave Return %c!\n",SPDR);
SPDR = 0x03; // Send 0x03 to Slave
PCON |= SET_BIT0; // Enter idle mode
if(SPDR != 0x4F) // Receive slave 4th DATA
SPI_Error();
printf ("\nSlave Return %c!\n",SPDR);
SPDR = 0x04; // Send 0x04 to Slave
PCON |= SET_BIT0; // Enter idle mode
if(SPDR != 0x54) // Receive slave 5th DATA
SPI_Error();
printf ("\nSlave Return %c!\n",SPDR);
SPDR = 0x4F;
PCON |= SET_BIT0; // Enter idle mode
*pu8MID = SPDR; // Receive Slave 1st DATA fron Slave
printf ("\nSlave Return %c!\n",SPDR);
SPDR = 0x4E;
PCON |= SET_BIT0; // Enter idle mode
*pu8DID = SPDR; // Receive Slave 2nd DATA from Slave
printf ("\nSlave Return %c!\n",SPDR);
SS = 1; |