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

📄 dsp281x_spi.c

📁 2812使用spi读写fm25cl64或者at25640的程序
💻 C
字号:
// TI File $Revision: /main/2 $
// Checkin $Date: April 29, 2005   11:08:24 $
//###########################################################################
//
// FILE:   DSP281x_Spi.c
//
// TITLE:  DSP281x SPI Initialization & Support Functions.
//
//###########################################################################
// $TI Release: DSP281x Header Files V1.11 $
// $Release Date: September 26, 2007 $
//###########################################################################

#include "DSP281x_Device.h"     // DSP281x Headerfile Include File
#include "DSP281x_Examples.h"   // DSP281x Examples Include File
#include "dspCtrl.h"

//---------------------------------------------------------------------------
// InitSPI: 
//---------------------------------------------------------------------------
// This function initializes the SPI(s) to a known state.
//
void InitSpi(void)
{
   // Initialize SPI-A:
   EALLOW;
   SpiaRegs.SPICCR.all=0x0007;       //16-bit character, No Loopback mode
   //SpiaRegs.SPICTL.all=0x0017;       //Interrupt enabled, Master/Slave XMIT enabled
   SpiaRegs.SPICTL.all=0x0006;       //Interrupt disabled
   //SpiaRegs.SPISTS.all=0x0000;
   SpiaRegs.SPIBRR = 3;           // Baud rate  30Mhz /(3 + 1) = 7.5MHz
   SpiaRegs.SPIPRI.all = 0x30;	// free run
   Init_Spi_GPIO();
   SpiaRegs.SPICCR.all=0x0087;//使SPI退出复位状态
   SpiaRegs.SPICCR.bit.CLKPOLARITY = 0;
   SpiaRegs.SPICTL.bit.CLK_PHASE   = 1;
   EDIS;
   //tbd...
 
}

void Init_Spi_GPIO(void)
{
   EALLOW;
   GpioMuxRegs.GPFMUX.all |= 0x0f;
   GpioMuxRegs.GPFMUX.bit.SPISTEA_GPIOF3 = As_GPIO;
   GpioMuxRegs.GPFDIR.bit.GPIOF3 = OUT_DIR;
   GpioDataRegs.GPFDAT.bit.GPIOF3 = 1;
   EDIS;
}

Uint16 EEPROM_Read(Uint16 address)
{
	Uint16 data;
	GpioDataRegs.GPFDAT.bit.GPIOF3 = 0;
	SpiWrite(READ);
      SpiWrite(address & 0xff00);
	SpiWrite(address<<8);
	data = SpiWrite(0x00);	
	GpioDataRegs.GPFDAT.bit.GPIOF3 = 1;
	return data;
}

void EEPROM_Write_Enable(void)
{
	GpioDataRegs.GPFDAT.bit.GPIOF3 = 0;
	SpiWrite(WREN);
	GpioDataRegs.GPFDAT.bit.GPIOF3 = 1;
}


void EEPROM_Write(Uint16 address,Uint16 data)
{
      Uint16 i;
	EEPROM_Write_Enable();
	GpioDataRegs.GPFDAT.bit.GPIOF3 = 0;
	SpiWrite(WRITE);
	SpiWrite(address & 0xff00);
	SpiWrite(address<<8);
	SpiWrite(data << 8);
	GpioDataRegs.GPFDAT.bit.GPIOF3 = 1; 
}

Uint16 EEPROM_Read_Status()
{
	Uint16 i1,data;
	GpioDataRegs.GPFDAT.bit.GPIOF3 = 0;
	SpiWrite(RDSR);
	data = SpiWrite(0x00);
	GpioDataRegs.GPFDAT.bit.GPIOF3 = 1;
	//判断SPI发送准备好
	return data;
}

Uint16 SpiWrite(Uint16 data)
{
   Uint16 ret;
   SpiaRegs.SPITXBUF = data;
   while(Spi_RxReady() == 0);
   ret = SpiaRegs.SPIRXBUF;
   return ret;
}

Uint16 Spi_TxReady(void)
{
	Uint16 in;
	if(SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1)
	{
		in = 0;
	}
	else
	{
		in = 1;
	}
	return(in);
}

Uint16 Spi_RxReady(void)
{
	Uint16 im;
	if(SpiaRegs.SPISTS.bit.INT_FLAG == 1)
	{
		im = 1;
	}
	else
	{
		im = 0;
	}
	return(im);	
}

//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

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