Tool/software: Code Composer Studio
Hi all,
I am using TMS320F28377S C2000 controller for my application.
I want to communicate controller with external devices via UART communication, for this purpose initially i want to get familiar UART communication of this controller.
I tried example code of control suite, In my point of view its not working. I am pasted my code below.
In this loop back mode working fine, but No data come out in SCIA-TX and RX pins(42,43). I am working in Lanuchpad
Regards,
Yuvaraj
//
// Included Files
//
#include "F28x_Project.h"
//
// Defines
//
#define CPU_FREQ 60E6
#define LSPCLK_FREQ CPU_FREQ/4
#define SCI_FREQ 100E3
#define SCI_PRD (LSPCLK_FREQ/(SCI_FREQ*8))-1
//
// Globals
//
Uint16 sdataA[2]; // Send data for SCI-A
Uint16 rdataA[2]; // Received data for SCI-A
Uint16 rdata_pointA; // Used for checking the received data
Uint16 a,j;
//
// Function Prototypes
//
interrupt void sciaTxFifoIsr(void);
interrupt void sciaRxFifoIsr(void);
void scia_fifo_init(void);
void error(void);
//
// Main
//
void main(void)
{
Uint16 i;
InitSysCtrl();
InitGpio();
GPIO_SetupPinMux(13, GPIO_MUX_CPU1, 0);
GPIO_SetupPinOptions(13, GPIO_OUTPUT, GPIO_PUSHPULL);
GPIO_SetupPinMux(12, GPIO_MUX_CPU1, 0);
GPIO_SetupPinOptions(12, GPIO_OUTPUT, GPIO_PUSHPULL);
GPIO_SetupPinMux(42, GPIO_MUX_CPU1, 1);
GPIO_SetupPinOptions(42, GPIO_INPUT, GPIO_ASYNC);
GPIO_SetupPinMux(43, GPIO_MUX_CPU1, 1);
GPIO_SetupPinOptions(43, GPIO_OUTPUT, GPIO_ASYNC);
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.SCIA_RX_INT = &sciaRxFifoIsr;
PieVectTable.SCIA_TX_INT = &sciaTxFifoIsr;
EDIS; // This is needed to disable write to EALLOW protected registers
scia_fifo_init(); // Init SCI-A
for(i = 0; i<2; i++)
{
sdataA[i] = i;
}
rdata_pointA = sdataA[0];
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER9.bit.INTx1 = 1; // PIE Group 9, INT1
PieCtrlRegs.PIEIER9.bit.INTx2 = 1; // PIE Group 9, INT2
IER = 0x100; // Enable CPU INT
EINT;
for(;;)
{
// Turn on LED
GPIO_WritePin(13, 0);
GPIO_WritePin(12, 1);
for(j = 0; j < 10000; j++)
{
for(a = 0; a < 100; a++)
{
}
}
// Turn off LED
GPIO_WritePin(13, 1);
GPIO_WritePin(12, 0);
for(j = 0; j < 10000; j++)
{
for(a = 0; a < 100; a++)
{
}
}
// Delay for a bit.
}
}
// error - Function to halt debugger on error
void error(void)
{
asm(" ESTOP0"); // Test failed!! Stop!
for (;;);
}
// sciaTxFifoIsr - SCIA Transmit FIFO ISR
interrupt void sciaTxFifoIsr(void)
{
Uint16 i;
for(i=0; i< 2; i++)
{
SciaRegs.SCITXBUF.all=sdataA[i]; // Send data
}
for(i=0; i< 2; i++) // Increment send data for next cycle
{
sdataA[i] = (sdataA[i]+1) & 0x00FF;
}
SciaRegs.SCIFFTX.bit.TXFFINTCLR=1; // Clear SCI Interrupt flag
PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ACK
}
// sciaRxFifoIsr - SCIA Receive FIFO ISR
interrupt void sciaRxFifoIsr(void)
{
Uint16 i;
for(i=0;i<2;i++)
{
rdataA[i]=SciaRegs.SCIRXBUF.all; // Read data
}
for(i=0;i<2;i++) // Check received data
{
if(rdataA[i] != ( (rdata_pointA+i) & 0x00FF) )
{
// error();
}
}
rdata_pointA = (rdata_pointA+1) & 0x00FF;
SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1; // Clear Overflow flag
SciaRegs.SCIFFRX.bit.RXFFINTCLR=1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ack
}
// scia_fifo_init - Configure SCIA FIFO
void scia_fifo_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.bit.TXINTENA = 1;
SciaRegs.SCICTL2.bit.RXBKINTENA = 1;
SciaRegs.SCIHBAUD.all = 0x0000;
SciaRegs.SCILBAUD.all = SCI_PRD;
SciaRegs.SCICCR.bit.LOOPBKENA = 0; // Enable loop back
SciaRegs.SCIFFTX.all = 0xC022;
SciaRegs.SCIFFRX.all = 0x0022;
SciaRegs.SCIFFCT.all = 0x00;
SciaRegs.SCICTL1.all = 0x0023; // Relinquish SCI from Reset
SciaRegs.SCIFFTX.bit.TXFIFORESET = 1;
SciaRegs.SCIFFRX.bit.RXFIFORESET = 1;
}