/*C**************************************************************************
* Module:
/****************************************************************************
* Copyright (c) 2004 ID TECH inc.,
/****************************************************************************
* CREATION_DATE:
/****************************************************************************
* 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
#define MAX_LEN
/*
D E F I N I T I O N
Uchar data SPI_IPNT; // Temp buffer to store SPI data.
Uchar data Command_OUTbuf[MAX_LEN]; // Command output buffer
Uchar data Command_INbuf[MAX_LEN]; // Command input buffer
Uint16 data spilength; // received command length
Uint16 data Command_Length; // output command length
/*
D E C L A R A T I O N
void main(void){
Uint16 data i, j; // Internal counter.
spi_master_init(0, 0, 1, 32); //SPI master mode, initialize to CPOL=0, CPHA=0, SSDIS=1,
bitrate=Fper/32
Enable_spi_interrupt(); // Turn on SPI interrupt in system.
_SPI_SS = 0; // Disable SPI slave during power on, to prevent indeterminate state.
do{ // keep polling...
tasks
if(_DAV_IN){ // If DAV pin is high level, SPI slave has data ready.
phase 1 needs this falling edge.
is 40us in this demo code.
in this subroutine too.
buffer.
high.
Copyright © 2010-2013, International Technologies & Systems Corporation. All rights reserved.
SecureHead SPI Interface with FPC User Manual
main.c
2004.1.10
512
{
// .............
}
_SPI_SS = 1; // To Generate a falling edge. Not useful for clock phase 0, but clock
delay10us(); // Wait for high level get steady.
_SPI_SS = 0; // Pull chip select pin low, ready to start SPI communication.
spilength = 0; // Initialize Command_buf pointer.
while(_DAV_IN){ // Keep polling DAV pin till it turns low level. Polling inverval
spi_Sendout(0xff); // Send out any data to get SPI slave input, delay 40us
Command_INbuf[spilength++] = SPI_IPNT; // Save data into Command_buf.
if(spilength >= MAX_LEN){ // Quit while loop if read the end of input
break;
}
}
_SPI_SS = 1; // Read out all the data from SPI slave, set chip select pin to idle
for(i = 0; i < spilength; i++){ // Send out data from UART port.
put_byte(Command_INbuf[i]);
}
}
{
Page 56 of 67
*/
*/
*/
*/
Other subroutine to handle other
Need help?
Do you have a question about the SecureHead and is the answer not in the manual?