DSP

【DSP】TMS320F28035 SCI例程(自发自收+查询)

2019-07-13 10:35发布

#include "DSP28x_Project.h" // Device Headerfile and Examples Include File void scia_loopback_init(void); void scia_fifo_init(void); void error(); Uint16 LoopCount; Uint16 ErrorCount; Uint16 SendChar; Uint16 ReceivedChar; void main(void) { InitSysCtrl(); InitSciGpio();//初始化SCI引脚 DINT; IER = 0x0000; IFR = 0x0000; InitPieVectTable(); PieCtrlRegs.PIECTRL.bit.ENPIE = 1;//使能PIE PieCtrlRegs.PIEACK.all = 0xFFFF;//写1清零,允许所有PIE都能被响应 EINT;//开启总中断 LoopCount = 0; ErrorCount = 0; scia_fifo_init(); // Initialize the SCI FIFO scia_loopback_init(); // Initalize SCI for digital loop back SendChar = 0; for(;;) { DELAY_US(1000000); //将要发送的数据存入SCITXBUF SciaRegs.SCITXBUF = SendChar; //等待发送完成 while(SciaRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for RRDY/RXFFST =1 for 1 data available in FIFO //存储接收数据 ReceivedChar = SciaRegs.SCIRXBUF.all; //自检 if(ReceivedChar != SendChar) error(); //发送的数据 SendChar++; // Limit the character to 8-bits SendChar &= 0x00FF; LoopCount++; } } // Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here: void error() { ErrorCount++; } // Test 1,SCIA DLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity void scia_loopback_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.all =0x0003; SciaRegs.SCICTL2.bit.TXINTENA =1; SciaRegs.SCICTL2.bit.RXBKINTENA =1; SciaRegs.SCIHBAUD =0x0000; SciaRegs.SCILBAUD =0x000F; SciaRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset } // Initalize the SCI FIFO void scia_fifo_init() { SciaRegs.SCIFFTX.all=0xE040; SciaRegs.SCIFFRX.all=0x2044; SciaRegs.SCIFFCT.all=0x0; }