Dear all,
Thanks for reading this topic and maybe helping me by solving my problem.
Short introduction
I'm working on a device to test some filter units. I think I'm quite near to the goal of this project, but this time some very bad things happen when running the program. After hours and hours of googling (around 30 hours) I still didn't find anything, so there are two possible reasons why I can't find an answer:
- It's a very stupid problem and will not see the answer
- It's a very uncommon problem and because of this I can't find anything.
It’s the first program of mine, which has such a big size, so everything is quite new for me, and I will be also pleased about other feedbacks of to this program.
What the program should do
I will run filters for a long term test and figure out its capacity. Therefore I run the device for a long term test by using defined dirt water. At the end there should be several tests on the same test bench, but now I only will test one. So something in the program are prepared to multiple tests at the time and something needs to get updated later.
Environment
I’m using the IDE version 1.6.5 combined with Notepad++ as external editor. The TFT-display and the SD card reader are the here shown device.
I use several tabs, for each subtask is one tab, for the special types (my own structs) and also one for all #defines . Some of this tasks are still empty, these aren’t implemented yet, but will follow soon. Further I’ve build my own class, FilterDummy. The “Dummy” is because it only returns random values this time for testing the software. I’m using an Arduino due.
Structure of the program
The program starts and do the following steps:
- Initialize some variables
- Initialize port 13, sometimes I use it for debugging
- Initialize the serial communication
- Initialize SPI for TFT-screen
- Initialize a que for events (later more)
- Initialize the TFT-screen (by running it’s routine the first time)
- Initialize the file system (figure out the number of the current test and generate new folder)
- Initialize all Interrupts
- Set the analogreadresolution to the maximum
- Initialize my array of objects from filterunits
After the initialization every interrupt just generate a short event (eg. Increase a count or add an event to my que of events). Every 0.1 s it refreshes the display if the que is empty. The program is only controlled by interrupts and the resulting events (and the periodically refreshment of the screen).
There are several finite state machines (FSM) for controlling the different states. One for the display states and one for the events.
My problem
When initializing the file system the program checks if the file “ReadMe.txt” exists, if not it generate a new one. In this file is a ongoing number for the current test (so the program will not overwrite the last test). If it exists, the program reads the number of the next test, increase the number in the file, and close it. A folder is generated with the number of the next test and a .csv file in it for each filter unit, which I like to check. So far the program works perfectly, the display shows the state, the files are made. Now the initialization of the filter is done, and the files should be extended. In the example I try to make new files, after pressing the green button in the state “START_SCREEN” (or even to open an existing file). This happens in the routine “void writeTestValue()”. Here fails the program. I weren’t able to figure out what’s the reason for this. I spent so much time, tried all things I read in the internet but was not able to figure out the problem. I saw that the files get initialized well the first time when running the SD library (also increasing the number, opening files and generating new files)
The code
Bellow I’ve attached the whole program including the following things:
- All tabs of the IDE
- The Output on the SD card, when restarting the program twice
- The oscilosope screens (later more)
The code of the problematic routine is on the first post in the Topic (see note on bottom)
Some reasons
While looking for a solution I also analyzed the output of the SPI-interface on a oscilloscope. And I saw that there are two different situations:
-
Situation:
While initializing the SD.open() works perfectly, chip gets selected and read/write-access is done fine. the Here is the screen from the oscilloscope. The channels are the following:
A: CS of SD-Card, Blue
B: CS of TFT-screen, Red
C: MOSI, Green
D: MISO, Brown
The trigger goes to the falling edge of CS from the SD-Card. -
Situation:
After the setup routine by pressing the green button it should generate or open some files, here is a problem. The SPI interface will not communicate with the SD-Card, but I did everthing the same way like in the first sitatione, expected initializing the SD-card (by using SD.begin(PIN_CS_SD) ). I set Pin 13 to High, when entering the routing so it’s clearly visible in which timespan the routine is working (I added a little delayMicroseconds at the end. Here is the second screen shown.
A: CS of SD-Card, Blue
B: Pin 13, Red
C: MOSI, Green
D: MISO, Brown
Some conclusions
- The wiring should be correct, it works fine the first time
- I think the problem is in the file “FileSystem.Ino” or in the file “currentVersion.ino”
- Once I exclude the TFT-library (and commenting all this things out) and it still doesn’t work, so I conclude that it shouldn’t be a problem between this two different usages of the SPI-interface.
Thanks for reading this post, I would be really thankfull if someone knows the answer. I hope I haven’t overseen something while use google and the search functions, otherwise I will appologice for doing my investigations not properly.
Many Thanks and best regards
Jérôme
For a shortern reading (whithout downloading the whole code) I add the code to the first post in this Topic. By adding the code to this post, the lenght will exceed the maximal lenght for a post
AllFiles.zip (16.4 KB)