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.

Sending hex values via UART

Other Parts Discussed in Thread: TM4C123GH6PGE, MAX3232

Hi,

My board is TM4C123GH6PGE. What i'm tring to achieve is to send hex commands to another controller throw the UART. Currently, i can send and receive data throw UART0 (USB cable) while connected to the PC. With a simple serial port teminal app' i can see the messages that i send from the controller to the PC.

I looked over the uart_echo.c example and i tried to change all of the UART0 references to UART3, and also initiate the relevent pins. After that i connected the Rx, Tx, GND and VCC(3.3) pins to an TTL to RS232 convertor because as i know, RS232 protocol doesn't work with 3.3v.

Now that my system is connected to the PC i tried to send messages between the PC and the controller but now my PC doesn't get anything from the controller.

My code for sending to PC is: 

UARTCharPut(UART3_BASE, 0xAB);

My final achievement is to send data from TI controller to anothe controller, by i prety sure that if it work with the PC i will work with another controller (non TI).

Thank You.

  • Hi Moataz,

    If you are using a Serial Monitor it most likely converts everything with ASCII code!
    0xAB won't show up anything in ASCII code so it's normal.

    Either configure the serial monitor to show the values received in hexa, connect to a scope (preferably one that connects to the computer and decodes various protocols including UART), or connect to another Tiva that receives the values, converts them in a way that you can read them in the serial monitor.

    Try sending UARTCharPut(UART3_BASE, 49); to confirm that the connection is working, it should read the number "1"
  • Hi,

    Post your modified uart_echo code here for review. Also, make sure that you are connecting the Tiva UART pins to the TTL to RS232 converter correctly.

    - kel
  • Hi Luis and Markel,

    Thank you for your response.

    First, the 0xAB what just an example for the hex string that i need to send. My actual strings are like: 0x08003024AFC and the meaning of this string is to set a command to another driver (non TI product).

    As i continue working with uart_echo.c example i changed the sending message to: UARTCharPut(UART3_BASE, 49);. I put this line inside the infinite while so from my understanding the controller should write "1" to serial without stop.

    This is not working. What is working is when i write to serial port terminal in my PC some hex values, the TI controller transmits back hex values but not the same.

    So i looked in the example again for the UARTIntHandler function, but i didn't understand who is the variable that holds the incomming message.

    The modifies code is attached, and i looked again to my TTL to RS232 convertor and it looks ok.

    uart_echo modified.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    //*****************************************************************************
    //
    // uart_echo.c - Example for reading data from and writing data to the UART in
    // an interrupt driven fashion.
    //
    // Copyright (c) 2011-2013 Texas Instruments Incorporated. All rights reserved.
    // Software License Agreement
    //
    // Texas Instruments (TI) is supplying this software for use solely and
    // exclusively on TI's microcontroller products. The software is owned by
    // TI and/or its suppliers, and is protected under applicable copyright
    // laws. You may not combine this software with "viral" open-source
    // software in order to form a larger program.
    //
    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Thank you.

  • Simple minded question here - does your PC actually have a (real) RS-232 style port?

    Few do - these days - and as you detailed your use of a proper RS-232 level converter - you'd need a (real) RS-232 port @ your PC end.

    You report success w/the original PC connection - that via USB. Most all PC's today support only USB - serial and parallel ports having long vanished.

    Undescribed is "how" your PC will handle (real) RS-232 signal levels....    And - "looked at" is less comforting than "scoped" input & output of RS-232 level shifter...

    Devil lives in (and loves) such details - all missing herein...

  • My PC do have a real RS-232 port (and also CANOpen ports).
    My connection now is: TI controller -> TTL to RS232 convertor -> RS232 cable that connects to the PC motherboard and vice versa.
    The USB that i mentioned is the USB cable that i got with the board for download the code into it.
    Thanks.
  • Shay Geva said:
    My PC does have a real RS-232 port

    Good that - but due to the "rarity" of such (our firm special orders PCs w/serial ports) we had to ask.   And - great "lightening" response by you!

    Now may we move beyond "looked at?"   Scope really simplifies/speeds data tracking between MCU's UART & level shifter's in/out. 

    Always there's the chance that your PC-side serial port requires HW "Handshake" - have you checked on that - and if possible - disabled it?

    Eased way to test UART/RS-232 level shifter is via continuous transmission of 0x55 or 0xAA.  (both produce equal width, alternating bit pattern)

    First time wiring or cable (you may have a "null modem" cable or "straight-through" cable) - only one will work.   (unless you modify)  Depends upon your PC serial and your wiring at/to the level shifter.

    BTW ...  English is screwy language - your title broadcast "throw" (throw a ball) - "through" (means through a pipe)

  • Hi,
    I scoped my Rx line from the PC to the controller and i can see a nice square wave every time i send some data from the PC to the controller, so the controller receives my data.
    About the "Hankshake", i don't know how and where i can modify this.
    The continuous transmission is my main problem..the command that i'm sending from the driver to the PC through( :-) ) RS-232 is :
    UARTCharPut(UART3_BASE, 0xAA);
    When i'm sending data from the PC to the driver, the driver sends me back wrong data,
    for example if i'm sending 00 i'm getting back FF, AA -> D5, FF -> FF and so on...
    Currently the sending command inside my 'while' command doesn't do nothing.
    Thanks
  • We've moved a bit too fast for my tastes - and have avoided KISS.  (that's our standard "modus operandi.")

    As I understand your situation - you have a stand-alone PC which includes an RS232 port.  And you have another maker's "driver."

    We know nothing about this "driver."

    May we establish the fact that you can exchange simple, ASCII readable text (0x20-0x7F) between your MCU and your PC?   (eliminate the "driver" for now)  It's vital that we proceed in small stages - too much - bundled together - always masks, lengthens and unduly complicates.

    Please eliminate "strings" for now.   Suggest that you attempt single (readable) character transmissions - between both your MCU and PC and PC and MCU.  Use 0x41 "A" for example - so it's arrival @ PC will not be clouded.  

    Your sending a known (good) character (such as 0x41) and your report of results (after doing just that) speeds/simplifies diagnosis.

    Continued use of "throw" rather than (corrected) "through" in your subject/title flags concern for your attention to detail...

  • OK,

    The driver that i'm talking about is a Technosoft driver, but as you said i'm not using it for now, just tring to send 0x41 from the MCU to the PC.

    So i still got nothing here, the MCU doesn't send data to the PC.

    i attached the code that i'm downloading to the MCU if you want to review it.

    0081.uart_echo modified.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    //*****************************************************************************
    //
    // uart_echo.c - Example for reading data from and writing data to the UART in
    // an interrupt driven fashion.
    //
    // Copyright (c) 2011-2013 Texas Instruments Incorporated. All rights reserved.
    // Software License Agreement
    //
    // Texas Instruments (TI) is supplying this software for use solely and
    // exclusively on TI's microcontroller products. The software is owned by
    // TI and/or its suppliers, and is protected under applicable copyright
    // laws. You may not combine this software with "viral" open-source
    // software in order to form a larger program.
    //
    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Also i have another Q,

    In the example code there is a function that handels the incomming data (UARTIntHandler). How can i view the data that this function get (for example if i want to print it to the console using printf)?

    Thanks

  • Shay Geva said:
    i [sic] I still got nothing here, the MCU doesn't send data to the PC.

    How do you know that?  

    1)  Have you checked w/scope to observe bit patterns flow from MCU's UART_TX to TX_IN of RS232 level shifter?   And then

    2) If "1" appears "normal" - have you then moved your scope to TX_OUT (i.e. RS232 levels now) and observed the data input to TX_IN now "INVERTED" and significantly level shifted (when you monitor TX_OUT? 

    3) Earlier I provided "alternating bit" codes to speed/ease such test.  Your level shifter raises the voltages and inverts the signals introduced upon it's TX_IN pin.  Minus your report of success at the "level shifter" - all else reduces to, "guesswork."   (not really my/other's interest)

    Should the level shifter scope monitoring "pass" (as described here) check and double check your cable and or connections to the PC.   Are you quite certain that all connections are proper?   Have you any means to (independently) test your PC's serial port?

    I cannot recall what program you are using @ PC side for serial terminal.   Many of these (default) into HW handshake - which you must disable!   (as I past noted)   your job is to insure that HW handshake is disabled - or we (continue) to spin our wheels. 

    You may edit your first post's subject to replace "throw" with the word you intended, "through."   Or you may replace "throw" with "via." 

  • Hi,
    Yesterday i knew that the MCU didn't sent any data to the PC because i scoped the lines and saw nothing in my scope. When i skoped the lines with TI uart_echo.c example i saw the signals very well.
    Today i got a different TTL to RS232 convertor and still nothing... now my skope doesn't shw me ant signal..
    I'm really don't know what i'm doing wrong and it's very frustrating.. I'm just want that my TI board send the letter 'a' over the UART.. :-(
    My convertor is: Serial Port Mini RS232 to TTL Converter Adaptor Module Board MAX3232 with Arduino.
    Also i looked over the connection again and they are all correct according to the datasheets.
    Thank You,
  • Feel you pain - detail instructions past provided have (always) led to serial port "fix."

    Thank you for correcting your subject - new forum "blows up" each title - to have an error there is disturbing.

    If your scope shows no data movement from UART_TX - you're stuck.   If that's (really) the case - I fear you may have connected (at some point) the RS-232 level shifter's RS232 levels to the MCU - which (often) proves destructive.

    Are you sure that your scope is working?   Have you measured 3V3 on your board - and then the HV (~12VDC) upon your RS232 level shifter - prior to measuring UART_TX @ the MCU?   Are you sure that you're probing the correct pin(s). 

    One guy - even looking over connections - may not prove best.   Even a hand drawn schematic - posted here - gains you "many" eyes for review.   (often I "cannot see" my own (repeated) mistake - that's why Lone Ranger so often fails - where small team succeeds.)  

    Suggest that you switch that UART_TX pin on your MCU to GPIO Output - and pulse it.  Then monitor w/your scope.   If pin is "dead" you'll soon know it.   But if it works as GPIO - suspect it will work as UART - too.  

    We need small, careful steps now.   Frustration helps no one - you've got your direction - I fly in an hour so farewell...

  • Did you modify the startup code to configure the UART interrupt handler for UART3?
    Have you tried running the program with a debugger to see if UARTCharPut and UARTIntHandler work as expected?

    Randy