Tue Aug 11, 2015 12:01 pm
#include <petit_fatfs.h>
FATFS* fatfs;
[...]
void setup() {
gb.begin();
pf_mount(fatfs);
int ldverr=pf_open("DF01.LDV");
Tue Aug 11, 2015 12:31 pm
#include <Fat16.h>
Fat16 file;
SdCard card;
void setup() {
card.init(); //Init the SD card
file.init(&card); //Init the file system
file.open("FILE.DAT", O_READ) //Open your file
file.seekSet(0xFF); //seek a position in a file
byte d = file.read(); //Read only one byte
byte data[8];
file.read(data,8); //Read a chunk of data
}
Tue Aug 11, 2015 1:05 pm
Tue Aug 11, 2015 1:14 pm
Tue Aug 11, 2015 1:40 pm
Tue Aug 11, 2015 2:09 pm
FRESULT res; /* Petit FatFs function common result code */
[...]
/* Mount the volume */
//pf_mount(&fs);
if (res) {
Serial.println(F("File system mount failed"));
//return;
}
Tue Aug 11, 2015 2:14 pm
Tue Aug 11, 2015 2:19 pm
Tue Aug 11, 2015 2:54 pm
int a = PFFS.begin(10, rx, tx);
Tue Aug 11, 2015 2:54 pm
#include <SPI.h>
#include <petit_fatfs.h>
#include <Gamebuino.h>
FATFS fs;
FRESULT res;
WORD br;
Gamebuino gb;
void setup() {
Serial.begin(9600);
gb.begin();
spi_init();
PFFS.begin(10, rx, tx);
// There is where you can load your file:
res = pf_open("MHQ0000.DAT");
if (res) {Serial.print(F("Error !"));Serial.print(res);while (1);}
}
void spi_init()
{
pinMode(10, OUTPUT); // 10 = SS = Slave select of SD
pinMode(11, OUTPUT); // MOSI data to SD
pinMode(12, INPUT); // PB 4 - MISO data from SD
pinMode(13, OUTPUT); // SCLK
// SET HARDWARE SPI in Master & enabled
// default speed is Clock/4 = 4 Mhz which is maximum for nokia lcd
SPCR = _BV(MSTR) | _BV(SPE); // Master mode, SPI enable, clock speed MCU_XTAL/4
}
byte rx()
{
// The SPI Data Register is a read/write register
// used for data transfer between the Register File and the SPI Shift Register.
// Writing to the register initiates data transmission. Reading the register causes the Shift Register receive buffer to be read.
SPDR = 0xFF; // dummy byte to initiate reading
// loop_until_bit_is_set is an AVR libc macro
// SPSR is SPI status register, SPIF is SPI interrupt flag, that is set after transmission is complete
loop_until_bit_is_set(SPSR, SPIF);
return SPDR; //return the SPDR (= value back from slave)
}
void tx(byte d)
{
SPDR = d;
loop_until_bit_is_set(SPSR, SPIF);
}