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.

TMS320F280049C: SCI and UART confusion.

Part Number: TMS320F280049C
Other Parts Discussed in Thread: C2000WARE

Tool/software:

Since, the launchpad f280049c has SCI instead of UART, I am confused if i necessarily have to use a USB-UART/Serial converter or something. In-fact I am trying to send data through Qt console to the Launchpad but the launchpad does not respond. Since i was using the XDS110 probe for debugging, i reckoned the same would be enough to interface Laptop and Launchpad. 

  • Hello,

    SCI  (accessible on the c28x core) is a module that uses/supports a UART protocol. The main characteristics of the UART protocol are that there are only 2 physical pin connections (TX: transmit and RX: receive), a shared baud rate (bits/second) between the two communicating devices, and that the communication is asynchronous (no clock signal is shared). 

    If you are using the Launchpad, you should be able to communicate to your PC with only the USB connection since the board has a USB-UART bridge already. You just have to make sure the board switches are set to use the correct SCI GPIOs that are connected to that path. (see you board schematics for this). We have an SCI echoback example in C2000Ware that can be used to test this connection as well: {C2000Ware}0\driverlib\f28004x\examples\sci.

    Best Regards,

    Allison

  • I was able to make SCIA and SCIB communicate with each other using echo-back example, so that part works well. However, the challenge now is transferring the UART connection across different applications. Despite having everything set up correctly in the code, I’m still not able to get it working. Any advice would be appreciated!

    Thanks, Allison.

  • Hi Momina,

    Glad to hear you got it working! Can you please elaborate on the issue you are seeing and applications you are trying to apply to? Are you having trouble with C2000 side SCI configurations? Wire connections/GPIO allocations? Are you able to run your program already and scope the pins to validate outputs? Or unable to build the project and seeing specific build errors?

    Once I know a bit more about the context and what state your development is in, I may be able to help provide better guidance.

    Best Regards,

    Allison

  • Hey Allison. I was just experimenting and testing a code on Qt to see if i can use serial communication to interface Qt software and Launchpad. Below is the code I used to see if the SCI works. I toggled GPIO 23 and GPIO34 LEDS to debug if every part of the transmit receive is being performed as I was not able to see anything on console. 

    #include <device.h>
    #include <driverlib.h>
    #include <f28004x_gpio.h>
    #include <adc.h>
    #include <f28004x_sci.h>
    #include <gpio.h>
    #include <stdio.h>
    #include <stdint.h>

    volatile struct SCI_REGS *ScibReg = (volatile struct SCI_REGS *) SCIB_BASE;
    volatile struct SCI_REGS *SciaReg = (volatile struct SCI_REGS *) SCIA_BASE;
    volatile struct GPIO_CTRL_REGS *GC = (volatile struct GPIO_CTRL_REGS *) GPIOCTRL_BASE;
    volatile struct GPIO_DATA_REGS *GD = (volatile struct GPIO_DATA_REGS *) GPIODATA_BASE;

    void initSCIB(void);
    void initSCIA(void);
    void scia_xmit(int a);
    int scia_recv(void);
    void scib_xmit(int a);
    int scib_recv(void);
    void scia_send_string(const char *str);

    int main(void)
    {
    Device_init();
    Device_initGPIO();
    SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_SCIA);
    Interrupt_initModule();
    Interrupt_initVectorTable();
    EINT;
    ERTM;
    EALLOW;

    GC->GPADIR.bit.GPIO23 = 1;
    GC->GPBDIR.bit.GPIO34 = 1;
    GD->GPADAT.bit.GPIO23 = 1;
    GD->GPBDAT.bit.GPIO34 = 1;

    GPIO_togglePin(34);
    DEVICE_DELAY_US(3000000);

    initSCIA();
    initSCIB();
    GPIO_togglePin(34);
    DEVICE_DELAY_US(3000000);

    EDIS;

    while (1)
    {
    scia_send_string("Hey\r\n");
    GPIO_togglePin(23);
    DEVICE_DELAY_US(3000000);

    int dataB = scib_recv();
    if (dataB != -1)
    {
    scib_xmit('5');
    }

    int dataA = scia_recv();
    if (dataA != -1)
    {
    scia_xmit(dataA);
    GPIO_togglePin(23);
    }

    }
    }

    void initSCIA(void)
    {
    GC->GPAMUX2.bit.GPIO16 = 6;
    GC->GPAMUX2.bit.GPIO17 = 6;
    GC->GPADIR.bit.GPIO16 = 1;
    GC->GPADIR.bit.GPIO17 = 0;
    SciaReg->SCICCR.all = 0x0007;
    SciaReg->SCICTL1.bit.RXENA = 1;
    SciaReg->SCICTL1.bit.TXENA = 1;
    SciaReg->SCICTL1.bit.SWRESET = 0;
    SciaReg->SCICTL2.bit.TXINTENA = 1;
    SciaReg->SCICTL2.bit.RXBKINTENA = 0;
    SciaReg->SCIHBAUD.all = 0;
    SciaReg->SCILBAUD.all = 64;
    SciaReg->SCICTL1.bit.SWRESET = 1;
    }

    void initSCIB(void)
    {
    GC->GPBMUX1.bit.GPIO40 = 9; //TX
    GC->GPBMUX2.bit.GPIO57 = 6;
    GC->GPBDIR.bit.GPIO40 = 1; // Set GPIO40 (TX) as Output
    GC->GPBDIR.bit.GPIO57 = 0; // Set GPIO57 (RX) as Input

    ScibReg->SCICCR.all = 0x0007;

    ScibReg->SCICTL1.bit.RXENA = 1;
    ScibReg->SCICTL1.bit.TXENA = 1;
    ScibReg->SCICTL1.bit.SWRESET = 0;

    ScibReg->SCICTL2.bit.TXINTENA = 1;
    ScibReg->SCICTL2.bit.RXBKINTENA = 0;

    ScibReg->SCIHBAUD.all = 0x0000; // High byte (2)
    ScibReg->SCILBAUD.all = 0x00A2; // Low byte (83)

    ScibReg->SCICTL1.bit.SWRESET = 1;
    }

    void scia_xmit(int a)
    {
    while (SciaReg->SCICTL2.bit.TXRDY != 1);
    SciaReg->SCITXBUF.all = a;
    }

    void scib_xmit(int a)
    {
    while (ScibReg->SCICTL2.bit.TXRDY != 1);
    ScibReg->SCITXBUF.all = a;
    }

    int scia_recv(void)
    {
    if (SciaReg->SCIRXST.bit.RXRDY == 1)
    {
    return SciaReg->SCIRXBUF.all;
    }
    return -1;
    }

    int scib_recv(void)
    {
    if (ScibReg->SCIRXST.bit.RXRDY == 1)
    {
    return ScibReg->SCIRXBUF.all;
    }
    return -1;
    }

    void scia_send_string(const char *str)
    {
    while (*str)
    {
    scia_xmit(*str++);
    }
    }

    Now this code is supposed to have the SCI initiated and working on the Launchpad right? so I wrote this code to communicate through the COM3 port (where Launchpad is connected) from the Qt. And i am not sure if the baudrates didnt match or what but the Launchpad was not responding. 

    #include <QCoreApplication>
    #include <QSerialPort>
    #include <QSerialPortInfo>
    #include <QTextStream>
    #include <iostream>
    int main(int argc, char *argv[]) {
        QCoreApplication a(argc, argv);
        // Create a QSerialPort object
        QSerialPort serial;
        // List available serial ports
        const auto ports = QSerialPortInfo::availablePorts();
        for (const QSerialPortInfo &port : ports) {
            std::cout << "Found port: " << port.portName().toStdString() << std::endl;
        }
        // Replace "COM3" with the port name your Launchpad is connected to
        serial.setPortName("COM3");
        serial.setBaudRate(QSerialPort::Baud9600);  // Set baud rate to match the Launchpad
        // Open the serial port
        if (!serial.open(QIODevice::ReadWrite)) {
            std::cerr << "Failed to open serial port: " << serial.errorString().toStdString() << std::endl;
            return 1;
        }
        // Set up a QTextStream for input/output
        QTextStream cin(stdin);
        QTextStream cout(stdout);
        // Example loop to send data and read responses
        while (true) {
            // Send data to Launchpad
            cout << "Enter data to send (type 'exit' to quit): ";
            cout.flush();
            QString input = cin.readLine();
            if (input == "exit") {
                break;  // Exit the loop
            }
            // Write data to the serial port
            serial.write(input.toUtf8());
            serial.waitForBytesWritten();
            // Wait for a response
            if (serial.waitForReadyRead(3000)) {  // Wait for data (timeout after 3 seconds)
                QByteArray response = serial.readAll();
                while (serial.waitForReadyRead(10)) {
                    response += serial.readAll();
                }
                std::cout << "Received: " << response.toStdString() << std::endl;
            } else {
                std::cerr << "No response from Launchpad!" << std::endl;
            }
        }
        // Close the serial port
        serial.close();
        return a.exec();
    }
    I am fairly new and trying out different interfaces and all so, if i am missing something or doing it wrong, please correct me.
    Regards,
    Momina
  • Hi Momina,

    I unfortunately can't speak too much to the Qt side, but for F28004x you can also verify the SCI module is configured properly by enabling internal loopback mode (where RX and TX are tied together internally) and transmitting data to verify you are transmitting and receiving the same thing ("looping back the data"). That can help in terms of ensuring the SCI module is working as expected.

    We have several loopback examples in C2000Ware as well in that same location {C2000Ware}\driverlib\f28004x\examples\sci.

    Are you able to confirm loopback functionality?

    Best Regards,

    Allison

  • Allison, it would be much appreciated if you could just guide me to debugging the code using console. I tried using the led's but I would like to absolutely confirm it by displaying the transmitted/received the on the console (or a Terminal). In my case if i use puts - like i've seen people use, it won't print anything or give a memory issue maybe! 

  • Hi Momina, 

    Using loopback mode can help to debug in terms of verifying the SCI function independent of your other device. It is also helpful to run the program and set breakpoints in various places in the code and then view the SCI registers at those points to check the status of your SCI regs. Note that if you are looking at your received data, you should use the SCIRXEMU reg and not SCIRXBUF - there are notes about this in the TRM. You could also create global variables and increment them within your RX or TX functions (e.g. in your RX/TX ISRs) and then add these as CCS watch variables to see the variable increment to indicate it passed certain parts of your code. 

    If you are trying to communicate via the serial terminal in CCS on your PC, then you need to be transmitting data from F28004x to your PC using the correct GPIOs (the schematics of your board will give information as to which SCI GPIOs are connected to the right hardware to send across the UART-USB bridge).

    There is also an FAQ that has some SCI debug tips as well:

    https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1031947/faq-my-c2000-sci-is-not-transmitting-and-or-receiving-data-correctly-how-do-i-fix-this 

    Best Regards,

    Allison