首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

TMS320F2407扩展EEPROM问题请教,附相关程序

TMS320F2407扩展EEPROM问题请教,附相关程序

我用TMS320F2407的SPI外扩EEPROM,EEPROM的型号为ATMEL25640A,在通讯时收不到EEPROM返回的数据,请教做过相关项目的朋友,请指点一二.不胜感激!
附上读取EEPROM状态的程序.
#include "register.h"

/********SPI MEMORY INSTRUCTION SFR DEFINES****************/
#define WREN 0x0006
#define WRDI 0x0004
#define RDSR 0x0005
#define WRSR 0x0001
#define READ 0x0003
#define WRITE 0x0002


#define READY_TO_SEND      0x0000      //the SPI interface is ready to send
#define TRANSFER_COMPLETED 0x000C      //the read access is completed whithout error
#define BUSY               0x0005      //the SPI memory or the SPI interface is busy.
#define INSTRUCTION        0x0001      //the op_code has been transferred
#define SEND_COMPLETED     0x0006     //multi_bytes transmit completed
#define ADDRESS            0x0002     //address of Eprom is two bytes long
#define DATA               0x0004
#define FULL               0x000A
#define BUSY1              0x000B


/**************************the follow program are set the i/o port to

select|deselect EEPROM
******************************************************************/
/****************************IOPORT_INITIAL***************************/
void IoportInital()
{
 *MCRC=*MCRC&0x0000;   //config IOPE,IOPF as IOPORT
 *PFDATDIR=*PFDATDIR|0xFF00;  //portF as output
}


/*********************CHIP_SELECT*********************************/
void ChipSelect()
{
  *PFDATDIR=*PFDATDIR&0xFF00;  //pull down cs, port value=0
}

/*********************CHIP_DESELECT***************************/
void ChipDeselect()
{
  *PFDATDIR=*PFDATDIR|0x00FF; //pull high cs,port value=1
}


/*******Disable Interrupt*******/
void inline disable()
{
  asm(" setc INTM ");
}


/*******Enable Interrupt********/

void inline enable()
{
  asm(" clrc INTM ");
}


/*******System Initial************/

void initial()
{
  asm(" setc SXM ");
  asm(" clrc OVM ");
  asm(" clrc CNF ");
  *SCSR1=0x8322;  //CLKIN=20M,CLKOUT=20M*2=40M,Enable SPI Clock
  *WDCR=0x0E8;    //Disable WatchDog
  *IMR=0x0001;    //Enable Interrupt1(High PRI SPI interrupt)
  *IFR=0x0FFFF;   //Clear Interrupt Flag
  *WSGR=0x0000;   //Disable WaitState
}


/***********SPI_INT_ENABLE******
**********************************/
void spi_int_enable()
{
 // *SPICCR&=0x007F;  //enter Reset mode to configure SFR
  *SPICTL|=0x0001;
 // *SPICCR|=0x0080;  //quit Reset mode(corressponding to firtst line
}

/*****************************************/

/***********SPI_INT_DISABLE***************/
void spi_int_disable()
{
//  *SPICCR=*SPICCR&0x007F;  //enter Reset mode to configure SFR
  *SPICTL=*SPICTL&0xFFFE;
 // *SPICCR=*SPICCR|0x0080;  //quit Reset mode(corressponding to firtst line
}

/*****************************************/


/***********SPI Initial**************/

int spi_initial()
{
  *SPICCR=0x0007;      //8 char bits,data transfer at rising edge
                       //and receive at falling edge enter Reset mode
  *SPICTL=0x0007;      //enable spi int,enable transfer,work mode: master
 // *SPIBRR=0x0003;      //CLKOUT=40M,BAUDRATE=10M,according to formula
  *SPIBRR=0x0007;      //CLKOUT=40M,BAUDRATE=5M,according to formula
  *MCRB=0x003C;        //set IO as SPI function port
  *SPICCR|=0x0080;     //quit Reset mode,in accordance with the first line
  state=READY_TO_SEND;
}


/*********SPI_TRANSFER****************

*the function is the elementary function that handles the spi********
*interface in polling mode.it sends a byte and stores the received one**

******************************************/
int spi_transfer(int data)
{
  int flag,data_in=0x0000;
  flag=*SPISTS&0x0040;       //flag=SPI INT FLAG
  *SPITXBUF=(data<<8);
  while(flag=!0x0040){;}
  return (*SPIRXBUF>>8);        

/************GetStatuRegister**************

**this function performs a RDSR access,it returns the access status code**
 
********************************************/
int GetStatusRegister(int *status)
{
  if(state==READY_TO_SEND)
    {
     spi_int_disable();       //read the spi memory status register,disable interrupt first
     ChipSelect();            //pull down the CS
     spi_transfer(RDSR);      //transmit the op_code RDSR
     *status=spi_transfer(0xFF); //get the status value
     inner++;
     ChipDeselect();           // pull high the CS
     spi_int_enable();         //enable interrupt
     return TRANSFER_COMPLETED; //transfer completed
    }
  else
    {
     *status=1;
     return BUSY;
    }
 }
 

/*********************************main*************************************/
void main()
{
  int inner;
   disable();    //disable all interrupt
  initial();    //system initial
  spi_initial();  //spi initial  
  IoportInital();  //ioport initial
  enable();     //enable interrupt
  while(1)
   {
     inner=GetStatusRegister(&jj);
   }

我用这样的程序读取EEPROM的状态字,却收不到返回的信号,请问是哪里出了问题?

拜谢!
 

竟然没有回复,太残酷了......
返回列表