CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

mmcsd and fat

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bessel
Guest







mmcsd and fat
PostPosted: Sun Mar 15, 2009 11:16 am     Reply with quote

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);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group