📄 dsp280x_sci.c
字号:
// TI File $Revision: /main/3 $
// Checkin $Date: August 2, 2006 13:51:10 $
//###########################################################################
//
// FILE: DSP280x_Sci.c
//
// TITLE: DSP280x SCI Initialization & Support Functions.
//
//###########################################################################
// $TI Release: DSP280x, DSP2801x Header Files V1.41 $
// $Release Date: August 7th, 2006 $
//###########################################################################
#include "DSP280x_Device.h" // DSP280x Headerfile Include File
#include "DSP280x_Examples.h" // DSP280x Examples Include File
//---------------------------------------------------------------------------
extern Uint16 Uart_err_flag,Uart_err_count,UART_COUNT;
extern Uint16 S90_DSP_V;//S90电马达速度
extern Uint16 run_start_flag,run_start_count;
extern Uint16 rqd_temp;//run_start_flag
// Global variables
extern Uint16 sdataA;
extern Uint16 rdataA[4]; // Received data for SCI-A
extern Uint16 txdaddr,TXD_FLAG;
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);
//--------------------------------------------------------------------------
#define CPU_FREQ 150E6
#define SCI_FREQ 100E3
#define SCI_PRD CPU_FREQ/(SCI_FREQ*8)
Uint16 temp11,temp22;
//---------------------------------------------------------------------------
// InitSci:
//---------------------------------------------------------------------------
// This function initializes the SCI(s) to a known state.
//
void InitSci(void)
{
// Initialize SCI-A:
//tbd...
scia_fifo_init();
InitSciaGpio();
// ISR functions found within this file.
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.SCIRXINTA = &sciaRxFifoIsr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Enable interrupts required for this example
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER9.bit.INTx1=1; // PIE Group 9, INT1
IER |= 0x100;
// Initialize SCI-B:
//tbd...
}
//---------------------------------------------------------------------------
// Example: InitSciGpio:
//---------------------------------------------------------------------------
// This function initializes GPIO pins to function as SCI pins
//
// Each GPIO pin can be configured as a GPIO pin or up to 3 different
// peripheral functional pins. By default all pins come up as GPIO
// inputs after reset.
//
// Caution:
// Only one GPIO pin should be enabled for SCITXDA/B operation.
// Only one GPIO pin shoudl be enabled for SCIRXDA/B operation.
// Comment out other unwanted lines.
void InitSciaGpio()
{
EALLOW;
/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled disabled by the user.
// This will enable the pullups for the specified pins.
GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0; // Enable pull-up for GPIO28 (SCIRXDA)
GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0; // Enable pull-up for GPIO29 (SCITXDA)
/* Set qualification for selected pins to asynch only */
// Inputs are synchronized to SYSCLKOUT by default.
// This will select asynch (no qualification) for the selected pins.
GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3; // Asynch input GPIO28 (SCIRXDA)
/* Configure SCI-A pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be SCI functional pins.
GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 1; // Configure GPIO28 for SCIRXDA operation
GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 1; // Configure GPIO29 for SCITXDA operation
EDIS;
}
//---------------------------------------------------------------------------
interrupt void sciaRxFifoIsr(void)
{
//Uint16 temp1,temp2;
rdataA[txdaddr]=SciaRegs.SCIRXBUF.all;
if(txdaddr<3)
{
txdaddr++;
}
else
{
temp11=CRC16(rdataA, 2);
temp22=(rdataA[2]<<8)+(rdataA[3]&0xff);
if(temp11!=temp22)
{
Uart_err_flag=1;
Uart_err_count++;
}
else
{//led
UART_COUNT++;
if(UART_COUNT>3)
UART_COUNT=0;
Uart_err_flag=0;
}
}
//---------------
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 =0;
SciaRegs.SCICTL2.bit.RXBKINTENA =1;
SciaRegs.SCIHBAUD = 0x0001;
SciaRegs.SCILBAUD = 0x88;
SciaRegs.SCICCR.bit.LOOPBKENA =0; // Enable loop back
//SciaRegs.SCIFFTX.all=0xC028;
//SciaRegs.SCIFFRX.all=0x0028;
//SciaRegs.SCIFFCT.all=0x00;
SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
//SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1;
//SciaRegs.SCIFFRX.bit.RXFIFORESET=1;
//-----地址模式---
//SciaRegs.SCICTL1.bit.TXWAKE=1;
//SciaRegs.SCICTL1.bit.SLEEP=1;
//SciaRegs.SCICCR.bit.ADDRIDLE_MODE=1;
}
//===========================================================================
// End of file.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -