TMS320F2808에는 2개의 SCI모듈이 있고 [DSP280x-M EVM] 보드에 표준 핀맵으로 연결되어 있다.
USB2UART 통신 모듈
USB로 전원 공급 및 UART통신이 가능하다.
초기화 함수
// Serial Prot0 Utility Fuction Routine
void U0_Init(unsigned char baud)
{
//SCI 포트 초기화
InitSciaGpio();
//SCI FIFO설정
SciaRegs.SCIFFTX.all=0xE040;
SciaRegs.SCIFFRX.all=0x204f;
SciaRegs.SCIFFCT.all=0x0;
//보레이트 설정
U0_SetBaud(baud);
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.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}
void U0_Init(unsigned char baud)
{
//SCI 포트 초기화
InitSciaGpio();
//SCI FIFO설정
SciaRegs.SCIFFTX.all=0xE040;
SciaRegs.SCIFFRX.all=0x204f;
SciaRegs.SCIFFCT.all=0x0;
//보레이트 설정
U0_SetBaud(baud);
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.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}
SCI 송수신 함수
#define WaitForSend() while(SciaRegs.SCIFFTX.bit.TXFFST != 0)
#define WaitForReceive() while(SciaRegs.SCIFFRX.bit.RXFFST !=1)
#define WaitForSend1() while(!(ScibRegs.SCICTL2.bit.TXEMPTY))
#define WaitForReceive1() while(!(ScibRegs.SCIRXST.bit.RXRDY))
#define WaitForReceive() while(SciaRegs.SCIFFRX.bit.RXFFST !=1)
#define WaitForSend1() while(!(ScibRegs.SCICTL2.bit.TXEMPTY))
#define WaitForReceive1() while(!(ScibRegs.SCIRXST.bit.RXRDY))
#define TxData(Data) (SciaRegs.SCITXBUF = (Data))
#define RxData() (SciaRegs.SCIRXBUF.all)
#define Tx1Data(Data) (ScibRegs.SCITXBUF = (Data))
#define Rx1Data() (ScibRegs.SCIRXBUF.all)
unsigned char U0_GetByte(void)
{
WaitForReceive();
return RxData();
}
void U0_PutByte(unsigned char Data)
{
WaitForSend();
TxData(Data);
}
#define RxData() (SciaRegs.SCIRXBUF.all)
#define Tx1Data(Data) (ScibRegs.SCITXBUF = (Data))
#define Rx1Data() (ScibRegs.SCIRXBUF.all)
unsigned char U0_GetByte(void)
{
WaitForReceive();
return RxData();
}
void U0_PutByte(unsigned char Data)
{
WaitForSend();
TxData(Data);
}
반응형