So, this blog entry was supposed to be my first one teeming with technical expertise and new discoveries. But alas, that was not entirely the case. While I have been able to use the last week to learn a lot of new things, I have not had as much tangible results as I would like. Regardless, I would like to document what I learned/did this week to encourage this new habit of frequent documentation.
I started off this week by first setting up the Digilent Analog Discovery 2 and using the Logic Analyzer to view the data bus. I had a lot of difficulty setting up the Logic Analyzer and getting the data to show up correctly on my display. When I tried setting this up for the first time, I had a lot of difficulty getting the data to trigger correctly, and I frankly did not have too much time then to get it working. I simply used LEDs and a debugger to check my results. This time, I had much better results by trying to trigger on rising edges of clock cycles as opposed to just letting the tool auto trigger. By using this method, I was able to see the data coming out of the MOSI line correctly after triggering with the time base a little bit. Unfortunately, I have been unable to see this result while using the debugger, but that is probably my most immediate need for my projects. I am hoping that playing around with more of the trigger settings will allow me to achieve this, but I would really like an oscilloscope to make sure that I am not going crazy. The Analog Discovery 2 has a lot of sophisticated settings for the Logic Analyzer and I am just getting started with this tool, but I already see the immense potential of this equipment and I hope to use it much more frequently in the future. Frankly, using the logic analyzer might be a necessity if I hope to interface my code with other libraries.
On that note, I have been thinking quite a lot about what I want the DAQLite firmware to look like and how I will implement the actual ADC polling within the rest of my code. I was able to put some of those pieces together when I realized that if I used a DMA approach for writing to the SD card, then I can keep polling data to a buffer while I wait for the DMA transfer to happen. I decided to start working on the SPI code again because I was never able to write to the SD card; I only received acknowledgement. As of now I have been able to replicate my success by changing the transfer function to work with DMA and keeping my receive functions as a normal SPI transfer. This should be sufficient for the most part as I will only be writing large amounts of data to the SD card and not reading so heavily from it. However, I would still like to get DMA fully running for educational purposes. Unfortunately, I have been having a lot of difficulty with getting the HAL DMA Transmit Receive function working. As of now, I know that the function and its callback function are getting called but unfortunately that’s about all that seems to be working. When I use the debugger, I can see that I am receiving an acknowledgement bit back and the code is functional, but the call back is not called as I step through the code. I can, however, access the callback if I add a break point to the function and step through until I reach it. This leads me to believe that the debugger is not a reliable tool for figuring out my bugs with the DMA and I will have to rely on the Logic Analyzer.
As for contingency plans, I have thought about setting up a transmission of a dummy byte through DMA and then receiving the next byte through DMA. Functionally, this seems to be what the Transmit Receive function is doing, but I might be wrong about that. Only snooping around on the internet and through the source code will reveal that. I guess the lesson I have learned from this is that while the CubeMX tool is awesome and takes care of a lot of the dirty work for me, I cannot rely too heavily on the started code the tool generates. If I cannot get the reception DMA working in the next couple days, I plan on hoisting a white flag and moving on to the rest of the implementation. I have quite a lot of work left to do on this project, so I cannot sit around waiting for miracles to happen. Hopefully I won’t have to resort to that and I can provide more positive results for the next blog post.