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.

Serial Communication between TIVA and Motor Driver

Would someone clarify the difference between UARTprint and UARTwrite. I am using a TIVA TM4C123GXL to transmit via UART to a motor driver. The specification of the driver say that it must be 8 bits no parity and 1 bit to stop at a baud rate of 9600 ( this is the one I'm choosing out of 4 different baud rates).

The driver is set to work as follows.

Char   Motion

1            full reverese

64          stop

127       full forward.

I started with lab 12 of the workshops and have included the two push buttons on the board. My code constantly prints a 64 (using UARTPUTCHAR function) unless one of the buttons is pressed in that case either print a 1 for reverse or a 127 for forward.

-Problems

My problem with using UARTPutChar is that when I write '127' it truncates the 12 and by using my putty I can tell it only transmits a 7. Similar scenario with 64.


I did some digging into some other codes and have discovered the UARTprint and the UARTwrite functions by adding the symbolic files.

So my question arises from this discovery, what is the difference and which one should I be using to communicate necessarily with the motor driver?

Thank You,

Luis Alberto Vergara-Rodriguez

  • Hi Luis,

    UARTprint and UARTwrite (btw those are not the complete names) are from the UARTstdio utility libraries while UARTCharPut (not UARTPutChar) is from the driver library.
    UARTCharPut simply allows to send a char by UART. So when you write '127' you are trying to send 3 chars, hence why the function only sends '7'. Remember that these are characters, sending '127' is different from sending 127.

    The UARTstdio helps allot if you want to send strings of multiple characters. There's the function UARTprintf() that in terms of code works just like printf(), 1st parameter is the string and the parameters that follow are the variables that you want to use on the string.
    UARTwrite also can also be used to send a string but the first parameter is the string to be sent and the second parameter is the length of the string. Personally I like to use UARTprintf over UARTwrite but whatever floats your boat.
  • Thank you for the reply. That clarifies a lot.
    Now if you are in fact telling me that '127' is not the same as sending character 127 would you mind telling me how to send character 127?
    My first guess is some kind of conversion but how do I convert 127 into only one character?

    Thanks again,

    Luis Alberto Vergara-Rodriguez

  • Hi Luis,

    That's a pretty basic question, try to look into how you output a string into the console (C++: cout, C:printf) and what is a char (see ASCII table).

    Each char is composed by 1 byte = 8 bits. And for examples the char '0' is the number 48. If you write 48 and output it as a char it will show 0.
    Hence '127' is composed by the chars '1', '2' and '7'. So the numeric value is actually 49, 50 and 55 (again, ascii table).

    So now a question arises, does your driver require the string "127" or the value 127? 127 can be easily be sent with UARTCharPut() since it's withing the range of a 8bit value but for the string "127" it requires either 3 UARTCharPut to send '1', '2' and '7' more easily use UARTprintf() which accepts a string so you can straight use "127" or '127' -the use of " means in the end there's an extra char '\0' so it might make a difference for your controller. Now if you need to use '127' instead of "127" I do believe you need to use UARTwrite() since UARTprintf() uses the '\0' to know the end of the string and the use of ' instead of " means there isn't one.

    Now if you don't know when your sending 7 or '7':
    UARTCharPut(UART0_BASE,7); //sends value 7
    UARTCharPut(UART0_BASE,'7'); //sends char '7' which is value 55. Notice the '. Using " is wrong since you are sending an extra char, the '\0'
  • Correct, I do understand what the difference is. I shall do some test to get to the bottom of it. Whether it is in fact a number or a character that it is need. My guess is that it will be the character it needs but I have done test with this kind and they haven't been quite successful in turning my motor other than is small twitches that resemble a stalled car trying to start again.

    Thank you a lot.
  • I got it to work, thank you very much Luis Alfonso(big fan of yours btw). I found out that the correct way to do it was by using UARTCharPut(UART_BASE, 127) or 64 or 1, without the single quotes.


    -Luis Alberto Vergara-Rodriguez

  • Glad to be of help.

    I wish you good luck with your project :)