Threaded R/W Hardware Serial

Status
Not open for further replies.

dk23

Member
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
 
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_timing_IntervalTimer.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.
 
Status
Not open for further replies.
Back
Top