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.

TMDSCNCD280025C: Displaying variables using SCI

Part Number: TMDSCNCD280025C

Hello!

I wanted to implement basic uart.
This is the program that I've written. I'm stuck on how to display the values of different variables by using %d, %s etc.
In the program below, I've printed a basic string.

//
// Included Files
//
#include "driverlib.h"
#include "device.h"
#include "board.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"

//
// Globals
//
uint16_t loopCount;
uint16_t errorCount;

//
// Function Prototypes
//
void error();
void uart(char[],int);

//
// Main
//
void main(void)
{
char send[256] = "Hello Everyone!\n";

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

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

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

//
// Board Initialization
//
Board_init();

//
// Enables CPU interrupts
//
Interrupt_enableGlobal();


//
// Send a character starting with 0
//
//sendChar = 0;

//
// Send Characters forever starting with 0x00 and going through 0xFF.
// After sending each, check the receive buffer for the cSCIorrect value.
//
for(;;)
{
uart(send,sizeof(send));
}

}

void uart(char name[],int a)
{

uint16_t sendChar;
uint16_t receivedChar;
uint8_t i;
char each;

for( i = 0; i<a; i++)
{
each = name[i];
sendChar = (uint16_t)each;

SCI_writeCharNonBlocking(mySCI0_BASE, sendChar);

//
// Wait for RRDY/RXFFST = 1 for 1 data available in FIFO
//
while(SCI_getRxFIFOStatus(mySCI0_BASE) == SCI_FIFO_RX0)
{
;
}

//
// Check received character
//
receivedChar = SCI_readCharBlockingFIFO(mySCI0_BASE);

//
// Received character not correct
//
if(receivedChar != sendChar)
{
asm(" ESTOP0"); // Uncomment to stop the test here
for (;;);
}
}
}

//
// End of file
//

output:

  • Hi,

    You don't need to use %d, %s in the SCI configuration. Every number is treated as a character which you can send the way you're using to send the 'Hello Everyone!' characters. Do you face any difficulty in doing so?

    Aditya

  • Thank you for responding. Let's suppose there is an integer variable count.

    uint16_t count=10;

    How should the character array send[] be defined such that the output is "The value of count is 10". I'm sending this array to the function 'uart'.

  • Hi Pranoti,

    You can count the number of data values to be sent and accordingly send the data as mentioned in the code snippet below:

        msg = "\r\n\n\nHello World!\0";
        SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 17);

    On your query regarding sending the number, you can checkout the example - sci_ex3_echoback

    The numbers are also treated in the same way as characters.

    Thanks,

    Aditya