Quantcast
Viewing all articles
Browse latest Browse all 20046

Multiple objects/threads/Interrupts - Using SPI at the same time

I am playing around with my little App that uses my Adafruit 2.8" TFT shield as adisplay console. I will launch this app when I power up my Edison that is mounted on a robot, that will display things like Battery voltage.  In addition I have touch buttons, that when I press one, it launches my Phoenix code base, when I press a different one it does a "Shutdown Now" command.

 

I ran into issue where the stuff I am trying to output to the TFT display was getting corrupted and other stuff stops working. So have simple app that keeps adding a line every two seconds and it is working. May refine a little the displaying, but...

 

Then figured out what that issue is. I created a secondary thread to wait on the pipe and when it receives data it then writes it to the display (SPI). Meanwhile the main thread is looking for user input from the touch screen (SPI), and the two spi communications collide.

 

Trying to decide which way I want to fix it.

a) Set up my own mutex or semaphore or like object which each of these threads explicitly sets/clears when doing these operations. Probably the quickest way to fix it. Although this may require me to do stuff in several different places.

 

b) Have my 2ndary thread put the messages into a queue that the primary thread, looks at from time to time and then it does the write to the main screen. sort of defeats the secondary thread.

 

c) See about adding the SPI begin/end transaction work that is going into the more recent Arduino IDEs and I know that is done for the Teensy. Internally it probably does the same as a)...   There are several threads about this up on the Teensy forums, with lots of pros and cons about the solution, but the main idea is that several libraries have been updated like the Adafruit ILI9341 library, STMPE610 library SDCARD... where updated, that many of the APIs have built into them, Calls like begin Transaction/end transaction.  These calls try to make sure you don't end up with multiple partial conversations at same time.  Especially when some of these may run at different speeds...

 

The good news is at least I think I know what this issue is.  Now trying to decide what I should do for now with my Edison code.

 

Thoughts?

Kurt


Viewing all articles
Browse latest Browse all 20046

Trending Articles