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.

UART & GPS

Expert 2065 points


Hello 

In a previous thread I mentionned that having a workshop related to UART would be helpful and here is the reason why I am asking this: 

I am working at interfacing TM4C123G and GPS L70 from Quectel. The module is supposed to be queried via UART. using some command (which are not AT command but roughly simila: PMTK command, it seems to look like this : $PMTK622,1*29<CR><LF> or $PMTK223,1,30,180000,60000*3C<CR><LF>). In my understanding the way to operate is to send command to the module using TX and then receive some information via RX (the format is NMEA), then to store them on memory, then to send them to another UART for visualization and control (Putty or Teraterm). 

I have difficulties to implement this for several reason: 

1./ Do I undersand that to send command to the module I should use a printf("COMMAND") or a put or UARTSEND in the main of the function . Do I have to use any library to do this ?

2./ Do I understand well that for receivig answer i have nothing to do? The chip will do it automatically ?

3./ Where do I read the values received by the TM4 once received(Uart register ? If yes, where and how)

4./ Do I undertsand well that to store the value received I will need to create an array and to fill it with the received values ? IF yes, what format for the "boxes" in the array it is recommended to use ?

5./ To visualize them I will need to get them back from this array 

In attachment is the datasheet of manufacturerQuectel_L70_GPS_Protocol_Specification_V2.2.pdf

  • This is not particularly a Tiva/TM4C question but rather a serial communications question.

    Might I suggest you get the reference I suggested in the following thread e2e.ti.com/.../1799723

    Robert
  • Chrischina,

    As Robert mentions, this isn't necessarily a TM4C issue and I would add it isn't really a UART issue. What I see is an issue with understanding of how to send and receive data within a specific UART based protocol. Hopefully my suggestions and comments below can help.

    Chrischina said:
    1./ Do I undersand that to send command to the module I should use a printf("COMMAND") or a put or UARTSEND in the main of the function . Do I have to use any library to do this ?

    Any of the functions can be used it simply depends on the level of abstraction you use. Essentially, UART transmits a byte (char) at a time. Multiple of these bytes strung together create the COMMAND or packet. Using the printf functionality is using a higher level utility/API to basically transmit the command for you but if you dig into the printf command it will be deconstructing your COMMAND and transmitting byte by byte. UARTSEND is most likely doing the same thing with a string passed into it. Using putchar would be another method but you would need to deconstruct and pass each char for transmit. I would suggest reviewing posts (searching this forum) on printf as to how to enable support of the printf function or to review the APIs provided with TivaWare in the DriverLib user guide.

    Chrischina said:
    2./ Do I understand well that for receivig answer i have nothing to do? The chip will do it automatically ?

    If properly configured, the TM4C will recieve a byte at a time. Once the FIFO is full, you will get an overrun error which will happen if you do not set up your software to service the receive. In this situation, it would be best to setup an Rx interrupt so that data can be copied out of the buffer before the next data is received or, at least, before an overrun occurs. 

    Chrischina said:
    3./ Where do I read the values received by the TM4 once received(Uart register ? If yes, where and how)

    There are APIs in TivaWare to read the data out of the buffer. Suggest you review these. For specifics on the FIFO operation and location information, suggest you review the Datasheet/user guide for the device. The information is clearly presented in both documents.

    Chrischina said:
    4./ Do I undertsand well that to store the value received I will need to create an array and to fill it with the received values ? IF yes, what format for the "boxes" in the array it is recommended to use ?

    An array is one method if the data lengths of the received data packet is fixed it could be an array of that length but you should consider if you want to save the received data for processing and, if so, how deep of a buffer (array) do you need? You might want to consider an array of structs where the struct is the deconstruction of the COMMAND packet which would facilitate easier parsing and command processing. If, as you state later, your only task is to redisplay the received COMMAND using another UART then you could consider just copying the data directly from UARTx used for the GPS to UARTy used for the interface to the PC (TeraTerm or Putty). In this latter case, there would only be temporary storage for each received byte to be copied to the second UART. Also, in the altter case you would use the API related to sending a char at a time and not the printf function since you will only be able to remap printf to one of the UARTs.

    Chrischina said:
    5./ To visualize them I will need to get them back from this array

    I think I covered this in the prior description. However, if you do store in an array, simply use the putchar (equivalent TivaWare function is UARTCharPut). 

  • why should I use printf and go on algorithm if UARTSEND can directly handle a string ?
  • If you have a formatted string there is almost no circumstance is which printf is the superior choice. It's a lot of overhead for very little gain. Its one advantage is, perhaps, simplicity.

    Robert
  • Chrischina,

    I would absolutely agree with Robert on this as well since printf is not necessarily a portable utility and can change in behavior depending on the development environment used. The only benefit as Robert states is its quick to use and simple. Using an already existing interface would be better if you have it. I don't know UARTSEND as I don't see it in the driverlib documentation or the TivaWare userguides but I do see support for UARTCharPut and UARTCharGet which could be used to support my earlier described methodology and reinforces the idea of treating the string as a collection of bytes.
  • Thank you both for your answers. 

    UARTSend is included in the uart_echo.c example of EK TM4C123G