📄 spi.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
*
*
****************************************************************************/
#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)
{
/* Open MCBSP Port 0, this will return a MCBSP handle that will */
/* be used in calls to other CSL functions. */
hMcbsp0 = MCBSP_open(MCBSP_PORT0, MCBSP_OPEN_RESET);
MCBSP_RSETH(hMcbsp0,SPCR1,0x0000);
MCBSP_RSETH(hMcbsp0, SPCR2,0x0000);
//;;Step 2
//;;Write PCR0 address into SPSA0
MCBSP_RSETH(hMcbsp0, PCR,pcrValue);
// ;;Write into RCR10 address into SPSA0
MCBSP_RSETH(hMcbsp0,RCR1 ,0x0000);
MCBSP_RSETH(hMcbsp0,RCR2 ,0x000D);
//Write into XCR10 address into SPSA0
MCBSP_RSETH(hMcbsp0, XCR1,0x0000);
MCBSP_RSETH(hMcbsp0, XCR2,xcr2Value);
//Write into SPSA0 with SPCR10 clkstop mode enabled
MCBSP_RSETH(hMcbsp0,SPCR1 ,0x1800);
MCBSP_RSETH(hMcbsp0,SPCR2 ,0x0080);
//Write into SPSA0 with SRGR10 address
MCBSP_RSETH(hMcbsp0,SRGR1 ,frequency);
MCBSP_RSETH(hMcbsp0, SRGR2,0x2000);
//;;Step3
//;;set GRST = 1 in spcr20
//;;write SPCR20 address with SPSA0
MCBSP_RSETH(hMcbsp0,SPCR2 ,0x00C0);
//Step4
//;;delay
//Step5
//;;Write into SPSA0 with SPCR10 address
MCBSP_RSETH(hMcbsp0, SPCR1,0x1801);
//;Write into SPSA0 with SPCR20 address
MCBSP_RSETH(hMcbsp0, SPCR2,0x00C3);
/* end init */
}
/*
* 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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -