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.

CCS/TMS320F28035-EP: UART Communication: Polling or Interrupt

Part Number: TMS320F28035-EP
Other Parts Discussed in Thread: TMS320F28035

Tool/software: Code Composer Studio

I am using TMS320F28035 microcontroller for ADC, GPIO and UART Application using C28.

In this application, i need to receive 20 Bytes of Data as command packet and send the status of ADCs and GPIOs on UART.

I tried using polling mode, which receives only last 4 bytes of data in buffer and rest all is getting discarded.

In case of interrupt mode data is received properly but other parts program in while(1) loop in not executing.

1) I would like to understand, which would be better approach to handle this 20 bytes of data(Interrupt or polling).

2) Kindly suggest the solution for the above issue of polling mode and interrupt mode.

Regards Ajay

  • Hi Ajay,

    ajay kumar13 said:
    1) I would like to understand, which would be better approach to handle this 20 bytes of data(Interrupt or polling).

    This will depend on your application. Polling causes your CPU larger overhead since you have to keep checking if there is any received data. While if you use interrupts then you can immediately handle the incoming data. Do you currently have other interrupts in your application?

    ajay kumar13 said:
    2) Kindly suggest the solution for the above issue of polling mode and interrupt mode.

    Polling mode: Are you using FIFO mode or non-FIFO mode? Have you checked to see if you are getting any overrun errors? 

    Interrupt mode: What part is not executing in your main loop? If you are checking ADC registers or GPIOs have you considered adding this into your ISR?

    Best Regards,

    Marlyn

  • Hi Marlyn,

    Thanks for your response.

    ajay kumar13
    1) I would like to understand, which would be better approach to handle this 20 bytes of data(Interrupt or polling).

    This will depend on your application. Polling causes your CPU larger overhead since you have to keep checking if there is any received data. While if you use interrupts then you can immediately handle the incoming data. Do you currently have other interrupts in your application?

    ajay kumar13

    Reply: I am using ADC and GPIOs. For GPIO and ADC i dont need any interrupt. Then i guess it would be better to go with Interrupt mode. Kindly confirm.

    ajay kumar13
    2) Kindly suggest the solution for the above issue of polling mode and interrupt mode.

    Polling mode: Are you using FIFO mode or non-FIFO mode? Have you checked to see if you are getting any overrun errors? 

    Interrupt mode: What part is not executing in your main loop? If you are checking ADC registers or GPIOs have you considered adding this into your ISR?

    Reply:

    Polling mode: Currently i am using FIFO mode, i will check about the overrun error, but i guess it might not be coming as i am getting last 4 bytes of my serial data. However i will reconfirm same.

    Interrupt mode: I just a code for blinking the LED. I kept a breakpoint and checked, the code in reaching to breakpoint. I have not added ADC and GPIOs in ISR, do i need to add those?

    Best Regards,

    Ajay

  • Hi Ajay,

    ajay kumar13 said:
    Reply: I am using ADC and GPIOs. For GPIO and ADC i dont need any interrupt. Then i guess it would be better to go with Interrupt mode. Kindly confirm.

    Are you planning on sending the ADC result through the SCI? What is your ADC trigger? If you could please provide more information on the sequence of events you would like I can confirm what the best path is.

    ajay kumar13 said:
    Interrupt mode: I just a code for blinking the LED. I kept a breakpoint and checked, the code in reaching to breakpoint. I have not added ADC and GPIOs in ISR, do i need to add those?

    If your code is reaching the breakpoint then the code must be executing. Have you checked if the register bits for the GPIO are changing through the 'Watch Expressions' window? If you SET/CLEAR the GPIO and don't have a delay in between then you might not be seeing the status of the LED change. 

    Depending on when you want your GPIO to change states you could have it TOGGLE every time data is received in your ISR or every time you transmit. Unfortunately, I am unaware of the specific circumstances you want your LED to blink. 

    Best Regards,

    Marlyn

  • Hi Marlyn,

    ajay kumar13
    Reply: I am using ADC and GPIOs. For GPIO and ADC i dont need any interrupt. Then i guess it would be better to go with Interrupt mode. Kindly confirm.

    Are you planning on sending the ADC result through the SCI? What is your ADC trigger? If you could please provide more information on the sequence of events you would like I can confirm what the best path is.

    Reply: Yes i am planning to send the ADC results through SCI. The application needs to read 10 ADC channels and send the result via SCI. I am using ADCINT1 and ADCINT2 as ADC triggers. The application has to read Some switches as externals input( Logic High/Low), generates Logic High/Low output signals(depends on SCI control packet and external digital Inputs), Read 10 Analog inputs and provides status packet on SCI.

    ajay kumar13
    Interrupt mode: I just a code for blinking the LED. I kept a breakpoint and checked, the code in reaching to breakpoint. I have not added ADC and GPIOs in ISR, do i need to add those?
    Reply: I am sorry about me missing NOT in this, which has completely changed the understanding. Actually the code is NOT reaching to breakpoint. 
    Regards
    Ajay

  • Hi Ajay,

    Based on the description you have provided I do think interrupt mode would be the best path.

    Since the code never reaches the breakpoint lets try isolating the gpio portion of it. What happens when you run only the code for the gpio, does it function as intended? If so, I would recommend looking at the 'After Launch' section of the Code Composer Studio guide so that you can step through your code and figure out what your code is doing from a sequence perspective. 

    Best Regards,

    Marlyn

  • Dear Marlyn,

    Thank you for your support.

    1) When i run the code for GPIO, it does function well. I am toggling a LED(GPIO) with a delay.

    2) I will check with "Step over" and "Step In" options today. 

    Regards

    Ajay

  • Hi Ajay,

    Just checking in to see if you were able to run through your code?

    Best Regards,

    Marlyn

  • Dear Marlyn,

    I was able to run through the code, if i was removing the delay_us(10) function from while(1) loop. However In case of delay_us(10) function, the code only reaches once to the while(1) loop and never returns back again. 

    I noticed one more thing, i am trying to received to 4 bytes of data, out of which only first two bytes are proper last two bytes are not correct data.

    I have attached the modified example code, which i am using to check the interrupt based SCI operation. Kindly provide your valuable guidance/comment.

    //###########################################################################
    //
    //!  \addtogroup f2803x_example_list
    //!  <h1>SCI Digital Loop Back with Interrupts(scia_loopback_interrupts)</h1>
    //!
    //!  This program uses the internal loop back test mode of the peripheral.
    //!  Other then boot mode pin configuration, no other hardware configuration
    //!  is required. Both interrupts and the SCI FIFOs are used.
    //!
    //!  A stream of data is sent and then compared to the received stream.
    //!  The SCI-A sent data looks like this: \n
    //!  00 01 \n
    //!  01 02 \n
    //!  02 03 \n
    //!  .... \n
    //!  FE FF \n
    //!  FF 00 \n
    //!  etc.. \n
    //!  The pattern is repeated forever.
    //!
    //!  \b Watch \b Variables \n
    //!  - \b sdataA , Data being sent
    //!  - \b rdataA , Data received
    //!  - \b rdata_pointA ,Keep track of where we are in the datastream.
    //!    This is used to check the incoming data
    //
    //###########################################################################
    // $TI Release: F2803x C/C++ Header Files and Peripheral Examples V129 $
    // $Release Date: January 15, 2015 $
    // $Copyright: Copyright (C) 2009-2015 Texas Instruments Incorporated -
    //             http://www.ti.com/ ALL RIGHTS RESERVED $
    //###########################################################################
    
    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    
    #define CPU_FREQ    60E6
    #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);
    __interrupt void scibTxFifoIsr(void);
    __interrupt void scibRxFifoIsr(void);
    void scia_fifo_init(void);
    void scib_fifo_init(void);
    void error(void);
    void InitGpios();
    
    // Global variables
    Uint16 sdataA[4];    // Send data for SCI-A
    Uint16 rdataA[4];    // Received data for SCI-A
    Uint16 rdata_pointA; // Used for checking the received data
    
    void main(void)
    {
       Uint16 i;
    
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the DSP2803x_SysCtrl.c file.
       InitSysCtrl();
    
    // Step 2. Initalize GPIO:
    // This example function is found in the DSP2803x_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 DSP2803x_Sci.c
       InitSciGpio();
       InitGpios();
    // 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 DSP2803x_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 DSP2803x_DefaultIsr.c.
    // This function is found in DSP2803x_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 DSP2803x_InitPeripherals.c
    // InitPeripherals(); // Not required for this example
       scia_fifo_init();  // Init SCI-A
    
    // Step 5. User specific code, enable interrupts:
    
    // Init send data.  After each transmission this data
    // will be updated for the next transmission
       for(i = 0; i<2; i++)
       {
          sdataA[i] = i;
       }
    
       rdata_pointA = sdataA[0];
    // 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):
        while(1)
        	{
        	SciaRegs.SCITXBUF=0x99;
        	DELAY_US(10);
        	GpioDataRegs.GPASET.bit.GPIO31 = 1;
        	GpioDataRegs.GPBSET.bit.GPIO34 = 1;
        	DELAY_US(10);
        	GpioDataRegs.GPACLEAR.bit.GPIO31 = 1;
        	GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
        	}
    
    }
    
    void error(void)
    {
        __asm("     ESTOP0"); // Test failed!! Stop!
        for (;;);
    }
    
    __interrupt void sciaTxFifoIsr(void)
    {
        Uint16 i;
        for(i=0; i< 2; i++)
        {
    //       SciaRegs.SCITXBUF=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
    }
    
    __interrupt void sciaRxFifoIsr(void)
    {
        Uint16 i;
        for(i=0;i<4;i++)
        {
           rdataA[i]=SciaRegs.SCIRXBUF.all;  // Read data
           SciaRegs.SCITXBUF=rdataA[i];
        }
    //    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
    }
    
    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    =0x0000;  // 9600 baud @LSPCLK = 15MHz (60 MHz SYSCLK).
       SciaRegs.SCILBAUD    =0x00C2;
      // SciaRegs.SCICCR.bit.LOOPBKENA =1; // 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;
    
    }
    
    
    void InitGpios()
    {
        EALLOW;
    
    	// CONFIGURE PINs AS GPIOs  // 0 = GPIO
    
    	GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 0;
    	GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;
    
    	//DEFINE DIRECTION OF IO PINs // 1 = OUTPUT, 0 = INPUT
    	GpioCtrlRegs.GPADIR.bit.GPIO31 = 1;
    	GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;
    
    
    	EDIS;
    
    }
    
    //===========================================================================
    // No more.
    //===========================================================================
    
    

  • Hi Ajay,

    I was able to take your code and modify it a little to get it working on my end. I only have one device available so I enabled loopback.

    With the code below I do see the GPIOs toggling and the content within the while loop being executed. Can you please test the code on your end and let me know if the same thing is true for you?

    //###########################################################################
    //
    //!  \addtogroup f2803x_example_list
    //!  <h1>SCI Digital Loop Back with Interrupts(scia_loopback_interrupts)</h1>
    //!
    //!  This program uses the internal loop back test mode of the peripheral.
    //!  Other then boot mode pin configuration, no other hardware configuration
    //!  is required. Both interrupts and the SCI FIFOs are used.
    //!
    //!  A stream of data is sent and then compared to the received stream.
    //!  The SCI-A sent data looks like this: \n
    //!  00 01 \n
    //!  01 02 \n
    //!  02 03 \n
    //!  .... \n
    //!  FE FF \n
    //!  FF 00 \n
    //!  etc.. \n
    //!  The pattern is repeated forever.
    //!
    //!  \b Watch \b Variables \n
    //!  - \b sdataA , Data being sent
    //!  - \b rdataA , Data received
    //!  - \b rdata_pointA ,Keep track of where we are in the datastream.
    //!    This is used to check the incoming data
    //
    //###########################################################################
    // $TI Release: F2803x C/C++ Header Files and Peripheral Examples V129 $
    // $Release Date: January 15, 2015 $
    // $Copyright: Copyright (C) 2009-2015 Texas Instruments Incorporated -
    //             http://www.ti.com/ ALL RIGHTS RESERVED $
    //###########################################################################
    
    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    
    #define CPU_FREQ    60E6
    #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);
    __interrupt void scibTxFifoIsr(void);
    __interrupt void scibRxFifoIsr(void);
    void scia_fifo_init(void);
    void scib_fifo_init(void);
    void error(void);
    void InitGpios();
    
    // Global variables
    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 Command[10];  // Command received
    Uint16 rxCount;      // Keep track of how many times rx ISR is called
    
    void main(void)
    {
       Uint16 i;
    
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the DSP2803x_SysCtrl.c file.
       InitSysCtrl();
    
    // Step 2. Initalize GPIO:
    // This example function is found in the DSP2803x_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 DSP2803x_Sci.c
       InitSciGpio();
       InitGpios();
    // 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 DSP2803x_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 DSP2803x_DefaultIsr.c.
    // This function is found in DSP2803x_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 DSP2803x_InitPeripherals.c
    // InitPeripherals(); // Not required for this example
       scia_fifo_init();  // Init SCI-A
    
    // Step 5. User specific code, enable interrupts:
    
    // Init send data.  After each transmission this data
    // will be updated for the next transmission
       for(i = 0; i<2; i++)
       {
          sdataA[i] = i;
       }
    
       rdata_pointA = sdataA[0];
    
    // 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):
       while(1){
           DELAY_US(10);
           GpioDataRegs.GPASET.bit.GPIO31 = 1;
           GpioDataRegs.GPBSET.bit.GPIO34 = 1;
           DELAY_US(10);
           GpioDataRegs.GPACLEAR.bit.GPIO31 = 1;
           GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
       }
    
    }
    
    void error(void)
    {
        __asm("     ESTOP0"); // Test failed!! Stop!
        for (;;);
    }
    
    __interrupt void sciaTxFifoIsr(void)
    {
        Uint16 i;
        for(i=0; i< 2; i++)
        {
           SciaRegs.SCITXBUF=sdataA[i];     
        }
    
        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
    }
    
    __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;
    
        if (rxCount == 10){              // Clear Command 
            for(i= 0; i<rxCount; i++)
               {
                Command[i] = 0;
               }
                rxCount=0;
        }
        else{
            for(i= 0; i<2; i++)          // Store the received characters
            {
                Command[rxCount] = rdataA[i];
                rxCount ++;
            }
        }
    
    
        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    =0x0000;      // 9600 baud @LSPCLK = 15MHz (60 MHz SYSCLK).
       SciaRegs.SCILBAUD    = SCI_PRD;    // SCI_PRD
       SciaRegs.SCICCR.bit.LOOPBKENA =1;  // Enable loop back
       SciaRegs.SCIFFTX.all=0xC022;       // TXFILL = 2 
       SciaRegs.SCIFFRX.all=0x0022;       // RXFILL = 2 
       SciaRegs.SCIFFCT.all=0x00;
    
       SciaRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset
       SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1;
       SciaRegs.SCIFFRX.bit.RXFIFORESET=1;
    
    }
    
    
    void InitGpios()
    {
        EALLOW;
    
        // CONFIGURE PINs AS GPIOs  // 0 = GPIO
    
        GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 0;
        GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;
    
        //DEFINE DIRECTION OF IO PINs // 1 = OUTPUT, 0 = INPUT
        GpioCtrlRegs.GPADIR.bit.GPIO31 = 1;
        GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;
    
    
        EDIS;
    
    }
    

    Within the SCIFFRX register you'll notice that RXFFST can only indicate when there are up to 4 words in the FIFO, meaning your RXFILL can only go up to 4.

    Because you want to receive a command of 20 bytes (10 words) I added an extra part in the RX FIFO ISR to store the incoming data until 20 bytes were received. 

    If you wanted to do the following, then you will have to alter your RXFILL and TXFILL appropriately and then find a way to store the data in a way that best meets your needs.

    Uint16 sdataA[4];    // Send data for SCI-A                     
    Uint16 rdataA[4];    // Received data for SCI-A 


    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    
    #define CPU_FREQ    60E6
    #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);
    __interrupt void scibTxFifoIsr(void);
    __interrupt void scibRxFifoIsr(void);
    void scia_fifo_init(void);
    void scib_fifo_init(void);
    void error(void);
    void InitGpios();
    
    // Global variables
    Uint16 sdataA[4];    // Send data for SCI-A
    Uint16 rdataA[4];    // Received data for SCI-A
    Uint16 rdata_pointA; // Used for checking the received data
    
    void main(void)
    {
       Uint16 i;
    
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the DSP2803x_SysCtrl.c file.
       InitSysCtrl();
    
    // Step 2. Initalize GPIO:
    // This example function is found in the DSP2803x_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 DSP2803x_Sci.c
       InitSciGpio();
       InitGpios();
    // 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 DSP2803x_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 DSP2803x_DefaultIsr.c.
    // This function is found in DSP2803x_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 DSP2803x_InitPeripherals.c
    // InitPeripherals(); // Not required for this example
       scia_fifo_init();  // Init SCI-A
    
    // Step 5. User specific code, enable interrupts:
    
    // Init send data.  After each transmission this data
    // will be updated for the next transmission
       for(i = 0; i<4; i++)
       {
          sdataA[i] = i;
       }
    
       rdata_pointA = sdataA[0];
    
    // 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):
       while(1){
           DELAY_US(10);
           GpioDataRegs.GPASET.bit.GPIO31 = 1;
           GpioDataRegs.GPBSET.bit.GPIO34 = 1;
           DELAY_US(10);
           GpioDataRegs.GPACLEAR.bit.GPIO31 = 1;
           GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
       }
    
    }
    
    void error(void)
    {
        __asm("     ESTOP0"); // Test failed!! Stop!
        for (;;);
    }
    
    __interrupt void sciaTxFifoIsr(void)
    {
        Uint16 i;
        for(i=0; i< 4; i++)
        {
           SciaRegs.SCITXBUF=sdataA[i];
        }
    
        for(i=0; i< 4; 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
    }
    
    __interrupt void sciaRxFifoIsr(void)
    {
        Uint16 i;
        for(i=0;i<4;i++)
        {
           rdataA[i]=SciaRegs.SCIRXBUF.all;  // Read data
        }
        for(i=0;i<4;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
    }
    
    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    =0x0000;      // 9600 baud @LSPCLK = 15MHz (60 MHz SYSCLK).
       SciaRegs.SCILBAUD    = SCI_PRD;    // SCI_PRD
       SciaRegs.SCICCR.bit.LOOPBKENA =1;  // Enable loop back
       SciaRegs.SCIFFTX.all=0xC020;       // TXFILL = 0
       SciaRegs.SCIFFRX.all=0x0024;       // RXFILL = 4
       SciaRegs.SCIFFCT.all=0x00;
    
       SciaRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset
       SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1;
       SciaRegs.SCIFFRX.bit.RXFIFORESET=1;
    
    }
    
    
    void InitGpios()
    {
        EALLOW;
    
        // CONFIGURE PINs AS GPIOs  // 0 = GPIO
    
        GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 0;
        GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;
    
        //DEFINE DIRECTION OF IO PINs // 1 = OUTPUT, 0 = INPUT
        GpioCtrlRegs.GPADIR.bit.GPIO31 = 1;
        GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;
    
    
        EDIS;
    
    }

    Hopefully you can use what I have provided above to further your debug!

    Best Regards,

    Marlyn

  • Hi Marlyn,

    Thank you very much for support. will check and get back to you.

    Regards

  • Hi Marlyn,

    Thank you very much, the code is working fine.

    Regards

    Ajay