打印

串口程序加上定时中断怎不好使,还没入门请高手指点,附

[复制链接]
1433|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
cmeihua|  楼主 | 2008-6-28 10:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我的源代码:

#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
void delay_loop(void);
void spi_xmit(Uint16 a);
void spi_fifo_init(void);
void spi_init(void);
interrupt void cpu_timer0_isr(void);
//interrupt void cpu_timer0_isr(void);
Uint16 sdata;  // send data
Uint16 rdata;
short Hrdata,Lrdata;  // received data
float  temp;

/***********************/
void scia_loopback_init(void);
void scia_fifo_init(void);
void scia_xmit(int a);
void error(int);
interrupt void scia_rx_isr(void);
interrupt void scia_tx_isr(void);

// Global counts used in this example
Uint16 LoopCount;
Uint16 ErrorCount,i,j;
int n=0;
void main(void)
{
    Uint16 SendChar;
    Uint16 ReceivedChar;

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

// Step 2. Select GPIO for the device or for the specific application:
// This function is found in the DSP2833x_Gpio.c file.
// InitGpio(); skip this as this is example selects the I/O
// for SCI-A in this file itself
   InitSciGpio();
   InitSpiaGpio();
// 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 DSP2833x_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 DSP2833x_PieCtrl.c file.
      // InitPieCtrl();  PIE is not used for this example

      // Initialize the PIE Vector Table To a Known State:
      // This function is found in DSP2833x_PieVect.c.
      // This function populates the PIE vector table with pointers
      // to the shell ISR functions found in DSP2833x_DefaultIsr.c.
      InitPieVectTable();

    

    EALLOW;
    PieVectTable.TINT0=&cpu_timer0_isr;
    EDIS;
    InitCpuTimers();
    ConfigCpuTimer(&CpuTimer0,150,1000);//800us
    StartCpuTimer0();
    IER|=M_INT1;
    PieCtrlRegs.PIEIER1.bit.INTx7=1;
    EINT;
    ERTM;
//    CpuTimer0Regs.TCR.bit.TSS=0;
    
      // Enable CPU and PIE interrupts
      // This example function is found in the DSP2833x_PieCtrl.c file.
  //EnableInterrupts();

// Step 4. Initialize all the Device Peripherals to a known state:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); skip this for SCI tests

// Step 5. User specific functions, Reassign vectors (optional), Enable Interrupts:

    LoopCount = 0;
    ErrorCount = 0;

    scia_fifo_init();       // Initialize the SCI FIFO
    scia_loopback_init();  // Initalize SCI for digital loop back
   spi_fifo_init();      // Initialize the Spi FIFO
    spi_init();        
    // Note: Autobaud lock is not required for this example

    // Send a character starting with 0
    SendChar = 0;

// Step 6. Send Characters forever starting with 0x00 and going through
// 0xFF.  After sending each, check the recieve buffer for the correct value

    for(;;)
    {
        while(CpuTimer0.InterruptCount<3);
        CpuTimer0.InterruptCount=0;
        spi_xmit(0x0400);
        while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) {}     
        rdata = SpiaRegs.SPIRXBUF;
        Hrdata=(rdata>>8);
          Lrdata=(rdata&0x00ff);
         rdata =rdata&0x3fff;
       scia_xmit(Hrdata);
   scia_xmit(Lrdata);
//       while(SciaRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for RRDY/RXFFST =1 for 1 data available in FIFO

       // Check received character
//       ReceivedChar = SciaRegs.SCIRXBUF.all;
//       if(ReceivedChar != SendChar) error(1);

       // Move to the next character and repeat the test
//       SendChar++;
       // Limit the character to 8-bits
//       SendChar &= 0x00FF;
        LoopCount++;
        for(i=0;i<=10000;i++)
        {for(j=0;j<150;j++);}
        EALLOW;
        SysCtrlRegs.WDKEY=0xAA;
        EDIS;
    }

}

interrupt void cpu_timer0_isr(void)
{
   CpuTimer0.InterruptCount++;
   n++;
    EALLOW;
    SysCtrlRegs.WDKEY=0x55;
    EDIS;
    PieCtrlRegs.PIEACK.all=PIEACK_GROUP1;

}
// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:

void error(int ErrorFlag)
{
      Uint16 Error = ErrorFlag;
      ErrorCount++;
//    asm("     ESTOP0");  // Uncomment to stop the test here
//    for (;;);

}

// Test 1,SCIA  DLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity
void scia_loopback_init()
{
    // Note: Clocks were turned on to the SCIA peripheral
    // in the InitSysCtrl() function

     SciaRegs.SCICCR.all =0x0007;   // 1 stop bit,  No loopback
                                   // No parity,8 char bits,
                                   // async mode, idle-line protocol
    SciaRegs.SCICTL1.all =0x0003;  // enable TX, RX, internal SCICLK,
                                   // Disable RX ERR, SLEEP, TXWAKE
    SciaRegs.SCICTL2.all =0x0003;
    SciaRegs.SCICTL2.bit.TXINTENA =1;
    SciaRegs.SCICTL2.bit.RXBKINTENA =1;
    SciaRegs.SCIHBAUD    =0x0001;
    SciaRegs.SCILBAUD    =0x00E7;
//    SciaRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back
    SciaRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset
}

// Transmit a character from the SCI'
void scia_xmit(int a)
{
    SciaRegs.SCITXBUF=a;
}

// Initalize the SCI FIFO
void scia_fifo_init()
{
    SciaRegs.SCIFFTX.all=0xE040;
    SciaRegs.SCIFFRX.all=0x204f;
    SciaRegs.SCIFFCT.all=0x0;

}

void delay_loop()
{
    long      i;
    for (i = 0; i < 100000; i++) {}
}
void spi_init()
{    

    SpiaRegs.SPICCR.bit.SPISWRESET = 0;
    SpiaRegs.SPICCR.all =0x004F;                 // 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;                                    
//    SpiaRegs.SPICCR.all =0x008F;                 // Relinquish SPI from Reset   
//    SpiaRegs.SPIPRI.bit.FREE = 1;                // Set so breakpoints don't disturb xmission
    SpiaRegs.SPICCR.bit.SPISWRESET = 1;
}

void spi_xmit(Uint16 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_CPIC| | 2008-7-8 10:02 | 只看该作者

RE


建议不要采用定时器中断来喂狗。另外喂狗语句也有问题,正确的写法如下:
 
EALLOW;
    SysCtrlRegs.WDKEY = 0x0055;
    SysCtrlRegs.WDKEY = 0x00AA;
EDIS;

使用特权

评论回复
板凳
qgaoyong| | 2009-12-1 20:40 | 只看该作者
你的狗有问题,就是喂狗有很大问题,可能不停产生中断

使用特权

评论回复
地板
thf2008| | 2009-12-1 22:03 | 只看该作者
学习了

使用特权

评论回复
5
午夜粪车| | 2009-12-2 17:45 | 只看该作者
好长的代码啊

使用特权

评论回复
6
贾君鹏子| | 2009-12-2 18:18 | 只看该作者
喂狗有什么问题啊?

使用特权

评论回复
7
skypoet| | 2009-12-5 11:07 | 只看该作者
狗狗在一给定的时间内收不到喂狗的数据,就会强制复位

使用特权

评论回复
8
午夜粪车| | 2009-12-5 23:13 | 只看该作者
是狗的问题吗?

使用特权

评论回复
9
linhai2009| | 2009-12-7 00:42 | 只看该作者
不应该是狗的问题吧

使用特权

评论回复
10
linhai2009| | 2009-12-7 00:43 | 只看该作者
我用串口的时候就从来没喂过狗

使用特权

评论回复
11
god_like| | 2009-12-7 01:09 | 只看该作者
咋不好使了?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

7

主题

12

帖子

0

粉丝