I am trying to implement the DShot protocol, which is summarized pretty well at this link: https://www.speedgoat.com/help/slrt/page/io_main/refentry_dshot_usage_notes. This protocol is pretty similar to Teensy would communicate with the WS2811 LED driver chip, and for this reason I have decided to adapt Paul's OctoWS2811 library for this task. Another benefit of his library is that it uses DMA and thereby frees up the processor, which is another plus for my application (a quadcopter). The general approach I use to generate these signals is explained pretty well at this video (relevant part begins around 12:07 and goes to the end): https://www.youtube.com/watch?v=fNLxHWd0Bvg. To be very brief, the code uses a similar timing setup to the OctoWS2811 to trigger DMA transfers to the Teensy 3.6 GPIO set and clear registers (in my case, since I am on Teensy 4.0, I am using GPIO9_DR_SET and GPIO9_DR_CLEAR).
Getting back to my code. I have read up on the datasheet and made every effort to actually understand Paul's code, so i am not blindly copy-pasting and as such I think I have a pretty decent grasp of what is going on in his code. My main file looks like this (the delayMicroseconds is there to simulate flight controller loop time, as it would be occupied with other things for at least that long):
What happens in this code (as I figured out through my own debugging) is that the function writeDshot() runs once, but then on the second loop it hangs on the following line forever:
I suspect this is something to do with the fact that I manually set b1DMAChannel as complete on line 88 in the setup function:
However, it should keep looping infinitely, as the OctoWS2811 code does. Can anybody offer me clues as to what is going wrong with my code? This is for a highschool senior capstone project that is due early next week, and since I have spent the better part of a week struggling with this issue to no avail, I thought I would come here for guidance.
Many thanks,
Michael
P.S. I have included the files dshotDMA.h and dshotDMA.cpp, which contain all relevant methods. The middle function fillDshotBuffer shouldn't be an issue, since it doesn't interfere with DMA and I checked that its output is what it should be, and the last function in the file xbar_connect is a copy of the function Paul wrote for pwm.c in the Teensy 4 core files.
View attachment dshotDMA.cpp View attachment dshotDMA.h
Getting back to my code. I have read up on the datasheet and made every effort to actually understand Paul's code, so i am not blindly copy-pasting and as such I think I have a pretty decent grasp of what is going on in his code. My main file looks like this (the delayMicroseconds is there to simulate flight controller loop time, as it would be occupied with other things for at least that long):
Code:
#include <Arduino.h>
#include "dshotDMA.h"
void setup() {
Serial.begin(115200);
setupDshotDMA();
}
void loop() {
uint16_t escValues[4] = {1500, 1500, 1500, 1500};
fillDshotBuffer(escValues);
writeDshot();
delayMicroseconds(150);
}
What happens in this code (as I figured out through my own debugging) is that the function writeDshot() runs once, but then on the second loop it hangs on the following line forever:
Code:
while((!b1DMAChannel.complete()));
I suspect this is something to do with the fact that I manually set b1DMAChannel as complete on line 88 in the setup function:
Code:
b1DMAChannel.TCD->CSR = DMA_TCD_CSR_DREQ | DMA_TCD_CSR_DONE;
However, it should keep looping infinitely, as the OctoWS2811 code does. Can anybody offer me clues as to what is going wrong with my code? This is for a highschool senior capstone project that is due early next week, and since I have spent the better part of a week struggling with this issue to no avail, I thought I would come here for guidance.
Many thanks,
Michael
P.S. I have included the files dshotDMA.h and dshotDMA.cpp, which contain all relevant methods. The middle function fillDshotBuffer shouldn't be an issue, since it doesn't interfere with DMA and I checked that its output is what it should be, and the last function in the file xbar_connect is a copy of the function Paul wrote for pwm.c in the Teensy 4 core files.
View attachment dshotDMA.cpp View attachment dshotDMA.h