
ID TECH SecureHead SPI with TMIV User Manual
Page | 49
}
_SPI_SS = 1; // Read out all the data from SPI slave, set BeepOn_Long(); // Send out
one beep to indicate command finished.
// .............
Other subroutine to handle other
}
while( TRUE );
}
/*C**************************************************************************
*
Module:
spi_drv.c
/****************************************************************************
*
Copyright (c) 2004 ID TECH inc.,
/****************************************************************************
*
CREATION_DATE:
2004.1.10
/****************************************************************************
*
PURPOSE:
*
spi library low level functions (init, receive and send functions)
*
and global variables declarations to use with user software application
*****************************************************************************/
/*
I N C L U D E S
*/ #include "spi_drv.h"
/*
M A C R O S */
/*
D E F I N I T I O N */ Uchar transmit_completed = 0; // 0
by default
extern Uchar data SPI_IPNT;
/*
D E C L A R A T I O N */
// Here are some global flags to use with spi library
// These global flags are used to communicate with higher level functions ( user application )
// Here the global variables to communicate with spi interrupt routine
/*F**************************************************************************
*
NAME: spi_isp
*
*
PARAMS: none
*
return: none
*
PURPOSE:
*
spi - interruption program for serial transmission ( Master and Slave mode )
*
*
NOTE:
*******************************************************************
**********/ Interrupt(void spi_isp(void), IRQ_SPI){
if(Spif_set()){ // Quit if data transfer has not been
completed. transmit_completed = 1;
// Set software complete
flag
SPI_IPNT = SPDAT;
// Store SPI input data in SPI_IPNT. SPDAT - Serial Peripheral Data
R
e
g
i
s
t
e
r
return
;
}
}
/*F**************************************************************************
*
NAME: spi_set_speed
*
PARAMS: ratio: spi clock ratio/XTAL
*
return: Uchar: status
*
PURPOSE:
*
Configure the baud rate of the spi, set CR2, CR1, CR0
*
NOTE:
*
This function is only used in spi master mode, called by spi_master_init
*******************************************************************
**********/ Uchar spi_set_speed(Uchar data ratio){
switch(ratio){ // Set SPCON register
case 2: SPCON |= SPI_RATIO_2; break; // FCLK PERIPH/2 case 4: SPCON