//#############################################################################
//
// File: f2802x_examples/scia_loopback_interrupts/Example_F2802xSci_FFDLB_int.c
//
// Title: F2802x Device SCI Digital Loop Back program.
//
// Group: C2000
// Target Device: TMS320F2802x
//
//! \addtogroup example_list
//! <h1>SCI Digital Loop Back with Interrupts</h1>
//!
//! This program is a SCI example that uses the internal loopback of
//! the peripheral. Both interrupts and the SCI FIFOs are used.
//!
//! A stream of data is sent and then compared to the recieved stream.
//!
//! The SCI-A sent data looks like this: \n
//! 00 01 \n
//! 01 02 \n
//! 02 03 \n
//! …. \n
//! FE FF \n
//! FF 00 \n
//! etc..
//!
//! The pattern is repeated forever.
//!
//! Watch Variables:
//! – sdataA – Data being sent
//! – rdataA – Data received
//! – rdata_pointA – Keep track of where we are in the datastream.
//! This is used to check the incoming data
//
//#############################################################################
// $TI Release: F2802x Support Library v222 $
// $Release Date: Thu Jan 15 13:56:57 CST 2015 $
// $Copyright: Copyright (C) 2008-2015 Texas Instruments Incorporated –
// http://www.ti.com/ ALL RIGHTS RESERVED $
//#############################################################################
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
#include <stdio.h>
#include <file.h>
#include "f2802x_common/include/adc.h"
#include "f2802x_common/include/clk.h"
#include "f2802x_common/include/flash.h"
#include "f2802x_common/include/gpio.h"
#include "f2802x_common/include/pie.h"
#include "f2802x_common/include/pll.h"
#include "f2802x_common/include/sci.h"
#include "f2802x_common/include/wdog.h"
#define CPU_FREQ 60E6 // Default = 40 MHz. Change to 50E6 for 50 MHz devices
#define LSPCLK_FREQ CPU_FREQ/4
#define SCI_FREQ 9.6E3
#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_init(void);
void scia_fifo_init(void);
void error(void);
// Global variables
uint16_t sdataA[16]; // Send data for SCI-A
uint16_t rdataA[16]; // Received data for SCI-A
uint16_t rdata_pointA; // Used for checking the received data
ADC_Handle myAdc;
CLK_Handle myClk;
FLASH_Handle myFlash;
GPIO_Handle myGpio;
PIE_Handle myPie;
SCI_Handle mySci;
void main(void)
{
uint16_t i;
CPU_Handle myCpu;
PLL_Handle myPll;
WDOG_Handle myWDog;
// Initialize all the handles needed for this application
myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));
myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));
myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj));
myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));
myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj));
myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));
mySci = SCI_init((void *)SCIA_BASE_ADDR, sizeof(SCI_Obj));
myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));
// Perform basic system initialization
WDOG_disable(myWDog);
CLK_enableAdcClock(myClk);
(*Device_cal)();
//Select the internal oscillator 1 as the clock source
CLK_setOscSrc(myClk, CLK_OscSrc_Internal);
// Setup the PLL for x10 /2 which will yield 50Mhz = 10Mhz * 10 / 2
PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);
// Disable the PIE and all interrupts
PIE_disable(myPie);
PIE_disableAllInts(myPie);
CPU_disableGlobalInts(myCpu);
CPU_clearIntFlags(myCpu);
// If running from flash copy RAM only functions to RAM
#ifdef _FLASH
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif
// Initialize GPIO
GPIO_setPullUp(myGpio, GPIO_Number_28, GPIO_PullUp_Enable);
GPIO_setPullUp(myGpio, GPIO_Number_29, GPIO_PullUp_Disable);
GPIO_setQualification(myGpio, GPIO_Number_28, GPIO_Qual_ASync);
GPIO_setMode(myGpio, GPIO_Number_28, GPIO_28_Mode_SCIRXDA);
GPIO_setMode(myGpio, GPIO_Number_29, GPIO_29_Mode_SCITXDA);
// Setup a debug vector table and enable the PIE
PIE_setDebugIntVectorTable(myPie);
PIE_enable(myPie);
// 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;
((PIE_Obj *)myPie)->SCIRXINTA = &sciaRxFifoIsr;
// PieVectTable.SCITXINTA = &sciaTxFifoIsr;
((PIE_Obj *)myPie)->SCITXINTA = &sciaTxFifoIsr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Register interrupt handlers in the PIE vector table
PIE_registerPieIntHandler(myPie, PIE_GroupNumber_9, PIE_SubGroupNumber_1, (intVec_t)&sciaRxFifoIsr);
PIE_registerPieIntHandler(myPie, PIE_GroupNumber_9, PIE_SubGroupNumber_2, (intVec_t)&sciaTxFifoIsr);
scia_init(); // Init SCI-A
scia_fifo_init(); // Init SCI-A Fifos
// Init send data. After each transmission this data
// will be updated for the next transmission
for(i = 0; i<2; i++)
{
sdataA[i] = i;
}
rdata_pointA = sdataA[0];
// Enable interrupts required for this example
PIE_enableInt(myPie, PIE_GroupNumber_9, PIE_InterruptSource_SCIARX);
PIE_enableInt(myPie, PIE_GroupNumber_9, PIE_InterruptSource_SCIATX);
CPU_enableInt(myCpu, CPU_IntNumber_9);
CPU_enableGlobalInts(myCpu);
for(;;){
}
}
void error(void)
{
__asm(" ESTOP0"); // Test failed!! Stop!
for (;;){
}
}
__interrupt void sciaTxFifoIsr(void)
{
uint16_t i;
for(i=0; i< 16; i++) {
// Send data
SCI_putDataBlocking(mySci, i+65);
}
// for(i=0; i< 2; i++) {
// //Increment send data for next cycle
// sdataA[i] = (sdataA[i]+1) & 0x00FF;
// }
// Clear SCI Interrupt flag
SCI_clearTxFifoInt(mySci);
// Issue PIE ACK
PIE_clearInt(myPie, PIE_GroupNumber_9);
return;
}
__interrupt void sciaRxFifoIsr(void)
{
uint16_t i;
if(SCI_getRxFifoStatus(mySci) != SCI_FifoLevel_Empty){
for(i=0;i<16;i++) {
// Read data
rdataA[i] = SCI_getData(mySci);
}
for(i=0;i<2;i++) {
// Check received data
}
rdata_pointA = (rdata_pointA+1) & 0x00FF;
}
// Clear Overflow flag
SCI_clearRxFifoOvf(mySci);
// Clear Interrupt flag
SCI_clearRxFifoInt(mySci);
// Issue PIE ack
PIE_clearInt(myPie, PIE_GroupNumber_9);
return;
}
void scia_init()
{
CLK_enableSciaClock(myClk);
// 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
SCI_disableParity(mySci);
SCI_setNumStopBits(mySci, SCI_NumStopBits_One);
SCI_setCharLength(mySci, SCI_CharLength_8_Bits);
// enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SCI_enableTx(mySci);
SCI_enableRx(mySci);
SCI_enableTxInt(mySci);
SCI_enableRxInt(mySci);
SCI_disableLoopBack(mySci); //禁止回传
// SCI BRR = LSPCLK/(SCI BAUDx8) – 1
// SCI_setBaudRate(mySci, (SCI_BaudRate_e)SCI_PRD);
//通过宏定义设置波特率
SCI_setBaudRate(mySci, (SCI_BaudRate_e)SCI_PRD);
SCI_enable(mySci);
return;
}
void scia_fifo_init()
{
SCI_enableFifoEnh(mySci);
SCI_resetTxFifo(mySci);
SCI_clearTxFifoInt(mySci);
SCI_resetChannels(mySci);
SCI_setTxFifoIntLevel(mySci, SCI_FifoLevel_4_Words);
SCI_enableTxFifoInt(mySci);
SCI_resetRxFifo(mySci);
SCI_clearRxFifoInt(mySci);
SCI_setRxFifoIntLevel(mySci, SCI_FifoLevel_2_Words);
SCI_enableRxFifoInt(mySci);
return;
}
//===========================================================================
// No more.
//===========================================================================
将程序稍微改了下,一上电就不停地进入发送中断发送数据,主函数里并没有发送数据它怎么能够反复进入发送中断呢?即使发送中断里什么也不发送也会不停地进入发送中断。
还有controlSUITE提供的f2802x-DRL-UG.pdf文件对Firmware里的函数的讲解太简介了,有没有详细一点的资料?