added spectrometer timeout
Dependencies: SDFileSystem mbed
Fork of All_Combined_Real2 by
Diff: main.cpp
- Revision:
- 6:059312376781
- Parent:
- 5:6532c5a5f576
- Child:
- 7:a125a1fa4694
--- a/main.cpp Wed Mar 23 14:32:41 2016 +0000 +++ b/main.cpp Thu Mar 31 19:54:14 2016 +0000 @@ -7,6 +7,7 @@ #define NUM_PIXELS 2048 #define BUF_SIZE 1024 +#define SPECTROMETER_TIMEOUT 1000 // TODO make a new file (name=timestamp) each time we start recording data #define OUTPUT_FILE "/sd/data.csv" @@ -49,14 +50,20 @@ void read_pixels() { char data[NUM_PIXELS]; + int cycles_waited = 0; for (int i = 0; i < NUM_PIXELS; i++) { - - while (!pixel_rdy); - + while (!pixel_rdy) { + cycles_waited++; + if (cycles_waited > SPECTROMETER_TIMEOUT) + break; + } fifo_cs = 0; data[i] = spi.write(0x00); // write a dummy byte just to read the data fifo_cs = 1; + if (cycles_waited > SPECTROMETER_TIMEOUT) + pc.printf("timed out\r\n"); + cycles_waited = 0; } // write to file and pc @@ -68,7 +75,7 @@ pc.printf("\r\n"); fprintf(fpData, "\r\n"); fclose(fpData); - + pc.printf("here4\r\n"); XBeeSend((const char *)data, 2048); } @@ -121,20 +128,22 @@ led = !led; // gps_read(); - + pc.printf("here\r\n"); check_temp(); + pc.printf("hereagain\r\n"); // Display result pc.printf(",%s", TempCelsiusDisplay); fpData = fopen(OUTPUT_FILE, "a"); fprintf(fpData, ",%s", TempCelsiusDisplay); fclose(fpData); - // Trigger an acquisition from spectrometer + pc.printf("hereagain2\r\n"); + // Trigger an acquisition from spectrometer trigger = 1; wait_ms(1); trigger = 0; read_pixels(); - + pc.printf("hereagain3\r\n"); wait(0.5f); } } \ No newline at end of file