I'm having some problems getting my mbed to read in data from a CMPS03 compass chip, and save it to a text (or other) file for later use - any help would be greatly appreciated, even if it turns out to be a simple mistake! The code I'm trying to use is below:
(The various LEDs are so I could try to visually see where the program was up to)
#include "mbed.h"
I2C compass(p9, p10);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
LocalFileSystem local("local");
int main() {
int address = 0xC0;
char read_cmd[2], read_result[3] = {0}, prnt_result[3] = {0};
read_cmd[0] = 2;
unsigned short data;
led1 = 1;
wait(0.5);
compass.write(address, read_cmd, 1);
wait(0.05);
compass.read(address, read_result, 2);
led2 = 1;
read_result[0] = prnt_result[2];
read_result[1] = prnt_result[1];
read_result[2] = prnt_result[0];
memcpy(&data, prnt_result, 3);
led3 = 1;
FILE *fp = fopen("/local/out.txt", "w");
fprintf(fp, "Begin Compass Log...");
led4 = 1;
fprintf(fp,"The compass data is: ");
fputs(prnt_result, fp);
fclose(fp);
led4 = 0;
}
I'm having some problems getting my mbed to read in data from a CMPS03 compass chip, and save it to a text (or other) file for later use - any help would be greatly appreciated, even if it turns out to be a simple mistake! The code I'm trying to use is below:
(The various LEDs are so I could try to visually see where the program was up to)