Reading Analog Ports and Saving in a micro SD CARD with the KL25z
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
main.cpp@26:50363a135213, 2017-08-10 (annotated)
- Committer:
- manuelmbed86
- Date:
- Thu Aug 10 18:08:02 2017 +0000
- Revision:
- 26:50363a135213
- Parent:
- 20:ec1c4f02d50e
Reading Analog Ports and Saving in a micro SD CARD with the KL25z
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
neilt6 | 0:8f2b6eed2a9d | 1 | #include "mbed.h" |
neilt6 | 0:8f2b6eed2a9d | 2 | #include "SDFileSystem.h" |
manuelmbed86 | 26:50363a135213 | 3 | #include "math.h" |
manuelmbed86 | 26:50363a135213 | 4 | |
manuelmbed86 | 26:50363a135213 | 5 | // sd card breakout board: https://www.sparkfun.com/products/544 |
manuelmbed86 | 26:50363a135213 | 6 | // |
manuelmbed86 | 26:50363a135213 | 7 | // frdm-kl25z sd card connections spi0 |
manuelmbed86 | 26:50363a135213 | 8 | // ------------------------------------------------ |
manuelmbed86 | 26:50363a135213 | 9 | // Header -- kl25z -- SPI |
manuelmbed86 | 26:50363a135213 | 10 | // J2-8 -- PTD2 -- MOSI |
manuelmbed86 | 26:50363a135213 | 11 | // J2-6 -- PTD0 -- CS |
manuelmbed86 | 26:50363a135213 | 12 | // J9-12 -- GND -- Vss (GND) |
manuelmbed86 | 26:50363a135213 | 13 | // J9-4 -- P3V3 -- Vdd (+3.3v) |
manuelmbed86 | 26:50363a135213 | 14 | // J2-12 -- PTD1 -- SCK |
manuelmbed86 | 26:50363a135213 | 15 | // J9-14 -- GND -- Vss (GND) |
manuelmbed86 | 26:50363a135213 | 16 | // J2-10 -- PTD3 -- MISO |
manuelmbed86 | 26:50363a135213 | 17 | AnalogIn ain(A0); |
manuelmbed86 | 26:50363a135213 | 18 | AnalogIn ain2(A1); |
manuelmbed86 | 26:50363a135213 | 19 | AnalogIn ain3(A2); |
manuelmbed86 | 26:50363a135213 | 20 | char buffer[3]; |
manuelmbed86 | 26:50363a135213 | 21 | int t1; |
manuelmbed86 | 26:50363a135213 | 22 | float a; |
manuelmbed86 | 26:50363a135213 | 23 | float b; |
manuelmbed86 | 26:50363a135213 | 24 | float c; |
manuelmbed86 | 26:50363a135213 | 25 | SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); // mosi, miso, sck, cs |
manuelmbed86 | 26:50363a135213 | 26 | Serial pc(USBTX,USBRX); |
manuelmbed86 | 26:50363a135213 | 27 | |
manuelmbed86 | 26:50363a135213 | 28 | int main() { |
manuelmbed86 | 26:50363a135213 | 29 | |
manuelmbed86 | 26:50363a135213 | 30 | pc.baud(115200); |
manuelmbed86 | 26:50363a135213 | 31 | pc.printf("start sd card !\r\n"); |
manuelmbed86 | 26:50363a135213 | 32 | mkdir("/sd/POF", 0777); |
manuelmbed86 | 26:50363a135213 | 33 | |
manuelmbed86 | 26:50363a135213 | 34 | FILE *fp = fopen("/sd/POF/test.txt", "w"); |
manuelmbed86 | 26:50363a135213 | 35 | if(fp == NULL) { |
manuelmbed86 | 26:50363a135213 | 36 | error("Could not open file for write\r\n"); |
neilt6 | 10:ae649a596123 | 37 | } |
manuelmbed86 | 26:50363a135213 | 38 | else |
manuelmbed86 | 26:50363a135213 | 39 | while (1){ |
manuelmbed86 | 26:50363a135213 | 40 | a=ain.read(); |
manuelmbed86 | 26:50363a135213 | 41 | b=ain2.read(); |
manuelmbed86 | 26:50363a135213 | 42 | c=ain3.read(); |
manuelmbed86 | 26:50363a135213 | 43 | wait(0.0050); |
manuelmbed86 | 26:50363a135213 | 44 | fprintf(fp,"%0.3f, %0.3f,%0.3f\n",a, b,c ); |
neilt6 | 0:8f2b6eed2a9d | 45 | } |
manuelmbed86 | 26:50363a135213 | 46 | |
manuelmbed86 | 26:50363a135213 | 47 | fclose(fp); |
manuelmbed86 | 26:50363a135213 | 48 | |
manuelmbed86 | 26:50363a135213 | 49 | } |