DSP_28335串口FIFO中断收发实验

(67条消息) DSP_28335_SCI_FIFO收发实验_小p孩不想长大的博客-CSDN博客

1、主函数main.c

/*
 * main.c
 *
 *  Created on: 2018-3-21
 *      Author: Administrator
 */


#include "DSP2833x_Device.h"     // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h"   // DSP2833x Examples Include File
#include "string.h"
#include "leds.h"
#include "time.h"
#include "uart.h"
#include "math.h"

char *receivedata;
char a[20];
void main()
{
	char *msg;
//使能 CPU 级中断,并初始化 PIE 控制器寄存器和 PIE中断向量表
	InitSysCtrl();
	InitPieCtrl();
	IER = 0x0000;
	IFR = 0x0000;
	InitPieVectTable();

	LED_Init();
	TIM0_Init(150,200000);//200ms
	UARTa_Init(115200);

	msg = "Hello World!\r\n";
	UARTa_SendString(msg);
	msg = "You will enter a character, and the DSP will echo it back!\r\n";
	UARTa_SendString(msg);

	while(1)
	{
		receivedata=UART_ReadData();
		strcpy(a,receivedata);

	}
}


2、串口uart.c

/*
 * uart.c
 *
 *  Created on: 2018-1-31
 *      Author: Administrator
 */

#include "uart.h"
#include "string.h"
char m[12];
char *msg;//定义指针
void UARTa_Init(Uint32 baud)
{
	unsigned char scihbaud=0;
	unsigned char scilbaud=0;
	Uint16 scibaud=0;

	scibaud=37500000/(8*baud)-1;
	scihbaud=scibaud>>8;
	scilbaud=scibaud&0xff;


	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.SCIAENCLK = 1;   // SCI-A
	EDIS;

	InitSciaGpio();

	//Initalize the SCI FIFO
	 //SCI发送FIFO寄存器SCIFFTX
	 //SciaRegs.SCIFFTX.all=0xE040;//1110 0000 0100 0000

	  SciaRegs.SCIFFTX.all=0xC04F;//1100 0000 0100 1111
	   //SCI发送FIFO寄存器SCIFFTX
	  // SciaRegs.SCIFFTX.bit.SCIRST=1;//SCI复位标志位,1.SCI接收和发送FIFO功能继续工作//15
	   //SciaRegs.SCIFFTX.bit.SCIFFENA=1;//使能FIFO//14
	  // SciaRegs.SCIFFTX.bit.TXFIFOXRESET=0;//SCI发送FIFO复位,0,复位发送FIFO指针//  13
	   //SciaRegs.SCIFFTX.bit.TXFFINTCLR=1;//发送FIFO中断清除标志位,1,清除TXFFINT位//6
	   //SciaRegs.SCIFFTX.bit.TXFFIENA=0;//不使能发送FIFO中断    //5
	   //SciaRegs.SCIFFTX.bit.TXFFIL=0x0F;//12级FIFO使能  1100 0x0C//0-改为16级使能1111 0x0F



	   //SCI接收FIFO寄存器SCIFFRX
	   //SciaRegs.SCIFFRX.all=0x204f;//0010 0000 0100 1111源程序
	   SciaRegs.SCIFFRX.all=0x406F;//0100 0000 0110 1111
	   //SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1;//SCI接收FIFO溢出清除标志位,1,清除RXFFOVF//14
	  // SciaRegs.SCIFFRX.bit.RXFIFORESET=0;//SCI接收FIFO复位,0,复位接收FIFO指针//13
	  // SciaRegs.SCIFFRX.bit.RXFFINTCLR=1;//接收FIFO中断清除标志位//6
	   //SciaRegs.SCIFFRX.bit.RXFFIENA=1;//接收FIFO中断使能位,//5
	   //SciaRegs.SCIFFRX.bit.RXFFIL=0x0F;//12级FIFO使能//0-4改为16级FIFO 1111

	   //SCI FIFO控制寄存器SCIFFCT
	   SciaRegs.SCIFFCT.all=0x00;
	   // SCI控制寄存器1
	   SciaRegs.SCICTL1.bit.SWRESET=1;//Relinquish SCI from Reset//

	   SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1;//重新使能发送FIFO
	   SciaRegs.SCIFFRX.bit.RXFIFORESET=1;//重新使能接受FIFO


	// Note: Clocks were turned on to the SCIA peripheral
	// in the InitSysCtrl() function
	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    =scihbaud;  // 9600 baud @LSPCLK = 37.5MHz.
	SciaRegs.SCILBAUD    =scilbaud;
//	SciaRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back
	SciaRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset

//定义串口中断名
	   EALLOW;
	   PieVectTable.SCIRXINTA = &sciaRxFifo;
	   PieVectTable.SCITXINTA = &sciaTxFifo;
	   EDIS;
	/
	// Enable interrupts required for this example
	   PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   // Enable the PIE block
	   //开启第9组串口中断定时器
	   PieCtrlRegs.PIEIER9.bit.INTx1=1;     // PIE Group 9, int1
	   PieCtrlRegs.PIEIER9.bit.INTx2=1;     // PIE Group 9, INT2
	   PieCtrlRegs.PIEIER9.bit.INTx3=1;     // PIE Group 9, INT3
	   PieCtrlRegs.PIEIER9.bit.INTx4=1;     // PIE Group 9, INT4
	   IER = M_INT9;        // Enable CPU INT
	   EINT;
	   ERTM;
}


// Transmit a character from the SCI'
void UARTa_SendByte(char a)
{
	//while (SciaRegs.SCIFFTX.bit.TXFFST != 0);
	while (SciaRegs.SCICTL2.bit.TXRDY == 0);
	SciaRegs.SCITXBUF=a;
}

void UARTa_SendString(char * msg)
{
	/*
	int i=0;

	while(msg[i] != '\0')
	{
		UARTa_SendByte(msg[i]);
		i++;
	}
	*/
    Uint16 len;
    Uint16 i;
    len=(strlen(msg)-1);
    for(i=0;i

3、UART.H

/*
 * uart.h
 *
 *  Created on: 2018-1-31
 *      Author: Administrator
 */

#ifndef UART_H_
#define UART_H_

#include "DSP2833x_Device.h"     // DSP2833x 头文件
#include "DSP2833x_Examples.h"   // DSP2833x 例子相关头文件


void UARTa_Init(Uint32 baud);
void UARTa_SendByte(char a);
void UARTa_SendString(char * msg);
char* UART_ReadData(void);
interrupt void sciaTxFifo(void);
interrupt void sciaRxFifo(void);
#endif /* UART_H_ */

4、实现的功能

实现串口的每发送14个字符进行一次中断

 

DSP_28335串口FIFO中断收发实验_第1张图片

你可能感兴趣的:(dsp,单片机,嵌入式硬件,dsp开发)