Skip to main content
Alejandro Ismael
Associate
March 20, 2018
Question

UART stm32f4 discovery board

Posted on March 20, 2018 at 16:20

hi, i need to recive variable amoun of data from the UART, but the problem is that the pointer of the Rx buffer is incremented any time and i cant decrease it, sorry for my english, i working whit stm32f4 discovery bord, thanks

    This topic has been closed for replies.

    8 replies

    Tesla DeLorean
    Guru
    March 20, 2018
    Posted on March 20, 2018 at 16:51

    If the buffering scheme isn't working for you, create a different one. The USART flags RXNE in the status, or can interrupt, upon the reception of each character.

    What library are you using? HAL or SPL

    Posted dozens of STM32F4-DISCO USART examples here over the years.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Alejandro Ismael
    Associate
    March 20, 2018
    Posted on March 20, 2018 at 16:54

    Im using HAL library

    henry.dick
    Associate II
    March 20, 2018
    Posted on March 20, 2018 at 18:15

    First, try to have a realistic expectation on what's doable. If you truly don't know the message length, and want your code to handle potentially an infinitely long message, give up because that's never going to happen in this word.

    If, on the other hand, you are sure that your processor has enough power to remove data from the receiver faster than it can handle, and you just need a buffer to hold the received data temporarily, consider a buffer of some sorts. A circular buffer makes perfect sense here.

    Alejandro Ismael
    Associate
    March 20, 2018
    Posted on March 20, 2018 at 18:19

    I try to read data from a RFID, the proble is that sometimes i have only one tag to read, but sometimes i have two or more tag because is a multitag RFID, so i dont now how many tag im going to read. Thats my problem, sorry for my english

    henry.dick
    Associate II
    March 21, 2018
    Posted on March 21, 2018 at 13:18

    '

    Thats my problem'

    that's the least of your problems,

    anyway, here is a circular buffer - platform independent as well: 

    https://dannyelectronics.wordpress.com/2018/03/14/yet-another-circular-buffer/

     
    Andrew Neil
    Super User
    March 21, 2018
    Posted on March 21, 2018 at 09:13

    As

    henry.****

    ‌ said, you need to do the basic sums on how much data is coming from your RFID reader, and how fast - and consider whether

    stm32f4

    can cope with that.

    However, in general, RFID is neither high-volume nor high-speed data; people having been connecting these things to simple 8-bit micros for decades - so it should really be no problem for a Cortex-M4!

    As already noted, a so-called 'Ring Buffer' (aka 'Circular Buffer' or 'FIFO') is commonly used to buffer UART data ...

    https://en.wikipedia.org/wiki/Circular_buffer

    eg, see:

    https://www.avrfreaks.net/comment/2369221#comment

    and

    https://www.avrfreaks.net/comment/2410116#comment

    and

    https://www.avrfreaks.net/comment/2333471#comment

    also:

    http://www.8052mcu.com/forum/read/74916

    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.