Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Threaded R/W Hardware Serial

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    11

    Threaded R/W Hardware Serial

    I'm working on a project that reads and sometime writes to a hardware serial port. I would like to put read/writing into a separate thread that writes to maybe a queue that the main can read for processing. Looking for pointers to code that can get me over the start line. As this project progresses I want to be able to use threads for I2C or SPI reading writing. Yes, This is yet another Ublox GPS project. HW: is Teensy 4.1

    Thanks

  2. #2
    You could use IntervalTimer if you plan to run these at a fixed interval. This is what I have used to acquire data from SPI and pass data to the main loop.
    https://www.pjrc.com/teensy/td_timin...rvalTimer.html

    Also check out TeensyThreads. If you don't already have it installed you can do so through the teensyduino installer.
    https://github.com/ftrias/TeensyThreads

    Once you go down this route you will need to consider race conditions, mark variables as volatile as needed, possibly use locks if you are writing to SPI/I2C in multiple threads. I would start by playing around with one of them, see if you can get something working and ask any questions that come up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •