sd raw writing with atmega328

hello, i've been trying all weekend to get some basic SD raw write sketches working on the atmega328 upgraded diecimila. the original sd raw write library wouldnt compile under arduino 0013 (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206874649/0) , so i tried using ladyada's waveshield library as it had the sd raw libraries within it. i figured i could keep using the example code that was with the other library, as it was based on the same libraries, but i keep running into this error

In function 'int print_disk_info()': error: cannot convert 'sd_raw_info' to 'sd_raw_info*' for argument '1' to 'uint8_t sd_raw_get_info(sd_raw_info*)'Couldn't determine program size: avr-size: '/tmp/build61834.tmp/sketch_090301a.hex': No such file

anyone willing to lend a helping hand, maybe i'm just missing something obvious.

btw,

im using this code

#include <sd-reader_config.h>
#include <sd_raw.h>
#include <sd_raw_config.h>

int print_disk_info();
int sample();
int readDisk();

byte incomingByte;
void printWelcome();
long int address;
byte tempBytes[2];

void setup()
{

Serial.begin(9600);
delay(1000);

printWelcome();
if(!sd_raw_init())
{
Serial.println(“MMC/SD initialization failed”);
}
print_disk_info();
}

void loop()
{
int i;

if(Serial.available()>0)
{
incomingByte=Serial.read();

switch(incomingByte)
{
case 114:
readDisk();
break;
case 115:
sample();
break;
default:
break;
}
}
}

int sample()
{
int i,j;
int temp;
byte low;
byte high;
byte inByte;

Serial.println();
Serial.println();
Serial.println(“Sampling…”);
for(i=0;i<500;i=i+2)
{
if(Serial.available()>0)
{
inByte=Serial.read();
if(inByte==113) return 0;
}
temp=analogRead(0);
Serial.print(temp,DEC);
Serial.print(" ");

//Convert int to 2 bytes
low=temp&0xFF;
high=temp>>8;
// Serial.print(temp,DEC);
//Serial.print(low,DEC);
//Serial.print(high,DEC);

tempBytes[0]=low;
tempBytes[1]=high;

if(!sd_raw_write(i,tempBytes,2))
{
Serial.print(“Write error”);
}
//sd_raw_sync();
delay(5000);

Serial.println();

}

return 1;
}

int readDisk()
{
byte low;
byte high;
byte info[2];
int i;
int result;
Serial.println();
for(i=0;i<50;i=i+2)
{
sd_raw_read(i,info,2);

//Serial.print(info[0],DEC);
//Serial.print(" “);
//Serial.print(info[1],DEC);
low=info[0];
high=info[1];
result=high<<8;
//result<<8;
Serial.print(” “);
Serial.print(result+low,DEC);
Serial.print(” ");
}

}

void printWelcome()
{
Serial.println("------------------------");
Serial.println(“Data sampling system”);
Serial.println(“send r to read disk”);
Serial.println(“send s to start sampling”);
Serial.println(“send q to stop sampling”);
Serial.println(“Ready…”);
Serial.println("-------------------------");
}

int print_disk_info()
{

struct sd_raw_info disk_info;
if(!sd_raw_get_info(&disk_info))
{
return 0;
}

Serial.println();
Serial.print("rev: ");
Serial.print(disk_info.revision,HEX);
Serial.println();
Serial.print(“serial: 0x”);
Serial.print(disk_info.serial,HEX);
Serial.println();
Serial.print("date: ");
Serial.print(disk_info.manufacturing_month,DEC);
Serial.println();
Serial.print(disk_info.manufacturing_year,DEC);
Serial.println();
Serial.print("size: ");
Serial.print(disk_info.capacity,DEC);
Serial.println();
Serial.print("copy: ");
Serial.print(disk_info.flag_copy,DEC);
Serial.println();
Serial.print("wr.pr.: ");
Serial.print(disk_info.flag_write_protect_temp,DEC);
Serial.print(’/’);
Serial.print(disk_info.flag_write_protect,DEC);
Serial.println();
Serial.print("format: ");
Serial.print(disk_info.format,DEC);
Serial.println();
Serial.print("free: ");

return 1;
}

and this is where the waveshield library is

Audio Shield for Arduino (its under the download section)

Also in the Exhibition board is a wonderful thread about SD Cards where everything is explained in detail. The code you find there works with the 328 out of the box (aaand you have FAT!)

i suppose, i dont really need FAT support though. i've soldered the card to my board and i only need to store a couple arrays of bytes. i'll go back later today and check it out.

Hi

I've googled a lot on this problem I have also

All comes from the lib to access sd, it doesn't yet work for the 328p

We just have to wait so...

Cheers

well, i got it working. i dont know what i did. replaced the sd raw files with the ones from the ladyada library. somehow it ended up working. i cant write anything other than integers though, and its confusing keeping track of the number of bytes you write. write any less than 512 and your data stays in the buffer and is deleted after reboot.

Thanks for this library !

I've been able to look at the code. In fact this lib is based on an old version of lib of roland, and has been patched to work with 328P

in sd_raw_config.h, there's a define SD_RAW_WRITE_SUPPORT 0 I would put 1 there

Also there's a define FAT16_WRITE_SUPPORT 0 I would put 1 there maybe

But ladyada has added more function in sd_raw.c, and it's said as terrible hacks :)

and I don't see sd_raw_write() function, that's strange

Would be good if AF_Wave use the new roland lib, changes by ladyada are some kind weird...

With 4lines in the new roland lib, i can compile everything except FAT, but it wouldn't help you, i guess...

Hi again

Well now, I've been able to compile this lib in arduino 0013 I've add some code in sd_raw_config.h to make C328P work, change all *.c file into *.cpp except fat.c that doesn't compile If i rename it to fat.cpp So I've let this file with this name, and make it compile in C89 mode (this file was compiling in C99 mode and not in C89 file, I've made very minor changes)

Could you test again your example to check if it works now ?

You can dl the lib for arduino there: http://dl.free.fr/vXq9plkTF Just paste it into your hardware/libraries, and delete all *.o files to force them to be compiled again

Tell me if it works