bessel Guest
|
mmcsd and fat |
Posted: Sun Mar 15, 2009 11:16 am |
|
|
Good morning
I use mmcsd and fat with pic18F4550 (compiler CCS 4.084).
My example work with proteus (read and write fat16 and fat32).
With the card I can read one file (fat16) on the root.
The function open_fat is working and create the file,
but the function write is bad.
I have the error code in the function:
Quote: | fatwrite--->fatputc--->clear_cluster(int32 cluster)--->mmcsd_write_data----->mmcsd_write_byte |
Code: |
MMCSD_err mmcsd_write_byte(int32 addr, char data)
{
MMCSD_err ec;
ec = mmcsd_move_buffer(addr);
if(ec != MMCSD_GOODEC)
return ec; the code error is here the adress is addr= 0x00061000 |
I have one SDCARD 1GB Sandisk
The example program is
Code: |
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,DEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#use rs232(baud=9600, bits=8, parity = N, xmit=PIN_C6, rcv=PIN_C0)
#USE FAST_IO(A)
#USE FAST_IO(B)
#USE FAST_IO(C)
#USE FAST_IO(D)
#USE FAST_IO(E)
#include <stdlib.h> // for atoi32
#include "mmcsd2p.c"
#define FAT16
#include "fatp.c"
#define LED PIN_D5
#define LED1 PIN_D6
#define LED_OFF output_low
#define LED_ON output_high
#define COMMAND_SIZE 10
#define NUM_COMMANDS 11
#DEFINE _CS PIN_C2
char g_CWD[200] = "/"; //current working directory
void main(void)
{
char bufferin[20]="bonjour laure";
char bufferout[20];
char *cmd, *option1, *option2;
FILE stream;
int i,a; // pointer to the buffer
set_tris_d(0x00);
LED_OFF(LED);
LED_OFF(LED1);
set_tris_c(0b00000001); //c7=rx I, c6=tx O, c5 SDO O,c4 SDI I
set_tris_b(0b11100001);
output_high(_CS);
setup_spi(SPI_MASTER | SPI_CLK_DIV_4 | SPI_H_TO_L |SPI_XMIT_L_TO_H );
if (( i = fat_init())==0)printf("\r\n\nINITIALIZING FAT\r\n\n");
setup_spi(SPI_MASTER | SPI_CLK_DIV_16 | SPI_H_TO_L |SPI_XMIT_L_TO_H );
i = mk_file("/tata.txt");
i = fatopen("/tata.txt", "w", &stream);
i = mk_dir("/essai1/");
i=fatwrite(bufferin,1, 10, &stream);
i=fatclose(&stream);
if (( i = fatopen("/toto.txt", "r", &stream))==0)printf("\r\n\ouverture fichier1\r\n");
if (( i = fatread(bufferout,1, 10, &stream))>0)printf("\r\n\lecture fichier1\r\n");
if (( i=fatclose(&stream))==0) printf("\r\n\fermeture fichier1\r\n");
while(1);
} |
|
|