sci_loopback_int的例程(中断程序)

2023-05-16

例程代码如下:




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



#define CPU_FREQ         40E6        // Default = 40 MHz. Change to 60E6 for 60 MHz devices

#define LSPCLK_FREQ CPU_FREQ/4

#define SCI_FREQ         100E3

#define SCI_PRD         (LSPCLK_FREQ/(SCI_FREQ*8))-1



// Prototype statements for functions found within this file.

interrupt void sciaTxFifoIsr(void);

interrupt void sciaRxFifoIsr(void);

interrupt void scibTxFifoIsr(void);

interrupt void scibRxFifoIsr(void);

void scia_fifo_init(void);

void scib_fifo_init(void);

void error(void);



// Global variables

Uint16 sdataA[2];    // Send data for SCI-A

Uint16 rdataA[2];    // Received data for SCI-A

Uint16 rdata_pointA; // Used for checking the received data



void main(void)

{

   Uint16 i;



// Step 1. Initialize System Control:

// PLL, WatchDog, enable Peripheral Clocks

// This example function is found in the DSP2802x_SysCtrl.c file.

   InitSysCtrl();



// Step 2. Initalize GPIO:

// This example function is found in the DSP2802x_Gpio.c file and

// illustrates how to set the GPIO to it's default state.

// InitGpio();

// Setup only the GP I/O only for SCI-A and SCI-B functionality

// This function is found in DSP2802x_Sci.c

   InitSciGpio();



// 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 DSP2802x_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 DSP2802x_DefaultIsr.c.

// This function is found in DSP2802x_PieVect.c.

   InitPieVectTable();



// Interrupts that are used in this example are re-mapped to

// ISR functions found within this file.

   EALLOW;        // This is needed to write to EALLOW protected registers

   PieVectTable.SCIRXINTA = &sciaRxFifoIsr;

   PieVectTable.SCITXINTA = &sciaTxFifoIsr;

   EDIS;   // This is needed to disable write to EALLOW protected registers



// Step 4. Initialize all the Device Peripherals:

// This function is found in DSP2802x_InitPeripherals.c

// InitPeripherals(); // Not required for this example

   scia_fifo_init();  // Init SCI-A



// Step 5. User specific code, enable interrupts:



// Init send data.  After each transmission this data

// will be updated for the next transmission

   for(i = 0; i<2; i++)

   {

      sdataA = i;

   }



   rdata_pointA = sdataA[0];

// Enable interrupts required for this example

   PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   // Enable the PIE block

   PieCtrlRegs.PIEIER9.bit.INTx1=1;     // PIE Group 9, INT1

   PieCtrlRegs.PIEIER9.bit.INTx2=1;     // PIE Group 9, INT2

   IER = 0x100;        // Enable CPU INT

   EINT;



// Step 6. IDLE loop. Just sit and loop forever (optional):

        for(;;);



}



void error(void)

{

    asm("     ESTOP0"); // Test failed!! Stop!

    for (;;);

}



interrupt void sciaTxFifoIsr(void)

{

    Uint16 i;

    for(i=0; i< 2; i++)

    {

           SciaRegs.SCITXBUF=sdataA;     // Send data

        }



    for(i=0; i< 2; i++)                 //Increment send data for next cycle

    {

           sdataA = (sdataA+1) & 0x00FF;

        }



        SciaRegs.SCIFFTX.bit.TXFFINTCLR=1;        // Clear SCI Interrupt flag

        PieCtrlRegs.PIEACK.all|=0x100;      // Issue PIE ACK

}



interrupt void sciaRxFifoIsr(void)

{

    Uint16 i;

        for(i=0;i<2;i++)

        {

           rdataA=SciaRegs.SCIRXBUF.all;         // Read data

        }

        for(i=0;i<2;i++)                     // Check received data

        {

           if(rdataA != ( (rdata_pointA+i) & 0x00FF) ) error();

        }

        rdata_pointA = (rdata_pointA+1) & 0x00FF;



        SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1;   // Clear Overflow flag

        SciaRegs.SCIFFRX.bit.RXFFINTCLR=1;   // Clear Interrupt flag



        PieCtrlRegs.PIEACK.all|=0x100;       // Issue PIE ack

}



void scia_fifo_init()

{

   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.bit.TXINTENA =1;

   SciaRegs.SCICTL2.bit.RXBKINTENA =1;

   SciaRegs.SCIHBAUD = 0x0000;

   SciaRegs.SCILBAUD = SCI_PRD;

   SciaRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back

   SciaRegs.SCIFFTX.all=0xC022;

   SciaRegs.SCIFFRX.all=0x0022;

   SciaRegs.SCIFFCT.all=0x00;



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

   SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1;

   SciaRegs.SCIFFRX.bit.RXFIFORESET=1;



}



//===========================================================================

// No more.

//===========================================================================



 
 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

sci_loopback_int的例程(中断程序) 的相关文章

随机推荐

  • 十分详细的数码管电子时钟(基于51单片机)

    数码管由于内部由多段LED灯构成 xff0c 也被称为多段式LED数码管 从数码管里面包含的LED个数来分 xff0c 可以分为七段式 八段式 十四段式等 七段式数码管 xff1a 八段式数码管 xff08 比七段式右下角多了一个小点 xf
  • 如何用Unity3D实现游戏中的角色换装?

    换装系统是游戏中较为常见的功能 xff0c 我们给它一个专业词avatar xff0c 可以做到装备与人物分离 xff0c 实现自由换装效果 我们可以将头部 身体 手 脚 武器独立建模 贴图 xff0c 利用avatar来动态换装 xff0
  • stm32学习(3)——NVIC中断优先级分组

    相信大多数铁汁在学习stm32的时候都了解过51单片机的基本内容 xff0c 对于51单片机来说 xff0c 中断就那么几个 xff1a 外部中断0定时器 计数器0中断外部中断1定时器 计数器1中断串口中断 它们在51单片机中的优先级也是按
  • STM32F407系统时钟配置不准确导致串口发送数据乱码、定时器定时不准问题

    前言 在用原子的F407探索者开发板时 xff0c 由于是用的野火的工程模板 xff0c 导致了一些串口发送乱码 定时器定时不准的问题 如果你也有类似的问题 xff0c 这个或许可以帮到你 原因 SYSCLK 系统时钟来源有三个方面 xff
  • 巡线PID算法

    相信很多电子专业的同学都做过循迹小车这个小玩意儿 xff0c 而在我们刚刚接触巡线的时候都是用的两个循迹模块 xff08 如下图 xff09 左边的模块检测到黑线了就说明我车子的方向偏右了就需要往左转 xff0c 同理 xff0c 右边检测
  • MSP432(Keil5)——9.ADC驱动

    本次例程驱动了板载的ADC来读取一个模拟的角度传感器 xff0c 大家可以在ADC读取中断里面换成其他的计算 xff0c 具体引脚见程序代码 adc c span class token macro property span class
  • C语言宏函数妙用——1

    span class token macro property span class token directive hash span span class token directive keyword include span spa
  • union和struct的区别

    union只配置一个空间来放置共用体中内存最大的数据 xff0c 而结构体则给其中每个变量内存空间 union常用来压缩数据空间 xff0c 其中两个变量不能同时使用时用union
  • 二极管基础知识

  • Java学习之多线程复制文件

    1 一个线程复制一个文件 import java io FileInputStream import java io FileOutputStream import java io IOException public class MyTh
  • 对于HTTP请求头及响应头的详解

    对于HTTP协议的请求头的详解 标签 xff1a CSDN博文 http协议由两部分组成 xff1a 请求和响应 当你在浏览器中输入一个URL时 xff0c 浏览器将按照你的请求创建并且发送请求 xff0c 该请求包含的所输入的URL以及一
  • 手把手教你实现Unity网络同步

    现如今 xff0c 网络同步的技术在各种游戏里被广泛应用和发展 xff0c 那么 xff0c 如何在Unity中搭建网络模块 xff1f 如何使服务器和客户端之间通信 xff1f 如何做到网络同步 xff1f 本文作者烂笔头 27将从自身经
  • Java个人学习笔记07多线程和网络编程

    Java 多线程编程 Java 给多线程编程提供了内置的支持 一条线程指的是进程中一个单一顺序的控制流 xff0c 一个进程中可以并发多个线程 xff0c 每条线程并行执行不同的任务 创建线程 Java 提供了三种创建线程的方法 xff1a
  • 同步/异步与阻塞/非阻塞的区别(转)(中软国际Fourth day)

    转自于 http www cppblog com converse archive 2009 05 13 82879 html 首先来解释同步和异步的概念 这两个概念与消息的通知机制有关 举个例子 比如我去银行办理业务 可能选择排队等候 也
  • python subprocess模块设置环境变量,加载动态库

    众所周知 xff0c 利用python的subprocess pOpen 可以执行应用程序 不过今天碰到一个问题 xff1a 应用程序需要调用动态库 xff0c 而且动态库和应用程序在同一目录下 不过python的运行目录不是应用程序所在目
  • 智能家居 WiFi&BLE 双模模组 WiFi蓝牙遥控器同时控制W800

    由于文档较长文档只展示部分资料需要了解详细资料 链接 https pan baidu com s 1cpmtH7fC7D RGBh09UbhIQ 提取码 pnu4 一 W800 Wi Fi 蓝牙双模SoC 芯片简介 2 二 W800 CDS
  • Qt Creator使用CMake配置第三方库

    语法 include directories 添加第三方库头文件路径 这里的 include directories 直接向括号里加入第三方库的头文件路径即可 span class token function include direct
  • QtGlobal中常见的一些函数和宏

    lt QtGlobal gt 头文件包含了 Qt 类库的一些全局定义 xff0c 包括基本数据类型 函数和宏 xff0c 一般的 Qt 类的头文件都会包含该文件 xff0c 所以不用显式包含这个头文件也可以使用其中的定义 全局变量定义 为了
  • 传感器之激光雷达简介与使用

    激光雷达是现今机器人尤其是无人车领域及最重要 最关键也是最常见的传感器之一 xff0c 是机器人感知外界的一种重要手段 概念 激光雷达 LiDAR xff0c 英文全称为 Light Detection And Ranging xff0c
  • sci_loopback_int的例程(中断程序)

    例程代码如下 xff1a include 34 DSP28x Project h 34 Device Headerfile and Examples Include File define CPU FREQ 40E6 Default 61