This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28069 SCI-A receive issue

I am trying to setup the SCI-A interface so that when from the computer I can send "LED1" to the microprocessor and the receive interrupt will occur and then send a message back to the computer.

I can get messages to send to the computer no problem but my receive is not working right, the first time it receives "LE" and the from then on it is random letter from the sequence I'm trying to send (i.e. "LLLLLLLLLLL", "LDDDDDDDD")

Also every time I start the program the transmit is function is executed how can I not have that happen.

Here is my code any help would be much appreciated!

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
#include "string.h"

#define CPU_FREQ    90E6
#define LSPCLK_FREQ CPU_FREQ/4
#define SCI_FREQ    100E3
#define SCI_PRD     (LSPCLK_FREQ/(SCI_FREQ*8))-1

// Prototype statements for functions found within this file.
__interrupt void sciaTxFifoIsr(void);
__interrupt void sciaRxFifoIsr(void);
void scia_fifo_init(void);
void error(void);

// Global variables
// Global Variables
char message[]={" Instruments! \n\r"};    // Send data for SCI-A
//Uint16 rdataA[2];    // Received data for SCI-A
//Uint16 rdata_pointA; // Used for checking the received data

void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2806x_SysCtrl.c file.
   InitSysCtrl();

// Step 2. Initalize GPIO:
// This example function is found in the F2806x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();
// Setup only the GP I/O only for SCI-A and SCI-B functionality
// This function is found in F2806x_Sci.c
   InitSciGpio();

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
   DINT;

// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F2806x_PieCtrl.c file.
   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in F2806x_DefaultIsr.c.
// This function is found in F2806x_PieVect.c.
   InitPieVectTable();

// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
   EALLOW;  // This is needed to write to EALLOW protected registers
   PieVectTable.SCIRXINTA = &sciaRxFifoIsr;
   PieVectTable.SCITXINTA = &sciaTxFifoIsr;
   EDIS;   // This is needed to disable write to EALLOW protected registers

// Step 4. Initialize all the Device Peripherals:
// This function is found in F2806x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
   scia_fifo_init();  // Init SCI-A


// Enable interrupts required for this example
   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;

// Step 6. IDLE loop. Just sit and loop forever (optional):
    for(;;);

}

void error(void)
{
   __asm("     ESTOP0"); // Test failed!! Stop!
    for (;;);
}

__interrupt void sciaTxFifoIsr(void)
{
    Uint16 i;
    for(i=0; i< 16; i++)
    {
    	while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
    	SciaRegs.SCITXBUF=message[i];     // Send data
    }

    PieCtrlRegs.PIEACK.all|=0x100;      // Issue PIE ACK
}

__interrupt void sciaRxFifoIsr(void)
{
	int i;
	char buffer[16];
	for (i=0;i<16;i++) buffer[i]= SciaRegs.SCIRXBUF.all;

	if (strncmp(buffer, "LED1", 4) == 0)
	{
		SciaRegs.SCIFFTX.bit.TXFIFOXRESET =1;  // enable TXFIFO
		SciaRegs.SCIFFTX.bit.TXFFINTCLR = 1 ;  // force TX-ISR
	}

    SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1;   // Clear Overflow flag
    SciaRegs.SCIFFRX.bit.RXFFINTCLR=1;   // Clear Interrupt flag

    PieCtrlRegs.PIEACK.all|=0x100;       // Issue PIE ack
}

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 = 0x0001; 		//9600 Baud (90MHz clock)
   SciaRegs.SCILBAUD = 0x0024;
   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.TXFIFOXRESET=1;
   SciaRegs.SCIFFRX.bit.RXFIFORESET=1;

}

//===========================================================================
// No more.
//===========================================================================