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.

TMS320F28388S: UART SCI interrupt

Part Number: TMS320F28388S
Other Parts Discussed in Thread: C2000WARE

Tool/software:

Hello,

     I am working on  SCI-UART (TMS320F28388S) .

    taken example sci_ex2_loopback_interrupts from devicelib in that just commented loopback function 

    but not getting output what is the issue 

    I have attached code for reference 

  

//
// Included Files
//
#include "driverlib.h"
#include "device.h"

//
// Globals
//

//
// Send data for SCI-A
//
uint16_t sDataA[2];

//
// Received data for SCI-A
//
uint16_t rDataA[2];

//
// Used for checking the received data
//
uint16_t rDataPointA;

//
// Function Prototypes
//
__interrupt void sciaTXFIFOISR(void);
__interrupt void sciaRXFIFOISR(void);
void initSCIAFIFO(void);
void error(void);

//
// Main
//
void main(void)
{
uint16_t i;

//
// Initialize device clock and peripherals
//
Device_init();

//
// Setup GPIO by disabling pin locks and enabling pullups
//
Device_initGPIO();

//
// GPIO28 is the SCI Rx pin.
//
GPIO_setControllerCore(DEVICE_GPIO_PIN_SCIRXDA, GPIO_CORE_CPU1);
GPIO_setPinConfig(DEVICE_GPIO_CFG_SCIRXDA);
GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCIRXDA, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(DEVICE_GPIO_PIN_SCIRXDA, GPIO_PIN_TYPE_STD);
GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCIRXDA, GPIO_QUAL_ASYNC);

//
// GPIO29 is the SCI Tx pin.
//
GPIO_setControllerCore(DEVICE_GPIO_PIN_SCITXDA, GPIO_CORE_CPU1);
GPIO_setPinConfig(DEVICE_GPIO_CFG_SCITXDA);
GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCITXDA, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(DEVICE_GPIO_PIN_SCITXDA, GPIO_PIN_TYPE_STD);
GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCITXDA, GPIO_QUAL_ASYNC);

//
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
//
Interrupt_initModule();

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
//
Interrupt_initVectorTable();

//
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
//
Interrupt_register(INT_SCIA_RX, sciaRXFIFOISR);
Interrupt_register(INT_SCIA_TX, sciaTXFIFOISR);

//
// Initialize the Device Peripherals:
//
initSCIAFIFO();

//
// Init the send data. After each transmission this data
// will be updated for the next transmission
//
for(i = 0; i < 2; i++)
{
sDataA[i] = i;
}

rDataPointA = sDataA[0];

Interrupt_enable(INT_SCIA_RX);
Interrupt_enable(INT_SCIA_TX);

// Interrupt_enableInPieCtrl(9); // PIE Group 9 controls SCI interrupts (RX, TX)

Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);

//
// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
//
EINT;
ERTM;

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

//
// error - Function to halt debugger on error
//
void error(void)
{
GPIO_writePin(31, 1); // Turn on LED at GPIO31 for debugging (Optional)
asm(" ESTOP0"); // Test failed!! Stop!
for (;;);
}

//
// sciaTXFIFOISR - SCIA Transmit FIFO ISR
//
__interrupt void sciaTXFIFOISR(void)
{
uint16_t i;

// Ensure TX FIFO is not full before writing
while (SCI_getTxFIFOStatus(SCIA_BASE) == SCI_FIFO_TX16);


SCI_writeCharArray(SCIA_BASE, sDataA, 2);

//
// Increment send data for next cycle
//
for(i = 0; i < 2; i++)
{
sDataA[i] = (sDataA[i] + 1) & 0x00FF;
}

SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXFF);

//
// Issue PIE ACK
//
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
}

//
// sciaRXFIFOISR - SCIA Receive FIFO ISR
//
__interrupt void sciaRXFIFOISR(void)
{
uint16_t i;

SCI_readCharArray(SCIA_BASE, rDataA, 2);

//
// Check received data
//
for(i = 0; i < 2; i++)
{
if(rDataA[i] != ((rDataPointA + i) & 0x00FF))
{
error();
}
}

rDataPointA = (rDataPointA + 1) & 0x00FF;

if (SCI_getOverflowStatus(SCIA_BASE))
{
SCI_clearOverflowStatus(SCIA_BASE);
}

SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_RXFF);

//
// Issue PIE ack
//
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
}

//
// initSCIAFIFO - Configure SCIA FIFO
//
void initSCIAFIFO()
{
//
// 8 char bits, 1 stop bit, no parity. Baud rate is 9600.

//uint16_t sysClockFreq = SysCtl_getClock(DEVICE_OSCSRC_FREQ);
SCI_performSoftwareReset(SCIA_BASE);

SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 9600, (SCI_CONFIG_WLEN_8 |
SCI_CONFIG_STOP_ONE |
SCI_CONFIG_PAR_NONE));
SCI_enableModule(SCIA_BASE);
// SCI_enableLoopback(SCIA_BASE);
SCI_resetChannels(SCIA_BASE);
SCI_enableFIFO(SCIA_BASE);

//
// RX and TX FIFO Interrupts Enabled
//
SCI_enableInterrupt(SCIA_BASE, (SCI_INT_RXFF | SCI_INT_TXFF));
SCI_disableInterrupt(SCIA_BASE, SCI_INT_RXERR);

//
// The transmit FIFO generates an interrupt when FIFO status
// bits are less than or equal to 2 out of 16 words
// The receive FIFO generates an interrupt when FIFO status
// bits are greater than equal to 2 out of 16 words
//
SCI_setFIFOInterruptLevel(SCIA_BASE, SCI_FIFO_TX2, SCI_FIFO_RX2);
//SCI_performSoftwareReset(SCIA_BASE);

SCI_resetTxFIFO(SCIA_BASE);
SCI_resetRxFIFO(SCIA_BASE);
}

//
// End of file
//

  • TX is working fine ,but RX is not working 

    please check attached code 

    #include "driverlib.h"
    #include "device.h"

    // Globals
    char txString[50]; // Transmit buffer
    volatile uint16_t txIndex = 0; // Transmit index

    char receivedData[50]; // Buffer for received message
    char rxBuffer[50]; // Buffer for received data
    volatile uint16_t rxIndex = 0; // Receive index

    // Function Prototypes
    __interrupt void sciaTXFIFOISR(void);
    __interrupt void sciaRXFIFOISR(void);
    void initSCIAFIFO(void);
    void sendString(const char *str);
    bool receiveString(char *buffer, uint16_t bufferSize);
    void printToSCI(const char *str);

    // Main
    void main(void)
    {
    Device_init();
    Device_initGPIO();

    GPIO_setControllerCore(DEVICE_GPIO_PIN_SCIRXDA, GPIO_CORE_CPU1);
    GPIO_setPinConfig(DEVICE_GPIO_CFG_SCIRXDA);
    GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCIRXDA, GPIO_DIR_MODE_IN);
    GPIO_setPadConfig(DEVICE_GPIO_PIN_SCIRXDA, GPIO_PIN_TYPE_STD);
    GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCIRXDA, GPIO_QUAL_ASYNC);

    GPIO_setControllerCore(DEVICE_GPIO_PIN_SCITXDA, GPIO_CORE_CPU1);
    GPIO_setPinConfig(DEVICE_GPIO_CFG_SCITXDA);
    GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCITXDA, GPIO_DIR_MODE_OUT);
    GPIO_setPadConfig(DEVICE_GPIO_PIN_SCITXDA, GPIO_PIN_TYPE_STD);
    GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCITXDA, GPIO_QUAL_ASYNC);

    Interrupt_initModule();
    Interrupt_initVectorTable();

    Interrupt_register(INT_SCIA_RX, sciaRXFIFOISR);
    Interrupt_register(INT_SCIA_TX, sciaTXFIFOISR);

    initSCIAFIFO();

    Interrupt_enable(INT_SCIA_RX);
    Interrupt_enable(INT_SCIA_TX);
    Interrupt_enablePIE();
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);

    EINT;
    ERTM;

    while(1)
    {
    if (receiveString(receivedData, sizeof(receivedData)))
    {
    sendString(receivedData); // Echo received message
    //printf("recived data\n");

    }
    //sendString("welcome");
    }
    }

    void sendString(const char *str)
    {
    strncpy(txString, str, sizeof(txString) - 1);
    txString[sizeof(txString) - 1] = '\0'; // Ensure null termination
    txIndex = 0;
    SCI_enableInterrupt(SCIA_BASE, SCI_INT_TXFF);
    }

    bool receiveString(char *buffer, uint16_t bufferSize)
    {
    if (rxBuffer[0] != '\0')
    {
    strncpy(buffer, rxBuffer, bufferSize - 1);
    buffer[bufferSize - 1] = '\0';
    memset(rxBuffer, 0, sizeof(rxBuffer));
    printToSCI("Received: ");
    printToSCI(buffer);
    printToSCI("\n");
    return true;
    }
    return false;
    }

    __interrupt void sciaTXFIFOISR(void)
    {
    if (txString[txIndex] != '\0')
    {
    SCI_writeCharBlockingNonFIFO(SCIA_BASE, txString[txIndex]);
    txIndex++;
    }
    else
    {
    txIndex = 0;
    SCI_disableInterrupt(SCIA_BASE, SCI_INT_TXFF);
    }
    SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXFF);
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
    }

    __interrupt void sciaRXFIFOISR(void)
    {
    printf("data is coming");
    char receivedChar = SCI_readCharBlockingNonFIFO(SCIA_BASE);

    if (rxIndex < sizeof(rxBuffer) - 1)
    {
    rxBuffer[rxIndex++] = receivedChar;
    if (receivedChar == '\n' || receivedChar == '\r')
    {
    rxBuffer[rxIndex] = '\0';
    rxIndex = 0;
    }
    }
    else
    {
    rxIndex = 0;
    memset(rxBuffer, 0, sizeof(rxBuffer));
    }

    if (SCI_getOverflowStatus(SCIA_BASE))
    {
    SCI_clearOverflowStatus(SCIA_BASE);
    }
    SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_RXFF);
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
    }

    void initSCIAFIFO()
    {
    SCI_performSoftwareReset(SCIA_BASE);

    SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 9600,
    (SCI_CONFIG_WLEN_8 | SCI_CONFIG_STOP_ONE | SCI_CONFIG_PAR_NONE));

    SCI_enableModule(SCIA_BASE);
    SCI_resetChannels(SCIA_BASE);
    SCI_enableFIFO(SCIA_BASE);

    SCI_enableInterrupt(SCIA_BASE, (SCI_INT_RXFF | SCI_INT_TXFF));
    SCI_disableInterrupt(SCIA_BASE, SCI_INT_RXERR);

    SCI_setFIFOInterruptLevel(SCIA_BASE, SCI_FIFO_TX1, SCI_FIFO_RX1);

    SCI_resetTxFIFO(SCIA_BASE);
    SCI_resetRxFIFO(SCIA_BASE);
    }

    void printToSCI(const char *str)
    {
    while (*str != '\0')
    {
    SCI_writeCharBlockingNonFIFO(SCIA_BASE, *str++);
    }
    }

  • Hi Tejashri,

    Please test the standalone (unchanged) example from C2000ware and make sure it works for you. This will confirm that your hardware setup is correct. 

    Best Regards,

    Delaney

  • helllo,

        can you please suggest me which example i need to take share me example name 

  • Hi Tejashri,

    I would suggest starting with the sci_ex3_echoback example in C2000ware path: [C2000ware install]\driverlib\f2838x\examples\c28x\sci. This example will help you verify your hardware setup by communicating with the COM port on your PC. The only thing you may have to modify would be the GPIO configurations depending on your specific board. Are you using a LaunchPAD or controlCARD?

    Best Regards,

    Delaney