DSP串口通信协议

转载附上源地址:https://blog.csdn.net/weixin_42226781/article/details/103701986

DSP串口通信协议

功能:实现串口调试助手发送区发送8个字节,接受区收到8个字节;当发送区小于8个字节,接收区等待收到8个后才显示8个字节;当发送区大于8个字节,则接收前8个字节。

#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#include void scic_init(void);
int ScicTx_Ready(void);
int ScicRx_Ready(void);
unsigned int j;
unsigned int Sci_VarRx[100];
unsigned int Send_Flag;
unsigned int N = 8; 
void main()
{	
InitSysCtrl();	
InitScicGpio();	
InitSci();	
DINT;	
IER = 0x0000;	
IFR = 0x0000;	
InitPieCtrl();	
InitPieVectTable();	
scic_init(); 	
for(j = 0;j < 100;j++)	
{		
Sci_VarRx[j] = 0;	
}	
j = 0;	
Send_Flag = 0; 	
for(;;)	
{		
if((ScicTx_Ready()==1)&&(Send_Flag == 1))				
{					
while(j<N)					
{						
if(ScicTx_Ready()==1)						
{							
ScicRegs.SCITXBUF = Sci_VarRx[j];							j++;						
}					
}					
Send_Flag = 0;					
j = 0;				
}		
if(ScicRx_Ready()==1)				
{					
Sci_VarRx[j] = ScicRegs.SCIRXBUF.all;
j++;					
if(j == N)					
{						
j = 0;						
Send_Flag =1;					
}				
}	
}
} 
void scic_init()
{	 
ScicRegs.SCICCR.all =0x0007;   // 1 stop bit, No loopback	   //配置通讯协议                             // No parity,8 char bits,	                                   // async mode, idle-line protocol	    
ScicRegs.SCICTL1.all =0x0003;  // enable TX, RX, internal SCICLK,	                                   // Disable RX ERR, SLEEP, TXWAKE	    
ScicRegs.SCICTL2.all =0x0003;	    
ScicRegs.SCICTL1.bit.TXENA = 1;	    
ScicRegs.SCICTL1.bit.RXENA = 1;	    
//SciaRegs.SCICTL2.bit.TXINTENA =1;	    
//SciaRegs.SCICTL2.bit.RXBKINTENA =1; 
#if (CPU_FRQ_150MHZ)	      
ScicRegs.SCIHBAUD    =0x0001;  // 9600 baud @LSPCLK = 37.5MHz.	      
ScicRegs.SCILBAUD    =0x00E7;	
#endif	
#if (CPU_FRQ_100MHZ)      
ScicRegs.SCIHBAUD    =0x0001;  // 9600 baud @LSPCLK = 20MHz.      
ScicRegs.SCILBAUD    =0x0044;	
#endif	    
ScicRegs.SCICCR.bit.LOOPBKENA = 0; // disable loop back	    
ScicRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset} 
int ScicTx_Ready(void)
{	
unsigned int i;	
if(ScicRegs.SCICTL2.bit.TXRDY == 1)	
{		
i = 1;	
}	
else	
{	
i = 0;	
}	
return(i);
} 
int ScicRx_Ready(void)
{	
unsigned int i;	
if(ScicRegs.SCIRXST.bit.RXRDY == 1)	
{		
i = 1;	
}	
else	
{		
i = 0;	
}	
return(i);
}

你可能感兴趣的:(DSP串口通信协议)