⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spi.c

📁 本文件的内容是实现TMS320VC5510对指纹芯片FPC1011C读写程序
💻 C
字号:
/****************************************************************************
*
*             
*             TEXAS INSTRUMENTS PROPRIETARY INFORMATION
*
*  (c) Copyright, Texas Instruments Incorporated, 2003.
*      All Rights Reserved.
*
*  Property of Texas Instruments Incorporated. Restricted Rights -
*  Use, duplication, or disclosure is subject to restrictions set
*  forth in TI's program license agreement and associated documentation.
*
***************************************************************************** 
*****************************************************************************
*
* NAME: spi.c
*   
*
* DESCRIPTION: functions to read complete image from FPC1010 sensor.
*   
*
*   CREATED:       05/20/2002 
*   MODIFIED:      06/13/2003 
*   
*
****************************************************************************/

#define DRR20_ADDR 			0x2800
#define DXR10_ADDR			(DRR20_ADDR+3)
#define DXR10      			*(ioport volatile unsigned int *)DXR10_ADDR	
#define DRR10_ADDR			(DRR20_ADDR+1)
#define DRR10       		*(ioport volatile unsigned int *)DRR10_ADDR

#define SPCR20_ADDR			(DRR20_ADDR+4)
#define SPCR20      		*(ioport volatile unsigned int *)SPCR20_ADDR
#define SPCR10_ADDR			(DRR20_ADDR+5)
#define SPCR10      		*(ioport volatile unsigned int *)SPCR10_ADDR
#define RCR20_ADDR			(DRR20_ADDR+6)
#define RCR20      			*(ioport volatile unsigned int *)RCR10_ADDR
#define RCR10_ADDR			(DRR20_ADDR+7)
#define RCR10      			*(ioport volatile unsigned int *)RCR20_ADDR
#define XCR20_ADDR			(DRR20_ADDR+8)
#define XCR20      			*(ioport volatile unsigned int *)XCR20_ADDR
#define XCR10_ADDR			(DRR20_ADDR+9)
#define XCR10      			*(ioport volatile unsigned int *)XCR10_ADDR
#define SRGR20_ADDR			(DRR20_ADDR+10)
#define SRGR20      		*(ioport volatile unsigned int *)SRGR20_ADDR
#define SRGR10_ADDR			(DRR20_ADDR+11)
#define SRGR10      		*(ioport volatile unsigned int *)SRGR10_ADDR
#define PCR0_ADDR			(DRR20_ADDR+18)
#define PCR0      			*(ioport volatile unsigned int *)PCR0_ADDR


#include <csl.h>
#include <csl_mcbsp.h>   

#include "spi.h"


MCBSP_Handle hMcbsp0;

/*
 * Function name :  SPI_txReady
 * Arguments     :  none              
 * Return value  :  none
 * Exceptions    : 
 * Description   :  waits till master is ready for transmission.
 */
void SPI_txReady(void)
{



unsigned char t;
	
	do{
	
	//0x2804 Port Address:McBSP 0 Serial Port Control Register 2(SPCR2_0)
	t = *(unsigned volatile ioport *)0x2804;
	}
	while (!( t & 0x02));

}

/*
 * Function name :  SPI_rxReady
 * Arguments     :  none              
 * Return value  :  none
 * Exceptions    : 
 * Description   :  waits till the slave is transmits the data ti master.
 */
void SPI_rxReady(void)
{


	unsigned char temp;
	do{
	////0x2805 Port Address:McBSP 0 Serial Port Control Register 1(SPCR1_0)
	temp = *(unsigned volatile ioport *)0x2805;
	}
	while (!( temp & 0x02));


}

/*
 * Function name :  SPI_init
 * Arguments     :  pcrValue , Frequency , xcr2 value            
 * Return value  :  if succes then returns 0 else error
 * Exceptions    : 
 * Description   :  initializes the McBSP 0 for SPI communication.
 */

void SPI_init(unsigned char pcrValue,unsigned char frequency,unsigned char xcr2Value)
{
	unsigned int temp = 0;
	

	SPCR20 = 0x0380;	/*
							FRST = 1 - Enable Frame Sync Logic
							Free = 1 - Clock Continues to RUN in Breakpoint
							Soft = 1 - Clock Continues to RUN in Breakpoint
						*/

	SPCR10 = 0x1800;	/*
							CLKStop = 3 -Clock Stop Mode with 1/2 cycle delay
						*/

	RCR20 = 0x0040;		/*
//							16-bit Word Length.
					//	*/
					
	RCR10 = 0x0001;		/*
							1-bit Data Delay
						*/

	XCR10 = 0x0040;			// 16 bit tx;

	XCR20 = 0x0041;			// 1 bit delay provided ;  16bit rx;

							


	SRGR20 = 0x2000;		// enabled clksm=1
						/*PCR 10*/
	SRGR10 = 0x00C7;		//Divide by 47;; 48/47+1 = 1Mhz
	
	PCR0 = 0x0F7D;

	/* Enable GRST*/
	temp = SPCR20;		/* GRST = 1 Sample Rate Generator enabled */
	temp |= 0x40;
	SPCR20 = temp;

	/* delay */
	for( temp = 0; temp < 0xff; temp++ );

	temp = SPCR20;
	temp |= 0x01;	/* XRST = 1 Enable transmitter by taking it out of reset */
	SPCR20 = temp;

	/* delay */
	for( temp = 0; temp < 0xff; temp++ );
	
	/* enable the receiver and taking out from the Reset condition */
	temp = SPCR10;
	temp |= 0x01;	/* RRST = 1 Enable receiver by taking it out of reset */
	SPCR10 = temp;

	/* delay */
	for( temp = 0; temp < 0x1ff; temp++ );
		
}



/*
 * Function name :  SPI_txChar
 * Arguments     :  character to be written to the slave          
 * Return value  :  none
 * Exceptions    : 
 * Description   :  write the argument character to slave.
 */
void SPI_txChar(unsigned char character)
{
	unsigned char t;
    SPI_txReady(); 
	/* write the command */
    MCBSP_RSETH(hMcbsp0, DXR1,character);
    
    /* dummy read always needed */
    SPI_rxReady();

 	t = MCBSP_RGETH(hMcbsp0, DRR1);
}
/*
 * Function name :  SPI_rxChar
 * Arguments     :  none
 * Return value  :  character
 * Exceptions    : 
 * Description   :  write the character from to slave.
 */
unsigned char SPI_rxChar(void)
{
	unsigned char character;
    SPI_txReady(); 
	/* write dummy byte to receive the image byte  */
	MCBSP_RSETH(hMcbsp0, DXR1,0xFF);
	 
	SPI_rxReady(); 
     character = MCBSP_RGETH(hMcbsp0,DRR1);    
    
	return character;
}

/*
 * Function name :  SPI_close
 * Arguments     :  none               
 * Return value  :  none
 * Exceptions    : 
 * Description   :  close the spi connection
 */
void SPI_close(void)
{
    MCBSP_close(hMcbsp0);
}

void spi_tx( unsigned char command, unsigned char parameter )
{

    SPI_txReady(); 

	/* write the command */
    DXR10 = ( ( command << 8 ) | ( parameter ) );
    

}


unsigned int spi_rx( void )
{
	unsigned int val = 0;

	SPI_rxReady();

    val = DRR10;    
    
	return val;
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -