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: rx interrupt issue tms320f28388s

Part Number: TMS320F28388S

Tool/software:

i am using SCI-A interrupt for UART 

I am using device library 

SCI_setFIFOInterruptLevel(SCIA_BASE, SCI_FIFO_TX2, SCI_FIFO_RX1);

after setting SCI_FIFO_RX1 i am getting garbage values 

after setting  SCI_FIFO_RX0 getting correct output but duw to this interrupt continuously coming and while(1) inside main it is not working  

i will attach my code please check and let me know the issues

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

//
// Globals
//
uint16_t loopCounter = 0;
bool newStringReceived = false; // Flag to indicate a complete string has been received
volatile bool transmitComplete = true; // Flag to indicate transmit is ready

// Message buffers
volatile char txBuffer[100]; // Transmit buffer
volatile uint16_t txLength = 0; // Length of data to transmit
volatile uint16_t txIndex = 0; // Current position in transmit buffer

volatile char rxBuffer[100]; // Receive buffer
volatile uint16_t rxIndex = 0; // Current position in receive buffer
volatile char processedString[100]; // Buffer for the fully received string

// Function Prototypes
__interrupt void sciaRXISR(void);
__interrupt void sciaTXISR(void);
void initSCI(void);
void sendMessage(const char *msg);
static bool startCapture = false;

void UART_init(void)
{
//
// 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);

}

void UART_interruptInit(void)
{
Interrupt_enablePIE();
Interrupt_register(INT_SCIA_RX, sciaRXISR);
Interrupt_register(INT_SCIA_TX, sciaTXISR);

initSCI();

Interrupt_enable(INT_SCIA_RX);
Interrupt_enable(INT_SCIA_TX);
Interrupt_enableInCPU(INTERRUPT_CPU_INT9);
Interrupt_enablePIE();
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
}

//
// Initialize SCI for interrupt-based operation
//
void initSCI(void)
{
//
// Reset and configure SCI
//
SCI_performSoftwareReset(SCIA_BASE);

//
// Configure SCIA for 9600 baud, 8-N-1
//
SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 9600, (SCI_CONFIG_WLEN_8 |
SCI_CONFIG_STOP_ONE |
SCI_CONFIG_PAR_NONE));

//
// Reset channels and FIFOs
//
SCI_resetChannels(SCIA_BASE);
SCI_resetRxFIFO(SCIA_BASE);
SCI_resetTxFIFO(SCIA_BASE);

//
// Clear any pending interrupts
//
SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXFF | SCI_INT_RXFF);

//
// Enable FIFO
//
SCI_enableFIFO(SCIA_BASE);

//
// Set FIFO interrupt levels
//
SCI_setFIFOInterruptLevel(SCIA_BASE, SCI_FIFO_TX2, SCI_FIFO_RX1);

//
// Enable receive interrupt only (transmit will be enabled when needed)
//
SCI_enableInterrupt(SCIA_BASE, SCI_INT_RXFF);

//
// Disable error interrupts;;;;;;;;;
//
SCI_disableInterrupt(SCIA_BASE, SCI_INT_RXERR);

//
// Enable the SCI module
//
SCI_enableModule(SCIA_BASE);

while(SCI_getRxFIFOStatus(SCIA_BASE) > 0)
{
SCI_readCharNonBlocking(SCIA_BASE);
}

SCI_writeCharNonBlocking(SCIA_BASE, '\r');
SCI_writeCharNonBlocking(SCIA_BASE, '\n');
}

//
// Send a null-terminated message string
//
void sendMessage(const char *msg)
{
// Wait for any ongoing transmission to complete
while(!transmitComplete);

// Copy message to transmit buffer
uint16_t i = 0;
while(msg[i] != '\0' && i < sizeof(txBuffer)-1)
{
txBuffer[i] = msg[i];
i++;
}

// Set message length and reset index
txLength = i;
txIndex = 0;

// Mark transmission as in progress
transmitComplete = false;

// Enable transmit interrupt to start sending
SCI_enableInterrupt(SCIA_BASE, SCI_INT_TXFF);
}

//
// SCI-A Receive FIFO ISR
//
__interrupt void sciaRXISR(void)
{
uint16_t availableChars;
char receivedChar;
uint16_t j,i;

// Get number of characters in the FIFO
availableChars = SCI_getRxFIFOStatus(SCIA_BASE);

// Process all available characters
for(i = 0; i < availableChars; i++)
{
// Read a character
receivedChar = SCI_readCharNonBlocking(SCIA_BASE);

// Echo back the character so user can see what they're typing
SCI_writeCharNonBlocking(SCIA_BASE, receivedChar);

// Process the received character
if(receivedChar == '\r' || receivedChar == '\n')
{
// End of line - complete the string
// Pad the remaining buffer with spaces
rxBuffer[rxIndex]='\0';
/* for (j = rxIndex+1; j < 50; j++)
rxBuffer[j] = ' ';*/

// Fill the rest of the buffer with null terminators
//memset(&rxBuffer[rxIndex + 1], '\0', 100 - (rxIndex + 1));
memset(&rxBuffer[rxIndex], '\0', 100 - (rxIndex + 1));
// Copy to processed buffer
strcpy(processedString, rxBuffer);

// Reset buffer for next string
rxIndex = 0;

// Set flag that a complete string is received
newStringReceived = true;
}
else if(receivedChar == '\b' || receivedChar == 127)
{
// Backspace - remove last character if buffer not empty
if(rxIndex > 0)
{
rxIndex--;

// Send backspace sequence to erase character on terminal
SCI_writeCharNonBlocking(SCIA_BASE, ' ');
SCI_writeCharNonBlocking(SCIA_BASE, '\b');
}
}
else if(rxIndex < sizeof(rxBuffer) - 1)
{
// Store character in buffer if not full
rxBuffer[rxIndex] = receivedChar;
rxIndex++;
}

/* if(receivedChar == 'G') // Use any appropriate start character
{
// Start of a new message
rxIndex = 0;
startCapture = true;
// Don't store the start character if you don't want it
}
else if(startCapture && (receivedChar == '\r' || receivedChar == '\n'))
{
// End of message - process as you're already doing
rxBuffer[rxIndex] = '\0';
memset(&rxBuffer[rxIndex], '\0', 100 - rxIndex);
strcpy(processedString, rxBuffer);
rxIndex = 0;
startCapture = false;
newStringReceived = true;
}
else if(startCapture && rxIndex < sizeof(rxBuffer) - 1)
{
// Only store characters after we've seen the start character
rxBuffer[rxIndex] = receivedChar;
rxIndex++;
}*/
}

// Check for overflow
if(SCI_getOverflowStatus(SCIA_BASE))
{
SCI_clearOverflowStatus(SCIA_BASE);
}

// Clear the interrupt flag
SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_RXFF);
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
}

//
// SCI-A Transmit FIFO ISR
//
__interrupt void sciaTXISR(void)
{
uint16_t i;
uint16_t charsToSend = 0;

// Calculate how many characters we can send (up to FIFO depth)
while((txIndex + charsToSend < txLength) && (charsToSend < 16))
{
charsToSend++;
}

// Send the characters
for(i = 0; i < charsToSend; i++)
{
SCI_writeCharNonBlocking(SCIA_BASE, txBuffer[txIndex++]);
}

// Check if all characters have been sent
if(txIndex >= txLength)
{
// Disable the transmit interrupt
SCI_disableInterrupt(SCIA_BASE, SCI_INT_TXFF);

// Mark transmission as complete
transmitComplete = true;
}

// Clear the interrupt flag
SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXFF);
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
}

  • Hi Tejashri,

    While full code analysis is not something we can support on the E2E forum, I can help explain how the SCI FIFO level works and answer any conceptual questions you have.

    For the SCI receiver, the FIFO level interrupt will be raised when the FIFO level is at or above the programed level. So, if you have the FIFO level set to 0, it will trigger when the FIFO has zero or more elements (so basically constantly). If set to a FIFO level of 1, the interrupt will trigger every time the FIFO has one or more words. Generally, with a FIFO level of 1, you want to read one word every time the flag is raised in order to stay synchronized. If the interrupt becomes blocked (by other higher priority ISRs) or there are errors on the receiving line (shown in the SCIRXST register), this synchronization can get thrown off. How many bytes is the other device sending to the C2000 device at a time? 

    Best Regards,

    Delaney