| @@ -95,7 +95,7 @@ const uint8_t BUFFER_BLOCK_COUNT = 12; | |||
| // Temporary log file. Will be deleted if a reset or power failure occurs. | |||
| #define TMP_FILE_NAME "tmp_log.bin" | |||
| // Size of file base name. Must not be larger than six. | |||
| // Size of file base name. | |||
| const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1; | |||
| const uint8_t FILE_NAME_DIM = BASE_NAME_SIZE + 7; | |||
| char binName[FILE_NAME_DIM] = FILE_BASE_NAME "00.bin"; | |||
| @@ -550,13 +550,19 @@ void setup(void) { | |||
| if (sizeof(block_t) != 512) { | |||
| error("Invalid block size"); | |||
| } | |||
| // Allow userSetup access to SPI bus. | |||
| pinMode(SD_CS_PIN, OUTPUT); | |||
| digitalWrite(SD_CS_PIN, HIGH); | |||
| // Setup sensors. | |||
| userSetup(); | |||
| // Initialize at the highest speed supported by the board that is | |||
| // not over 50 MHz. Try a lower speed if SPI errors occur. | |||
| if (!sd.begin(SD_CS_PIN, SD_SCK_MHZ(50))) { | |||
| sd.initErrorPrint(&Serial); | |||
| fatalBlink(); | |||
| } | |||
| userSetup(); | |||
| } | |||
| //------------------------------------------------------------------------------ | |||
| void loop(void) { | |||
| @@ -2,7 +2,7 @@ | |||
| // User data functions. Modify these functions for your data items. | |||
| // Start time for data | |||
| uint32_t startTime; | |||
| static uint32_t startMicros; | |||
| // Acquire a data record. | |||
| void acquireData(data_t* data) { | |||
| @@ -14,10 +14,10 @@ void acquireData(data_t* data) { | |||
| // Print a data record. | |||
| void printData(Print* pr, data_t* data) { | |||
| if (startTime == 0) { | |||
| startTime = data->time; | |||
| if (startMicros == 0) { | |||
| startMicros = data->time; | |||
| } | |||
| pr->print(data->time - startTime); | |||
| pr->print(data->time - startMicros); | |||
| for (int i = 0; i < ADC_DIM; i++) { | |||
| pr->write(','); | |||
| pr->print(data->adc[i]); | |||
| @@ -27,7 +27,7 @@ void printData(Print* pr, data_t* data) { | |||
| // Print data header. | |||
| void printHeader(Print* pr) { | |||
| startTime = 0; | |||
| startMicros = 0; | |||
| pr->print(F("micros")); | |||
| for (int i = 0; i < ADC_DIM; i++) { | |||
| pr->print(F(",adc")); | |||
| @@ -5,8 +5,8 @@ | |||
| #define FILE_BASE_NAME "adc4pin" | |||
| const uint8_t ADC_DIM = 4; | |||
| struct data_t { | |||
| unsigned long time; | |||
| unsigned short adc[ADC_DIM]; | |||
| uint32_t time; | |||
| uint16_t adc[ADC_DIM]; | |||
| }; | |||
| void acquireData(data_t* data); | |||
| void printData(Print* pr, data_t* data); | |||
| @@ -95,7 +95,7 @@ const uint8_t BUFFER_BLOCK_COUNT = 12; | |||
| // Temporary log file. Will be deleted if a reset or power failure occurs. | |||
| #define TMP_FILE_NAME "tmp_log.bin" | |||
| // Size of file base name. Must not be larger than six. | |||
| // Size of file base name. | |||
| const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1; | |||
| const uint8_t FILE_NAME_DIM = BASE_NAME_SIZE + 7; | |||
| char binName[FILE_NAME_DIM] = FILE_BASE_NAME "00.bin"; | |||
| @@ -550,13 +550,19 @@ void setup(void) { | |||
| if (sizeof(block_t) != 512) { | |||
| error("Invalid block size"); | |||
| } | |||
| // Allow userSetup access to SPI bus. | |||
| pinMode(SD_CS_PIN, OUTPUT); | |||
| digitalWrite(SD_CS_PIN, HIGH); | |||
| // Setup sensors. | |||
| userSetup(); | |||
| // Initialize at the highest speed supported by the board that is | |||
| // not over 50 MHz. Try a lower speed if SPI errors occur. | |||
| if (!sd.begin(SD_CS_PIN, SD_SCK_MHZ(50))) { | |||
| sd.initErrorPrint(&Serial); | |||
| fatalBlink(); | |||
| } | |||
| userSetup(); | |||
| } | |||
| //------------------------------------------------------------------------------ | |||
| void loop(void) { | |||
| @@ -16,10 +16,13 @@ const uint8_t DATAZ0 = 0x36; //Z-Axis Data 0 | |||
| const uint8_t DATAZ1 = 0x37; //Z-Axis Data 1 | |||
| void writeADXL345Register(const uint8_t registerAddress, const uint8_t value) { | |||
| // Max SPI clock frequency is 5 MHz with CPOL = 1 and CPHA = 1. | |||
| SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE3)); | |||
| digitalWrite(ADXL345_CS, LOW); | |||
| SPI.transfer(registerAddress); | |||
| SPI.transfer(value); | |||
| digitalWrite(ADXL345_CS, HIGH); | |||
| SPI.endTransaction(); | |||
| } | |||
| void userSetup() { | |||
| @@ -7,7 +7,7 @@ | |||
| // User data types. Modify for your data items. | |||
| const uint8_t ACCEL_DIM = 3; | |||
| struct data_t { | |||
| unsigned long time; | |||
| uint32_t time; | |||
| int16_t accel[ACCEL_DIM]; | |||
| }; | |||
| void acquireData(data_t* data); | |||
| @@ -50,7 +50,7 @@ const uint8_t SD_CS_PIN = SS; | |||
| #ifdef ERROR_LED_PIN | |||
| #undef ERROR_LED_PIN | |||
| #endif // ERROR_LED_PIN | |||
| const int8_t ERROR_LED_PIN = 3; | |||
| const int8_t ERROR_LED_PIN = -1; | |||
| //------------------------------------------------------------------------------ | |||
| // File definitions. | |||
| // | |||
| @@ -95,7 +95,7 @@ const uint8_t BUFFER_BLOCK_COUNT = 12; | |||
| // Temporary log file. Will be deleted if a reset or power failure occurs. | |||
| #define TMP_FILE_NAME "tmp_log.bin" | |||
| // Size of file base name. Must not be larger than six. | |||
| // Size of file base name. | |||
| const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1; | |||
| const uint8_t FILE_NAME_DIM = BASE_NAME_SIZE + 7; | |||
| char binName[FILE_NAME_DIM] = FILE_BASE_NAME "00.bin"; | |||
| @@ -550,13 +550,19 @@ void setup(void) { | |||
| if (sizeof(block_t) != 512) { | |||
| error("Invalid block size"); | |||
| } | |||
| // Allow userSetup access to SPI bus. | |||
| pinMode(SD_CS_PIN, OUTPUT); | |||
| digitalWrite(SD_CS_PIN, HIGH); | |||
| // Setup sensors. | |||
| userSetup(); | |||
| // Initialize at the highest speed supported by the board that is | |||
| // not over 50 MHz. Try a lower speed if SPI errors occur. | |||
| if (!sd.begin(SD_CS_PIN, SD_SCK_MHZ(50))) { | |||
| sd.initErrorPrint(&Serial); | |||
| fatalBlink(); | |||
| } | |||
| userSetup(); | |||
| } | |||
| //------------------------------------------------------------------------------ | |||
| void loop(void) { | |||