Clearing UART buffers



  • Hello,
    I have connected a GPS module to GPy board and reading NMEA strings from it. My code flow is such that the GPS module keeps on sending data continuously on UART. When I need the GPS data in my application, I read the buffer, parse the buffer for a specific NMEA message and read out the data.
    Here, I want to clear the buffers after each successful GPS read. How can I achieve that?
    I'm already using uart.deinit() and seems that it is not clearing the buffers.



  • @jmarcelino @catalin Thank you for the suggestions! Will try this.


  • administrators

    hi @sprasad, if you're using uart.read([nbytes]), or uart.readall() the UART internal buffer is "consumed" and cleared. Isn't this what you want to achieve?

    I would call uart.readall() and wait 1 sec (probably NMEA messages are coming 1Hz), so after 1sec I would have in uart buffer the latest messages.



  • Hello @sprasad
    Can you do a uart.readall() and just ignore the results?


 

Pycom on Twitter