28335无法进入SCI FIFO中断问题探究

问题的关键在于SCIFFTX,SCIFFRX的bit一定要置1

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

// Prototype statements for functions found within this file.
void Scic_loopback_init(void);
void Scic_fifo_init(void);
void Scic_xmit(int a);
int  Scic_recv(void);
void error();

__interrupt void scicTxFifoIsr(void);
__interrupt void scicRxFifoIsr(void);

// Global counts used in this example
Uint16 LoopCount;
Uint16 ErrorCount;
Uint16 ReceivedChar;

Uint16 sdataB[8];    // Send data for SCI-B
Uint16 rdataB[8];    // Received data for SCI-A

void main(void)
{
    Uint16 i;

// 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();

// 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;
    InitPieCtrl();
    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;  // This is needed to write to EALLOW protected registers
    PieVectTable.SCIRXINTC = &scicRxFifoIsr;
    PieVectTable.SCITXINTC = &scicTxFifoIsr;
    EDIS;   // This is needed to disable write to EALLOW protected registers

// Enable CPU and PIE interrupts
// This example function is found in the DSP2833x_PieCtrl.c file.
    PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
    PieCtrlRegs.PIEIER8.bit.INTx5=1;     // PIE Group 9, int1
    PieCtrlRegs.PIEIER8.bit.INTx6=1;     // PIE Group 9, INT2

    IER|=M_INT8; // Enable CPU INT
    EINT;

// 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;

    for(i = 0; i<8; i++)
    {
       sdataB[i] = 0xFF - i;
    }

    Scic_loopback_init();  // Initialize SCI for digital loop back

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

    for(;;)
    {
       LoopCount++;
    }
}

// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:
void error()
{
    ErrorCount++;
    __asm("     ESTOP0");  // Uncomment to stop the test here
    for (;;);
}

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

    ScicRegs.SCICCR.all =0x0007;   // 1 stop bit,  No loopback
                                   // No parity,8 char bits,
                                   // async mode, idle-line protocol
    ScicRegs.SCICTL1.all =0x0003;  // enable TX, RX, internal SCICLK,
                                   // Disable RX ERR, SLEEP, TXWAKE
    ScicRegs.SCIHBAUD    =0x0001;
    ScicRegs.SCILBAUD    =0x00E7;
    ScicRegs.SCIFFTX.all =0xE060; //bit5一定要置1使能中断,bit4~bit0表示缓冲多少个字节进中断
    ScicRegs.SCIFFRX.all =0x2068; //bit5一定要置1使能中断,bit4~bit0表示缓冲多少个字节进中断
    ScicRegs.SCIFFCT.all =0x0;

    ScicRegs.SCIFFTX.bit.TXFIFOXRESET=1;//重新使能发送fifo操作
    ScicRegs.SCIFFRX.bit.RXFIFORESET=1; //重新使能接收fifo操作
    ScicRegs.SCICTL1.all =0x0023;       // Relinquish SCI from Reset  重启sci
}

// Transmit a character from the SCI'
void Scic_xmit(int a)
{
    while(ScicRegs.SCICTL2.bit.TXRDY!=1){}
    ScicRegs.SCITXBUF = a;
}
int Scic_recv(void)
{
    while(SciaRegs.SCIRXST.bit.RXRDY!=1){} // wait for XRDY =1 for empty state
    return SciaRegs.SCIRXBUF.all;
}

__interrupt void scicTxFifoIsr(void)
{
    Uint16 i;
    for(i=0; i< 8; i++)
    {
       ScicRegs.SCITXBUF=sdataB[i];     // Send data
    }

    ScicRegs.SCIFFTX.bit.TXFFINTCLR=1;  // Clear Interrupt flag
    PieCtrlRegs.PIEACK.bit.ACK8=1;
}

__interrupt void scicRxFifoIsr(void)
{
    Uint16 i;
    for(i=0;i<8;i++)
    {
       rdataB[i]=ScicRegs.SCIRXBUF.all;  // Read data
    }

    ScicRegs.SCIFFRX.bit.RXFFOVRCLR=1;  // Clear Overflow flag
    ScicRegs.SCIFFRX.bit.RXFFINTCLR=1;  // Clear Interrupt flag
    PieCtrlRegs.PIEACK.bit.ACK8=1;
}

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

猜你喜欢

转载自blog.csdn.net/qianshishangdi/article/details/82526189