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.

CCS/TM4C123GH6PM: Transmitting variable content to UART of tiva module.

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

Hello,

I am Balaji, i am not getting how to transmit data stored in variables(like updated sensor values) to UART module of TM4C123GH6PM.

I am using UARTCharPut() API to send a charecter, but what should use to send content of variable to UART.

unsigned char a=34;

UARTCharPut(UART0_BASE,a);

if i do this i am getting only on the serial monitor.

  • Hello Balaji,

    That's exactly what I would expect with the API you used. That is just going to print out the input value straight to the terminal which will represent the value as an ASCII character. The ASCII character for 0x34 is 4. Hence your printout is '4' and not 34.

    What you need to do is use UARTprintf. Try that and see if the result is as you desire.
  • Thanks Ralph,

    If i use UARTprintf what all the libraries i have to include. 

    And as you told UARTCharPut() will print ASCII character but if i send 78 instead of 34 it is printing 8 not ASCII character for78. Please let me know what is the reason.

  • Hello Balaji,

    You need to include the uartstdio file in your project.

    If you have TivaWare linked properly (this will be the case for sure if using a TivaWare exmaple) then you can just use this line of code:

    #include "utils/uartstdio.h"

    As far as the 78 printing as an 8, I am not sure. The UARTCharPut API just transmit the character as is, so it would send 0x78 over the line. Did you check if your terminal's baud rate aligns with the MCU baud settings?

  • Hello Ralph,

    Feel NOT bad - I thought - 'Exactly as you had!'    (not that (that) - provides much comfort.)      Although it must be noted - that  0x34  (not 34)  is the ASCII equivalent of  '4'.

    The standard  UARTCharPut() - as its 'source code' reveals - is  limited to a single character - and the (first '4' (from 34) and later '8' (from 78)) were the  last characters placed w/in the UART's FIFO - thus  'those'  characters ('ALONE' being Sent) appear to 'violate'  the  'First In - First Out'  (FIFO) operation - do they not?    (Clearly the 'First In' (3) and then (7) - appear  NOT to have been  'FIRST OUT!'    *** (unless they were 'over-written' - yet the terminal's 'capture' - appears to have eliminated that possibility.)

    Might you (attempt) to detail (even explain) this (apparent) FIFO contradiction?    (LIFO (Last In - First Out)  appears to be  (pardon)  FAR More 'operational' - here...)

    [EDIT]:  Pondering this a bit more - it appears (most) likely that the, 'FIFO's treatment, handling and/or acceptance' of  the presented variable - must prove 'key.'    And to further complicate - there exists a 'duality'  here - does there not?     In the case of the variable 'a=34' -  the FIFO (may) see this as, '2 unique characters' - or as  the variable's (actual) value!    (so long as that value is 255 or less.)     From  this poster's (preliminary) report - it appears that such 'multi-digit' variable is (seen) by the FIFO as 'least significant digit' - gaining FIRST ENTRY to the FIFO - and thus 'First to Exit.'    (maybe)     Further experimentation - and my earlier (another thread's) request for (some) FIFO Detailing (to which no response resulted) leaves us in (some) confusion...

    If there existed some means - to ouput the FIFO's content - (without requiring the addition of the character parameter - within ' UARTCharPut()' -  then (that) just may - present the (missing) '3' ... or  '7' ... in our poster's  use case!       While the 'API Giveth' ... it (sometimes)  Taketh Away!

    As an admittedly 'crude' (yet, Good for Gov't Work) (likely)  solution - and one desires to transfer '9876' via the uart - the following (untested) is presented:

    UARTCharPut(UART0_BASE, '9');
    UARTCharPut(UART0_BASE, '8');
    UARTCharPut(UART0_BASE, '7');
    UARTCharPut(UART0_BASE, '6');   //  assumes that 'CR/LF' is not embedded - and that characters fill the screen - from Left to Right...

    I made the time/effort to (much earlier) review the code of the 'key function' w/in, 'uartstdio'  ( UARTvprintf() ) - it IS a  nightmare!     Even the function's author apologizes - noting (multiple)  'GO TO's - therein...

    I suggest that our poster employ 'basic math' - to  'extract each (base 10) 'positional value' from the 'multi-digit variable' - and present those (now proper) individual numeric characters - to the  far faster & more efficient, 'UARTCharPut()' function.     HINT:  the proper use of  'divide by powers of ten' - followed by the '%' operator - renders 'Single Digit Extraction - from a Multi-Digit field' - quick & easy!  

    This 'use of basic math'  proves (near)  Universal in:  Value, Usage & Application - as well.    (which 'uartstdio' does not!)     Consider the case of an attached 'LCD' - which (also) requires the receipt of, "Individual Characters" - rather than the 'multi-digit' variable.     The 'broader, math solution' - appears the CLEAR WINNER - due to its far greater 'REACH & VALUE!'     And - of course - proves,  'Vendor Agnostic!'