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.

LAUNCHXL-F28379D: transmitting more than one char over SCI

Part Number: LAUNCHXL-F28379D

Hi,

I am using the echoback.c program of TI C2000. I would like to send more than one character (as in picture attached, jpt for example) over the Hyperterminal (or Putty).

I was going through the forum, but I missed myself among too much other infos. Can you please guide me further?

which example of C2000 works the best in my case?

  • Hi parisaSA,

    In the echoback example, the DSP is already sending multiple characters via the
    scia_msg(msg)

    function. e.g. the "Hello World!" message is sent using one function call.
  • Hi Devin,

    the "Hello world" is a fixed message, that in the loop of function scia_msg() is transmitting character by character.

    I like to transfer more than one character via the PC keyboard, observing them in Hyperterminal (in echoback as I enter one letter it goes to a new line , actually I can enter only one letter).

    Indeed, I need to send one value like 0x0AFF to my program, I should be able to write the value e.g. 0x0AFF via my PC keyboard ( for controlling it see it in Hyperterminal), then set it

    // scia_xmit - Transmit a character from the SCI %%✏ i need to transfer more than one character. e.g. 0x0AFF.
    //
    void scia_xmit(int a)
    {
    while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
    SciaRegs.SCITXBUF.all =a;
    }


    EPwm1Regs.CMPA.bit.CMPA=0x0AFF.

    this value is changing , whenever the user enter new value.

    Regards,

    Parisa
  • Hi Parisa,

    I think you have all the building blocks in the example.  You just need to assemble them with your additional logic to meet your needs:

    • On character receive, copy the character to a buffer
    • (Don't echo back the char)
    • Check if the received character is a newline (or whatever you want your stop character to be)
      • If not the stop character, wait for additional characters
      • If stop character, process message
        • Echo back the whole message
        • Discard any leading whitespace
        • Validate that the first two characters are 0x 
          • (I'm not sure if you want to always send as hex, or if this is supposed to be an option
        • Validate that additional characters before the stop character are all valid hex digits
        • Convert the hex digit characters into a Uint16 or whatever datatype the message represents
        • Write decoded value to register
        • Reset the buffer
      • You could also implement that if a backspace or delete is received, to take the corresponding action on the current message so far
  • Hi Devin,

    thanks for fast reply.

    I changed the code as following:

    /////////////////////

    void scia_echoback_init(void);
    void scia_fifo_init(void);
    void scia_xmit(int a);
    void scia_msg(char *msg);
    #define RESULTS_BUFFER_SIZE 4
    Uint16 SCIMESSAGE[RESULTS_BUFFER_SIZE];

    ///////////////////////////

    for(;;)
    {
    //msg = "\r\nEnter a character: \0";
    //scia_msg(msg);

    //
    // Wait for inc character
    //
    for(resultsIndex = 0; resultsIndex < RESULTS_BUFFER_SIZE; resultsIndex++){

    while(SciaRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for empty state
    SCIMESSAGE[resultsIndex] = SciaRegs.SCIRXBUF.all;  // SCIMESSAGE is the buffer name. 
    }
    //
    // Get character
    //

    scia_msg(SCIMESSAGE );
    msg = "\r\nEnter new characters: \0";
    scia_msg(msg);
    // resultsIndex = 0;


    // Echo character back
    //
    //msg = " You sent: \0";
    //scia_msg(msg);

    //scia_xmit(ReceivedChar); // scia_xmit - Transmit a character
    //msg =ReceivedChar\0
    //scia_msg(msg);
    /*
    while(CpuTimer0.InterruptCount < 40) // 40 * 50ms = 2 sec
    {
    EALLOW;
    WdRegs.WDCR.all= 0x00AA; // Re-enable the watchdog // Service watchdog #2

    EDIS;
    }
    CpuTimer0.InterruptCount = 0;
    scia_xmit(ReceivedChar); // scia_xmit - Transmit a character
    */
    LoopCount++;
    }
    }

    //
    // scia_echoback_init - Test 1,SCIA DLB, 8-bit word, baud rate 0x000F,
    // default, 1 STOP bit, no parity
    //
    void scia_echoback_init()
    {
    //
    // Note: Clocks were turned on to the SCIA peripheral
    // in the InitSysCtrl() function
    //

    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.all = 0x0003;
    SciaRegs.SCICTL2.bit.TXINTENA = 1;
    SciaRegs.SCICTL2.bit.RXBKINTENA = 1;

    //
    // SCIA at 9600 baud
    // @LSPCLK = 50 MHz (200 MHz SYSCLK) HBAUD = 0x02 and LBAUD = 0x8B.
    // @LSPCLK = 30 MHz (120 MHz SYSCLK) HBAUD = 0x01 and LBAUD = 0x86.
    //
    SciaRegs.SCIHBAUD.all = 0x0002;
    SciaRegs.SCILBAUD.all = 0x008A;

    SciaRegs.SCICTL1.all = 0x0023; // Relinquish SCI from Reset
    }

    //
    // scia_xmit - Transmit a character from the SCI
    //
    void scia_xmit(int a)
    {
    while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
    SciaRegs.SCITXBUF.all =a;
    while ( SciaRegs.SCICTL2.bit.TXEMPTY == 0); //wait for TX -empty
    }

    //
    // scia_msg - Transmit message via SCIA
    //
    void scia_msg(char * msg)
    {
    int i;
    i = 0;
    while(msg[i] != '\0')
    {
    scia_xmit(msg[i]);
    i++;
    }
    }

    //
    // scia_fifo_init - Initialize the SCI FIFO
    //
    void scia_fifo_init()
    {
    SciaRegs.SCIFFTX.all = 0xE040;
    SciaRegs.SCIFFRX.all = 0x2044;
    SciaRegs.SCIFFCT.all = 0x0;
    }

    "I'm not sure if you want to always send as hex, or if this is supposed to be an option"? I need to send Hex value in my final program. 

    the Hperterminal buad rate is 9600. Just now for testing the code, I am sending four character, after 4 character I receive non-sense character. 

    I should add, when I put the buffer size equals an odd number. e.g. 3, there is no problem. 

    thank you in advanced.

    Parisa

  • Hi Parisa,

    I don't see anything obviously wrong based on a cursory look through the code. You might want to put a breakpoint after a character is received and placed in the buffer to check the state of everything. In this case you'd probably type a new character, verify the state, type the next char, verify the state, etc. Alternately you could set a breakpoint after the buffer is full to see what was received and what the code state is.