搜索
bottom↓
回复: 0

TSM320f28335的SCIb和SCIc查询发现中断接收

[复制链接]

出0入0汤圆

发表于 2013-7-25 21:08:13 | 显示全部楼层 |阅读模式
本帖最后由 daidaimumu 于 2013-7-25 21:23 编辑

TSM320f28335的SCIb和SCIc查询发现中断接收使用FIFO功能的简单例程

#include "DSP2833x_Device.h"     // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h"   // DSP2833x Examples Include File

// Prototype statements for functions found within this file.
void scic_echoback_init(void);
void scib_echoback_init(void);

void scic_fifo_init(void);
void scib_fifo_init(void);

void scic_xmit(int a);
void scic_msg(char *msg);

void scib_xmit(int a);
void scib_msg(char *msg);

interrupt void scib_INT(void);
interrupt void scic_INT(void);

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

void main(void)
{

  //  Uint16 ReceivedChar;
    char *msg;

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
   InitSysCtrl();

// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
   // InitGpio(); Skipped for this example

// For this example, only init the pins for the SCI-A port.
// This function is found in the DSP2833x_Sci.c file.
        InitScibGpio();
    InitScicGpio();

   InitXintf16Gpio();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
   DINT;

// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
   InitPieCtrl();

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

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
   InitPieVectTable();
   EALLOW;

        PieVectTable.SCIRXINTB= &scib_INT;    //SCIB 接收 中断入口地址
        PieVectTable.SCIRXINTC= &scic_INT;    //SCIC 接收 中断入口地址

   EDIS;

// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example

// Step 5. User specific code:

    LoopCount = 0;
    ErrorCount = 0;

    scic_fifo_init();           // Initialize the SCI FIFO     
    scic_echoback_init();  // Initalize SCI for echoback

        scib_fifo_init();
        scib_echoback_init();

   PieCtrlRegs.PIEIER9.bit.INTx3=1;     // PIE Group 9, INT3 使能PIE模块的SCIB 接收中断
   PieCtrlRegs.PIEIER8.bit.INTx5=1;                //PIE Group 8, INT5  使能PIE模块的SCIC 接收中断

    IER |= M_INT9;     //开CPU中断 Group9 对应SCIB 中断
        IER |= M_INT8;     //开CPU中断 Group8 对应SCIC 中断

    msg = "\r\n\n\nHello Yan Xu!\0";
    scic_msg(msg);
        scib_msg(msg);

    msg = "\r\nYou will enter a character, and the DSP will echo it back! \n\0";
    scic_msg(msg);
        scib_msg(msg);
          
// Enable global Interrupts and higher priority real-time debug events:
    EINT;   // Enable Global interrupt INTM  开全局中断
    ERTM;   // Enable Global realtime interrupt DBGM  开全局实时中断

        for(;;)
    {
         LoopCount++;
    }

}


// Test 1,SCIA  DLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity
void scic_echoback_init()
{
    // Note: Clocks were turned on to the SCIA peripheral
    // in the InitSysCtrl() function
//scic
        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.SCICTL2.all =0x0003;
        ScicRegs.SCICTL2.bit.TXINTENA = 0;
        ScicRegs.SCICTL2.bit.RXBKINTENA =1;
        #if (CPU_FRQ_150MHZ)
              ScicRegs.SCIHBAUD    =0x0001;  // 9600 baud @LSPCLK = 37.5MHz.
              ScicRegs.SCILBAUD    =0x00E7;
        #endif
        #if (CPU_FRQ_100MHZ)
      ScicRegs.SCIHBAUD    =0x0001;  // 9600 baud @LSPCLK = 20MHz.
      ScicRegs.SCILBAUD    =0x0044;
        #endif
        ScicRegs.SCICTL1.all =0x0023;  // Relinquish SCI from Reset

}

void scib_echoback_init()
{
//scib
        ScibRegs.SCICCR.all =0x0007;   // 1 stop bit,  No loopback
                                   // No parity,8 char bits,
                                   // async mode, idle-line protocol
        ScibRegs.SCICTL1.all =0x0003;  // enable TX, RX, internal SCICLK,
                                   // Disable RX ERR, SLEEP, TXWAKE
        ScibRegs.SCICTL2.all =0x0003;
        ScibRegs.SCICTL2.bit.TXINTENA = 0;
        ScibRegs.SCICTL2.bit.RXBKINTENA =1;
        #if (CPU_FRQ_150MHZ)
              ScibRegs.SCIHBAUD    =0x0001;  // 9600 baud @LSPCLK = 37.5MHz.
              ScibRegs.SCILBAUD    =0x00E7;
        #endif
        #if (CPU_FRQ_100MHZ)
      ScibRegs.SCIHBAUD    =0x0001;  // 9600 baud @LSPCLK = 20MHz.
      ScibRegs.SCILBAUD    =0x0044;
        #endif

        ScibRegs.SCICTL1.all =0x0023;   // Relinquish SCI from Reset

}


// Transmit a character from the SCI
void scic_xmit(int a)
{
    while (ScicRegs.SCIFFTX.bit.TXFFST != 0) {}
          ScicRegs.SCITXBUF=a;

}

void scic_msg(char * msg)
{
    int i;
    i = 0;
    while(msg != '\0')
    {
        scic_xmit(msg);
        i++;
    }
}

void scib_xmit(int a)
{
    while (ScibRegs.SCIFFTX.bit.TXFFST != 0) {}
    ScibRegs.SCITXBUF=a;

}

void scib_msg(char * msg)
{
    int i;
    i = 0;
    while(msg != '\0')
    {
        scib_xmit(msg);
        i++;
    }
}


// Initalize the SCI FIFO
void scic_fifo_init()
{
    ScicRegs.SCIFFTX.all=0xE040;
    ScicRegs.SCIFFRX.all=0x6061;
   ScicRegs.SCIFFCT.all=0x0;

}

void scib_fifo_init()
{

    ScibRegs.SCIFFTX.all=0xE040;
    ScibRegs.SCIFFRX.all=0x6061;
           ScibRegs.SCIFFCT.all=0x0;

}

//SCIB中断接收程序
interrupt void scib_INT(void)
{

    Uint16 ReceivedChar1;
    char *msg1;

       // Get character
       ReceivedChar1 = ScibRegs.SCIRXBUF.all;

       // Echo character back
       msg1 = "  You sent: \0";
                scib_msg(msg1);
             scib_xmit(ReceivedChar1);

            msg1 = "\r\n\0";
                scib_msg(msg1);

        ScibRegs.SCIFFRX.bit.RXFFOVRCLR=1;
        ScibRegs.SCIFFRX.bit.RXFFINTCLR=1;
        PieCtrlRegs.PIEACK.all = PIEACK_GROUP9;

        EINT;
}

//SCIC中断接收程序
interrupt void scic_INT(void)
{
    Uint16 ReceivedChar1;
    char *msg1;

       ReceivedChar1 = ScicRegs.SCIRXBUF.all;

       // Echo character back
       msg1 = "  You sent: \0";
                scic_msg(msg1);

           scic_xmit(ReceivedChar1);

           msg1 = "\r\n\0";
           scic_msg(msg1);
                  
        ScicRegs.SCIFFRX.bit.RXFFOVRCLR=1;
        ScicRegs.SCIFFRX.bit.RXFFINTCLR=1;
        PieCtrlRegs.PIEACK.all = PIEACK_GROUP8;
        EINT;
}


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-3 11:09

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表