Skip to main content
hospodar
Associate III
November 20, 2012
Question

UART example code for STM32F0

  • November 20, 2012
  • 60 replies
  • 11870 views
Posted on November 20, 2012 at 23:34

Hello,

I looking for some example code for communication between my ST-DISCOVERY F0 board and PC (UART). Can someone help me with it? I´m novice.

Thank you
    This topic has been closed for replies.

    60 replies

    hospodar
    hospodarAuthor
    Associate III
    May 7, 2015
    Posted on May 07, 2015 at 22:42

    Now, I have three .c files (main.c, fifo.c, stdio_through_usart.c). In all of them is included fifo.h.

    fifo.h contains:

    #ifndef FIFO_H
    #define FIFO_H
    #define RXSIZE 1024
    #define TXSIZE 512
    uint8_t RxBuffer[RXSIZE];
    uint8_t TxBuffer[TXSIZE];
    typedef
    struct
    {
    char
    * buf;
    int
    head;
    int
    tail;
    int
    size;
    } fifo_t;
    fifo_t RxFifo[1];
    fifo_t TxFifo[1];
    void
    fifo_init(fifo_t * f, 
    char
    * buf, 
    int
    size);
    int
    fifo_read(fifo_t * f, 
    void
    * buf, 
    int
    nbytes);
    int
    fifo_write(fifo_t * f, 
    const
    void
    * buf, 
    int
    nbytes);
    #endif /* FIFO_H */

    But now there is new errors. Is this double inclusion? I have defined these arrays just once. Error: L6200E: Symbol RxBuffer multiply defined (by stdio_through_usart.o and main.o). Error: L6200E: Symbol RxBuffer multiply defined (by fifo.o and main.o). Error: L6200E: Symbol TxBuffer multiply defined (by stdio_through_usart.o and main.o). Error: L6200E: Symbol TxBuffer multiply defined (by fifo.o and main.o). Error: L6200E: Symbol RxFifo multiply defined (by stdio_through_usart.o and main.o). Error: L6200E: Symbol RxFifo multiply defined (by fifo.o and main.o). Error: L6200E: Symbol TxFifo multiply defined (by stdio_through_usart.o and main.o). Error: L6200E: Symbol TxFifo multiply defined (by fifo.o and main.o).
    Tesla DeLorean
    Guru
    May 7, 2015
    Posted on May 08, 2015 at 01:16

    Define the actual variables, once, in your .C file, and the refer to them in your .H file with the extern prefix.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    May 7, 2015
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    hospodar
    hospodarAuthor
    Associate III
    May 13, 2015
    Posted on May 13, 2015 at 18:43

    to be migrated, sourceId: 13890:74F499D6-C293-4561-BFB5-4F1489999957

    Tesla DeLorean
    Guru
    May 13, 2015
    Posted on May 13, 2015 at 20:02

    It's a FIFO, you've presumably already pulled other byte(s) from the buffer, and the tail has moved forward to account for that. It doesn't shift/copy the buffer content, it keeps track of where the ''next'' byte should come from.

    Variable advances, data doesn't move.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    May 13, 2015
    Posted on May 13, 2015 at 20:09

    to be migrated, sourceId: 13895:74F499D6-C293-4561-BFB5-4F1489999957

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    jeffrey23
    Associate III
    September 16, 2015
    Posted on September 16, 2015 at 16:04

    Dear All,

    How I can retarget scanf function to software buffer in order to send data in interrupt handler?

    Tesla DeLorean
    Guru
    September 16, 2015
    Posted on September 16, 2015 at 17:33

    Keil allows you to provide a replacement for int fgetc(FILE *f)

    int fgetc(FILE *f)
    {
    uint16_t ch;
    while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
    ch = USART_ReceiveData(USART1);
    return((int)ch);
    }

    Alternatively, make a buffer, and use sscanf() ?
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    alla_venugopal
    Visitor II
    November 26, 2015
    Posted on November 26, 2015 at 13:48

    Hi clive1,

    I am new to STM32F0 contoller. I need to communicate 2 STM32F0 controllers using RS485 protocol.Could you please share the code.

    Thanks

    Tesla DeLorean
    Guru
    November 26, 2015
    Posted on November 26, 2015 at 15:06

    Not really a combination I have an example for, you'll need to review the peripheral library examples, source, and reference docs, related to 1-wire USART operation.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..