Skip to main content
K_P_D
Associate III
March 28, 2018
Question

UART Communication for STM32L4 in KEIL

  • March 28, 2018
  • 13 replies
  • 2369 views
Posted on March 28, 2018 at 14:14

Hi,

I am newbie to this STM32L4 Controller. I am working on GPS device to get the location of the location and i am using the CubeMax and Keil software for programming. As i have mention that i am newbie, I dont know how do I move forward.

I want to Learn the programming in Keil and with their HAL Drive and all. I am using the UART-2 in STM32L4 controller to communicate between the GPS and controller. Here I have used the UART HAL Driver for communication, but i properly dont know that how i should pass argument i that HAL driver function for communication. 

So please share and guide for this UART Communication using HAL Driver in keil. And also share if their is any study material available for this.

I my code HALL function defined like this:

'HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);'

And i have pass the argument like this:

'HAL_UART_Transmit(&huart2 ,(uint8_t*)&buffer,20,1000); '

In buffer i have assigned the AT+QGPSCFG to send the AT command to communicate between the GPS and the Controller.  If their is any problem in code please let me know.

Please share me the proper details for this.

Thanks 

Sachin

    This topic has been closed for replies.

    13 replies

    Tesla DeLorean
    Guru
    March 28, 2018
    Posted on March 28, 2018 at 14:43

    Cross-posted here

    http://www.keil.com/forum/63479/

     

    >> If their is any problem in code please let me know.

    You've showed a single line, you should perhaps be using strings, and only sending the actual length of the viable data rather than arbitrary length.

    GPS receivers typically don't take AT commands, so presume you have a MODEM with a GPS connected. You need to automate the interaction, ie sending commands and parsing and processing responses.

    A lot of this is basic programming rather than being Keil or STM32 specific. You should perhaps focus on general tutorials, and work through all the code examples under the STM32 HAL source trees. Lots of book available of programming, get comfortable with that.

    This is a handler that collects whole GPS NMEA sentences and then passes them off. The USART typically receives a character at a time so you either need to accumulate multiple bytes, or use a state machine.

    https://community.st.com/message/181151-implementing-interrupt-driven-stream-uart-rx-handling-on-l4

     
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    K_P_D
    K_P_DAuthor
    Associate III
    March 29, 2018
    Posted on March 29, 2018 at 08:09

    The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6tN&d=%2Fa%2F0X0000000bxT%2FFkCx5NUNJfeJaytTdclXgIPPKY4DC.KSg6FXEBjemAs&asPdf=false
    AvaTar
    Senior III
    March 29, 2018
    Posted on March 29, 2018 at 08:43

    I have read the AT commands for the GPS operation. They mention so many commands for the many operation like configuration, get location and many others also.

    Are you sure you don't mix up things here ?

    GPS modules don't take AT commands, they use the NMEA 183 standard (or the newer NMEA 2000).

    And the have a default setting (baudrate, update rate, sentences sent), i.e. the work 'out of the box', without configuration.

    I would suggest to concentrate on RX first, use these GPS default settings, and see if you get the sentences.

    Tackle more complex things later.

    Andrew Neil
    Super User
    March 28, 2018
    Posted on March 28, 2018 at 19:33

    I am newbie to this STM32L4 Controller.

    So do you have any prior experience with any other microcontroller(s) ?

    Or with 'C' programming in general?

    Did you study  the learning resources suggested in your cross-post on the Keil forum?

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    K_P_D
    K_P_DAuthor
    Associate III
    March 29, 2018
    Posted on March 29, 2018 at 07:47

    Hi Andrew Neil,

                                Yes, I am experienced with the micro-controller as well as with C language.

    Not yet, for now i am started to read the suggested resources from cross post.

    Andrew Neil
    Super User
    March 29, 2018
    Posted on March 29, 2018 at 12:04

    sachin singh wrote:

    I am experienced with the micro-controller as well as with C language.

    So where's the problem?

    You should be familiar with how to approach a project like this.

    1. Start with something simple - sending 'Hello, World' out of the UART;
    2. Try receiving text - maybe just echo it straight back;
    3. etc, ...
    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.