This is doing my head RIGHT IN...
I have a program which scans the I2C bus at setup and creates an array of the valid MLX90614 temp sensors so later on it only scans the ones that were detected at startup.
This worked great until I integrated some code which opens a couple of files on SDcard to log both the complete raw data, and the laptimes (also calculated by the program).
What's happening is that before opening either log file, the array is fine, and the code works great. After opening the first LOG file, the array is fine and the code works normally. after opening the second file however, the array is all stamped on and full of garbage.
This is the relevant snippet of code. All this does is open 2 files, and prints out the contents of the valid I2C array after the first and second file opens. The data below (26,27,28,42,43,44) is valid, the second set (69, 83, 46, 116, 120, 116) is garbage.
And this is the troubleshooting printout...
I'm using a Teensy 3.5 and I don't seem to be using anything like all the memory...
Using SdFat.h
It looks like something is stomping on memory - is there anything I can do to verify this or trace why the second file open is doing it (NOT the first!)
Cheers - Neil G
I have a program which scans the I2C bus at setup and creates an array of the valid MLX90614 temp sensors so later on it only scans the ones that were detected at startup.
This worked great until I integrated some code which opens a couple of files on SDcard to log both the complete raw data, and the laptimes (also calculated by the program).
What's happening is that before opening either log file, the array is fine, and the code works great. After opening the first LOG file, the array is fine and the code works normally. after opening the second file however, the array is all stamped on and full of garbage.
This is the relevant snippet of code. All this does is open 2 files, and prints out the contents of the valid I2C array after the first and second file opens. The data below (26,27,28,42,43,44) is valid, the second set (69, 83, 46, 116, 120, 116) is garbage.
Code:
byte readsensors[64];
{snip}
sprintf(filename, "%02u%02u%02u-%02u%02u%02u.txt", fix_data.dateTime.year, fix_data.dateTime.month, fix_data.dateTime.date, fix_data.dateTime.hours, fix_data.dateTime.minutes, fix_data.dateTime.seconds);
if (logFile.open(filename, O_CREAT | O_WRITE | O_EXCL)) {
logFile.println(F("Time;Distance;Lap;Brake;Throttle;Gear;RPM;KPH;KPHGPS;Heading;Roll;Pitch;Temp;Latitude;Longitude"));
DEBUG_PORT.print(" Creating log file : ");
DEBUG_PORT.println(filename);
} else {
initerror();
}
DEBUG_PORT.println("After LOG file opens");
debugloop = 0;
while (debugloop < nMLXdevices) {
DEBUG_PORT.print(debugloop); DEBUG_PORT.print(" : "); DEBUG_PORT.println(readsensors[debugloop]);
debugloop++;
}
sprintf(filename, "%02u%02u%02u-%02u%02u%02u-LAPTIMES.txt", fix_data.dateTime.year, fix_data.dateTime.month, fix_data.dateTime.date, fix_data.dateTime.hours, fix_data.dateTime.minutes, fix_data.dateTime.seconds);
if (lapFile.open(filename, O_CREAT | O_WRITE | O_EXCL)) {
lapFile.println(F("Lap;Time"));
DEBUG_PORT.print(" Creating laptime file : ");
DEBUG_PORT.println(filename);
} else {
initerror();
}
DEBUG_PORT.println("After LAP file opens");
debugloop = 0;
while (debugloop < nMLXdevices) {
DEBUG_PORT.print(debugloop); DEBUG_PORT.print(" : "); DEBUG_PORT.println(readsensors[debugloop]);
debugloop++;
}
And this is the troubleshooting printout...
Code:
Laptimer started
Ruapuna : -435307000 : 1724808240 : -435304940 : 1724809940 : -436153118 : 1723706322 : 12.94
DunlopLoop : -436151360 : 1723713960 : -436152110 : 1723714710 : -436153118 : 1723706322 : 0.06
Creating log file : 171231-042259.txt
After LOG file opens
0 : 26
1 : 27
2 : 28
3 : 42
4 : 43
5 : 44
Creating laptime file : 171231-042259-LAPTIMES.txt
After LAP file opens
0 : 69
1 : 83
2 : 46
3 : 116
4 : 120
5 : 116
568009379.40,0.099,0,2,185.7,-43.x,172.y,52.10,7,4,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,26.11,25.23,24.17,0.00,33.79,33.91,27.25,0.00
568009379.60,0.232,0,1,0.0,-43.x,172.y,0.00,0,3,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,26.11,25.23,24.17,0.00,33.79,33.91,27.25,0.00
I'm using a Teensy 3.5 and I don't seem to be using anything like all the memory...
Code:
Sketch uses 68696 bytes (13%) of program storage space. Maximum is 524288 bytes.
Global variables use 10404 bytes (5%) of dynamic memory, leaving 186204 bytes for local variables. Maximum is 196608 bytes.
Using SdFat.h
It looks like something is stomping on memory - is there anything I can do to verify this or trace why the second file open is doing it (NOT the first!)
Cheers - Neil G