Prop C Learn - SD Datalogger lesson - problems read/write integer
John Kauffman
Posts: 653
I'm in the C learning system http://learn.parallax.com/propeller-c-simple-devices/sd-card-data
I've modified from example: SD Datalogger.side.
I'm trying to save integers from an RCTime circuit to EEPROM. For test I am showing value measured, writing to EEPROM, reading and showing value read back. On read-back test I keep getting zeros read out to terminal and when I open in notepad I see gibberish, like the values are not lined up with ASCII codes.
I'm very suspicious of my args for the fwrite / fread lines. The "element of data" would be an integer so 4 bytes? And just one of those elements.
I'm having problems finding the documentation on this. I got as far as here but nothing on fwrite file:///C:/Users/John%20Kauffman/Documents/SimpleIDE/Learn/Simple%20Libraries/Utility/libsimpletools/Documentation%20simpletools%20Library.html
// Write to EEPROM
int DO = 22, CLK = 23, DI = 24, CS = 25; // SD card pins on Propeller BOE
sd_mount(DO, CLK, DI, CS); // Mount SD card
FILE* fp = fopen("003.txt", "w"); // Open a file for writing
fwrite(&temp, 4, 1, fp); // Add contents to the file
fclose(fp); // Close the file
// Read from EEPROM
int myOut; // var for value read out
fp = fopen("003.txt", "r"); // Reopen file for reading
fread(myOut, 4, 1, fp); // Read one int
fclose(fp); // Close the file
print(" > read: %d",myOut); // Display value
print("\n"); // With a newline at the end
Entire file attachedTempLightLogger 02.c
I've modified from example: SD Datalogger.side.
I'm trying to save integers from an RCTime circuit to EEPROM. For test I am showing value measured, writing to EEPROM, reading and showing value read back. On read-back test I keep getting zeros read out to terminal and when I open in notepad I see gibberish, like the values are not lined up with ASCII codes.
I'm very suspicious of my args for the fwrite / fread lines. The "element of data" would be an integer so 4 bytes? And just one of those elements.
I'm having problems finding the documentation on this. I got as far as here but nothing on fwrite file:///C:/Users/John%20Kauffman/Documents/SimpleIDE/Learn/Simple%20Libraries/Utility/libsimpletools/Documentation%20simpletools%20Library.html
// Write to EEPROM
int DO = 22, CLK = 23, DI = 24, CS = 25; // SD card pins on Propeller BOE
sd_mount(DO, CLK, DI, CS); // Mount SD card
FILE* fp = fopen("003.txt", "w"); // Open a file for writing
fwrite(&temp, 4, 1, fp); // Add contents to the file
fclose(fp); // Close the file
// Read from EEPROM
int myOut; // var for value read out
fp = fopen("003.txt", "r"); // Reopen file for reading
fread(myOut, 4, 1, fp); // Read one int
fclose(fp); // Close the file
print(" > read: %d",myOut); // Display value
print("\n"); // With a newline at the end
Entire file attachedTempLightLogger 02.c
Comments