1. IO Configuration
Taking SCIA as an example: GPIO35--SCITXDA GPIOA36--SCIRXDA is used
Using registers:
GPBPUD: Set pull-up GPIO32-GPIO63 corresponding bit 0 enables pull-up
GPBQSEL1:
GPBMUX1: IO mode selection
The code is as follows:
GpioCtrlRegs.GPBPUD.bit.GPIO36 = 0; // Enable pull-up for GPIO28 (SCIRXDA) //Enable internal pull
-up GpioCtrlRegs.GPBPUD.bit.GPIO35 = 0; // Enable pull-up for GPIO29 (SCITXDA) //Enable internal pull-up
GpioCtrlRegs.GPBQSEL1.bit.GPIO36 = 3; // Asynch input GPIO28 (SCIRXDA) //Set to asynchronous input mode
GpioCtrlRegs.GPBMUX1.bit.GPIO36 = 1; // Configure GPIO28 for SCIRXDA operation //Configure as peripheral mode
GpioCtrlRegs.GPBMUX1.bit.GPIO35 = 1; // Configure GPIO29 for SCITXDA operation //Configure as peripheral mode
Set FIFO register:
Copy code
void scia_fifo_init()
{
SciaRegs.SCIFFTX.all=0xE040;//Enable FIFO; Clear the transmit interrupt flag; Disable FIFO transmit interrupt;
//The transmit interrupt level is defined as 0;
SciaRegs.SCIFFRX.all=0x204f;//Clear FIFO overflow flag; Clear overflow receive interrupt flag; Disable
//FF receive interrupt; The receive interrupt level is 16;
SciaRegs.SCIFFCT.all=0x0;//SCITXBUF to shift register transfer without delay
}
Copy code
Set SCI related registers: Register description see http://www.ti.com/lit/ug/sprufz5a/sprufz5a.pdf
Copy code
void scia_echoback_init()
{
// 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;//Enable receive interrupt
SciaRegs.SCICTL2.bit.RXBKINTENA =1;//Enable transmit interrupt
# if (CPU_FRQ_150MHZ)
SciaRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 37.5MHz.
SciaRegs.SCIHBAUD =0x00E7;
#endif
#if (CPU_FRQ_100MHZ)
SciaRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 20MHz.
SciaRegs.SCILBAUD =0x0044;
#endif
SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}
Copy code
Baud rate calculation method:
A byte occurs:
void scia_xmit(int a)
{
while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
SciaRegs.SCITXBUF=a;
}
Use SICA to send and serial port interrupt to receive:
The configuration parameters are as follows:
Copy code
static void Init_SCI_A(Uint32 Baud)
{
//Init IO
Uint16 BRR=0;
EALLOW;
GpioCtrlRegs.GPBPUD.bit.GPIO36 = 0; // Enable pull-up for GPIO28 (SCIRXDA)
GpioCtrlRegs.GPBPUD.bit.GPIO35 = 0; // Enable pull-up for GPIO29 (SCITXDA)
GpioCtrlRegs.GPBQSEL1.bit.GPIO36 = 3; // Asynch input GPIO28 (SCIRXDA)
GpioCtrlRegs.GPBMUX1.bit.GPIO36 = 1; // Configure GPIO28 for SCIRXDA operation
GpioCtrlRegs. GPBMUX1.bit.GPIO35 = 1; // Configure GPIO29 for SCITXDA operation
EDIS;
//set RX interrput function
EALLOW;
PieVectTable.SCIRXINTA = &SciaRxIsr;
EDIS;
//set SCIA register
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;//close TX interrput
SciaRegs.SCICTL2.bit.RXBKINTENA =1;
//set Baud BRR= LSPCLK/( Baud*8)-1
BRR = SCI_LSPCLK/(Baud*8)-1;
SciaRegs.SCIHBAUD = (BRR>>8); // 9600 baud @LSPCLK = 37.5MHz.
SciaRegs.SCILBAUD = (BRR&0x00ff);
// SciaRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 37.5MHz.
// SciaRegs.SCILBAUD =0x00E7;
SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
EALLOW;
//set SCI interrput Group
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER9.bit.INTx1=1; // PIE Group 9, int1 enable SCIA_RX
//PieCtrlRegs.PIEIER9.bit.INTx2=1; // PIE Group 9, INT2 enable SCIA_TX
EDIS;
}
Copy code
Send data code:
Copy code
//send one byte data
static void scia_xmit(int a)
{
while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
SciaRegs.SCITXBUF=a;
}
//send string
void scia_msg(char * msg)
{
int i;
i = 0;
while(msg != '\0')
{
scia_xmit(msg);
i++;
}
}
|