AceRoutine with SPI communications #52
Replies: 2 comments 2 replies
-
Hi, I've never tested AceRoutine on a SAMD51, so I'm just guessing, but here are some thoughts:
So to answer your question about using AceRoutine inside an SPI transaction, I have never done that because AceRoutine cannot guarantee the timing delays due to the interaction with other coroutines. I have always used I scanned your code to see if there are any other interaction between AceRoutine and the SPI transactions. Nothing obvious stood out for me. My guess is that the |
Beta Was this translation helpful? Give feedback.
-
I tried out the logic analyzer and discovered I was just missing the SPI transaction. I was using the one-shot form of coroutine (_BEGIN() and _END() ). I switched to a COROUTINE_LOOP() and it works as expected. I don't really need this part to be a coroutine, but it's nice to know I could get it to work. The library is still useful for other parts of my project though i.e. controlling the step timing of a stepper motor without blocking everything else, although I suppose I could use a timer interrupt instead. |
Beta Was this translation helpful? Give feedback.
-
Great library and easy to use.
However I encountered a problem trying to use the coroutine to communicate with LS7366R chip (quadrature encoder counter) that uses SPI communication. I wonder if you've every tried SPI communications with AceRoutine?
I've created a class for my sensor and it works fine when it is not a coroutine i.e. I can get the count. However when I created a CoroutineEncoder class derived from Coroutine I always get a return value of 0. The basic procedure to get the count is to send a command via (simplified, see full code below):
SPI.transfer(0xE8)
// brief delay required by LS7366r (minimum is 120 ns)
COROUTINE_DELAY_MICROS(1)
//then receive the count
count = SPI.transfer(0x00) //repeat a few times, then combine with bit-shift and OR'ing; input argument here is ignored
This is used with another coroutine that makes use of COROUTINE_DELAY() to control the speed of a stepper motor (which works really well), so I don't want any of these delays to be blocking.
Here is the header file:
And the coroutine in the .cpp file:
Execution leaves the runCoroutine and later returns at the COROUTINE_DELAY_MICROS, and this is between the SPI.beginTransaction() and SPI.endTransaction(). Does this somehow interfere with SPI functionality? Currently there are no other SPI communications in my system. Have you (or anybody else) had any success using SPI with AceRoutine? The coroutine may not be necessary for such a short delay time, but I'm trying to understand why SPI isn't working within the runCoroutine? Any ideas would be appreciated. In case it matters, I'm using the the Metro M4 Grand Central (SAMD51) and the Arduino IDE. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions