网站公告列表

  没有公告

加入收藏
设为首页
联系站长
您现在的位置: 61IC中国电子在线 >> DSP >> 代码示例 >> TI DSP代码示例 >> C2000 >> 文章正文
  TMS320F2812 SPI_FFDLB范例程序         ★★★ 【字体:
TMS320F2812 SPI_FFDLB范例程序
作者:61IC    文章来源:本站原创    点击数:    更新时间:2007-1-16    

//
//      TMDX ALPHA RELEASE
//      Intended for product evaluation purposes
//
//###########################################################################
//
// FILE: Example_28xSpi_FFDLB.c
//
// TITLE: DSP28 Device Spi Digital Loop Back porgram.
//   All these tests will self validate the code and update the
//          Test status in Test_status array.
//   And PASS_Flag =0xDOBE for pass, 0xDEAD for fail
//
//  Test 1  SPI  16-bit character, Internal loop back
//          In MASTER MODE  Rising edge, baud rate =0x07f
//  
//  
//  
//
//###########################################################################
//
//  Ver | dd mmm yyyy | Who  | Description of changes
// =====|=============|======|===============================================
//  0.56| 06 May 2002 | S.S. | EzDSP Alpha Release
//  0.57| 27 May 2002 | L.H. | No change
//  0.58| 03 July2002 | S.S. | SPI example
//###########################################################################


#include "DSP28_Device.h"
#include "DSP28_Globalprototypes.h"

// Prototype statements for functions found within this file.
// interrupt void ISRTimer2(void);
void delay_loop(void);
void spi_dlb16(void);
void spi_xmit(int a);
void spi_fifo_init(void); 
void error(int);
void program_stop();
unsigned int var1 = 0;
unsigned int var2 = 0;
unsigned int var3 = 0;
unsigned int var4 = 0;
unsigned int var5 = 0;
unsigned int test_count = 0;
unsigned int Test_flag1 = 0;
unsigned int Test_flag2 = 0;
unsigned int Test_flag3 = 0;
unsigned int Test_flag4 = 0;
unsigned int Test_var  = 0;
unsigned int Test_status[32];
unsigned int PASS_flag = 0;

void main(void)
{

// Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to default state:
        // This function is found in the DSP28_SysCtrl.c file.
 InitSysCtrl();

 

// Step 2. Select GPIO for the device or for the specific application:
        // This function is found in the DSP28_Gpio.c file.
// InitGpio(); skip this as this is example selects the I/O for McBSP in this file itself
  EALLOW;
 
     GpioMuxRegs.GPFMUX.all=0x000F; // Select GPIOs to be SPI pins 
          // Port F MUX - x000 0000 0000 1111
             
     EDIS;

// Step 3. Initialize PIE vector table:
 // The PIE vector table is initialized with pointers to shell Interrupt
        // Service Routines (ISR).  The shell routines are found in DSP28_DefaultIsr.c.
 // Insert user specific ISR code in the appropriate shell ISR routine in
        // the DSP28_DefaultIsr.c file.

 // Disable and clear all CPU interrupts:
 DINT;
 IER = 0x0000;
 IFR = 0x0000;

 // Initialize Pie Control Registers To Default State:
        // This function is found in the DSP28_PieCtrl.c file.
 InitPieCtrl();

 // Initialize the PIE Vector Table To a Known State:
        // This function is found in DSP28_PieVect.c.
 // This function populates the PIE vector table with pointers
    // to the shell ISR functions found in DSP28_DefaultIsr.c.
 InitPieVectTable(); 
 
// Step 4. Initialize all the Device Peripherals to a known state:
 // This function is found in DSP28_InitPeripherals.c
    // InitPeripherals(); skip this for GPIO tests
 
// Step 5. User specific functions, Reassign vectors (optional), Enable Interrupts:

 
    spi_fifo_init(); // Initialize the Spi FIFO
 
 spi_dlb16();  // Digital loop back test


// Update Test status 
 if(PASS_flag !=0)
    PASS_flag=0xDEAD;        // Test code exit here..
 else
    PASS_flag=0xD0BE;        // Test code exit he
 
// EALLOW; // This is needed to write to EALLOW protected registers
// PieVectTable.TINT2 = &ISRTimer2;
// EDIS;   // This is needed to disable write to EALLOW protected registers
   

    // Enable INT14 which is connected to CPU-Timer 2:
// IER |= M_INT14;

    // Enable global Interrupts and higher priority real-time debug events:
 
// EINT;   // Enable Global interrupt INTM
// ERTM; // Enable Global realtime interrupt DBGM

// Step 6. IDLE loop. Just sit and loop forever (optional): 
    asm("     ESTOP0");   // Break point
 for(;;);

}  


// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here: 
 // If local ISRs are used, reassign vector addresses in vector table as
    // shown in Step 5
/*
// Interrupt function template
interrupt void ISRTimer2(void)
{
 
}
*/

// Some Useful local functions
void delay_loop()
{
    long      i;
    for (i = 0; i < 1000000; i++) {}
}


void error(int ErrorFlag)
{
    PASS_flag =0xDEAD;
    Test_status[ Test_var]= 0xDEAD;    
//    asm("     ESTOP0");      // Test failed!! Stop!
//    for (;;);

}

//  Test 1,SPI  16-bit character, Internal loop back
//  In MASTER MODE  Rising edge, baud rate =0x07f
 
void spi_dlb16()
 {   
   
 SpiaRegs.SPICCR.all =0x000F;              // Reset on, rising edge, 16-bit char bits 
      
 SpiaRegs.SPICTL.all =0x0006;           // Enable master mode, normal phase,
                                                 // enable talk, and SPI int disabled.
 SpiaRegs.SPIBRR =0x007F;         

// Bit changes to registers       

// Release Reset for SPI  
    SpiaRegs.SPICCR.all =0x009F;           // Relinquish SPI from Reset  
                                                 // Bit 4 loop back mode enabled
// Bit changes for the test 
 
    var3 =0x4141;       
    spi_xmit(var3);
    while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }    
    Test_flag4 = SpiaRegs.SPIRXBUF;    
    if(Test_flag4 != 0x4141) error(1);
    Test_status[ Test_var]= 0x8000;       // update Test_status test number
    Test_var++;
 
    }

 

void spi_xmit(int a)
{

    SpiaRegs.SPITXBUF =a;

   
}   

void spi_fifo_init()          
{
// Initialize SPI FIFO registers
    SpiaRegs.SPIFFTX.all=0xE040;
    SpiaRegs.SPIFFRX.all=0x204f;
    SpiaRegs.SPIFFCT.all=0x0;
   

                       
 
   


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

               欢迎点击进入:TI德州中文网   (国内唯一针对TI应用的中文技术网站)    文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    TMS320F2812的SPWM原程序
    基于LabVIEW和TMS320F2812的…
    TMS320F2812的CAN调试成功经…
    基于TMS320F2812和μC/OS II…
    TMS320F2812 全局汇编函数
    TMS320F2812 CMD 文件各段含…
    基于TMS320F2812集中供电系统…
    TMS320F2812的CMD文件配置详…
    基于TMS320F2812的多轴伺服控…
    利用TMS320F2812 DSP&DRV592…
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    站长:61IC 湘ICP备05002478号