I have built a robot with an Axon II microcontroller and several other components built on a LEGO chassis. Here is a pic of the bot:
http://home.fossilfolk.com/_/rsrc/1341900528772/home/mike/mikerobot.jpg I am testing out an sd card to store matrices for a mapping program that I am working on. The program I am using is just an sd card test. (the code is ugly) The robot will make folders and files and output, but it will not read text (even text that the robot itself outputted) into a string or char[].
I expect it to make two files, one with " Text Into A File! 123abc " and one with "Text Into ". The first one works, the other one is always blank. I have tried letting it read RTTTL files and play them but it won't read anything into the char[].
Here is my code:
#include "sys/axon2.h"
#include "Storage/sdCard.h"
#include "Storage/FileSystem/FAT.h"
#include "rprintf.h"
#include "spi.h"
#include "spisw.h"
#include "tone.h" //L5 is tone pin
#define MOSI B2
#define MISO B3
#define SCLK B1
#define CS L0
SD_CARD card = MAKE_SD_CARD(CS); //miso- orange, mosi- grey, clk- white, green L0, red 3.3+, arrows align.
SPI_DEVICE_LIST devices[] = { &card._device_};
SPI sd_spi = MAKE_SPI(devices);
DISK disk;
FILE test_file;
boolean written = 0;
boolean initRslt;
TONE_PLAYER testTone = MAKE_TONE_PLAYER(TIMER1, L5);
void appInitHardware(void)
{
spiBusInit(&sd_spi,1);
initRslt = sdCardInit(&card);
diskInit(&disk, 10, sdCardGetStorageClass(), &card);
segled_put_char(&led_display, 'A');
}
TICK_COUNT appInitSoftware(TICK_COUNT loopStart)
{
segled_put_char(&led_display, 'B');
rprintfInit(fileGetWriter(&test_file));
return 0;
}
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart)
{
string tune;
if (!initRslt)
segled_put_char(&led_display, 'o');
if(written)
{
return 500000;
}
diskMkdir(&disk, "test_folder");
fileOpen(&disk, &test_file, "/test_folder/test_file.txt", 'r');
fileReadNext(&test_file, 10, tune);
fileClose(&test_file);
segled_put_char(&led_display, 'C');
fileOpen(&disk, &test_file, "/test_folder/test2_file.txt", 'w');
rprintfStr(tune);
fileClose(&test_file);
tonePlay(&testTone, 1568, 200);//high G
clockWaitms(200);
written = 1;
return 1000;
}