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 support@ccsinfo.com

mk_file was not working (very urgent, please respond mail)

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



Joined: 11 Aug 2011
Posts: 3

View user's profile Send private message

mk_file was not working (very urgent, please respond mail)
PostPosted: Sat Aug 13, 2011 9:42 am     Reply with quote

Hi all,

I'm working on pic18f67j10 microcontroller, ccs compiler version is 4.121.
I'm working on memory module for storing log data but when I'm calling mk-file, it was continuously in while loop in get_next_free_entry function.
Code:

mk_file->set_file_name->get_next_free_entry


signed int get_next_free_entry(int32* start_addr)
{
   int buf;

   int32 i;

   i = *start_addr;

   if(mmcsd_read_data(i, 1, &buf) != GOODEC)
     return EOF;

   while(buf != 0)
   {
      i += 0x1F;
      // get the next address
      if(get_next_addr(&i) == EOF)
         if(alloc_clusters(addr_to_cluster(i), &i) == EOF)
            return EOF;

      if(mmcsd_read_data(i, 1, &buf) != GOODEC)
        return EOF;
   }

   *start_addr = i;

   return GOODEC;
}

Thanks Smile
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat Aug 13, 2011 9:44 pm     Reply with quote

If you're using the MMC/SD library bundled with the CCS compiler, there is a bug in the get_next_addr function that might be your problem. See my thread:

http://www.ccsinfo.com/forum/viewtopic.php?t=43417

BTW, it doesn't matter how urgent you think your problem is, no one is going to email you.
_________________
Andrew
ranga_ccs



Joined: 11 Aug 2011
Posts: 3

View user's profile Send private message

PostPosted: Fri Aug 19, 2011 1:40 am     Reply with quote

Thanks andrewg for your response.
I checked the link you have forwarded but I'm using updated fat and mmcsd drivers only. Still the problem was not resolved.
Can I know, what are the initial initialization steps we need to follow for mmcsd and fat system when we are using PIC18F67J10, oscillator=8M, clock=32M ?
The following initialization steps I had done in my code.
Code:

#include <18F67J10.h>
#device  ICD=TRUE
#device  adc=8

#FUSES   NOWDT                    //No Watch Dog Timer
#FUSES   WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES   HS   //High speed Osc (> 4mhz for PCM/PCH) (>10mhz forPCD)
#FUSES   DEBUG                    //Debug mode for use with ICD
#FUSES   NOXINST                  //Extended set extension and Indexed
#FUSES   STVREN                   //Stack full/underflow will cause reset
#FUSES   NOPROTECT                //Code not protected from reading
#FUSES   FCMEN                    //Fail-safe clock monitor enabled
#FUSES   IESO                     //Internal External Switch Over mode enabled

#use delay(oscillator=8M,clock=32M)

//UART CONFIGURATIONS
#use rs232(baud=4800,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=U1)
#use rs232(baud=9600,parity=N,xmit=PIN_G1,rcv=PIN_G2,bits=8,stream=U2)

/******************************SD CARD ******************************/

#ifndef MMCSD_PIN_SCL

#define MMCSD_PIN_SCL     PIN_D6 //o
#define MMCSD_PIN_SDI     PIN_D5 //i
#define MMCSD_PIN_SDO     PIN_D4 //o
#define MMCSD_PIN_SELECT  PIN_D7 //o

#endif

#use spi(SPI2, MODE=0, BAUD=3000000, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, IDLE=1, SAMPLE_RISE, stream=mmcsd_spi)
 

Can I know if anyone faced like this problem, please give us some direction.

Thanks Smile
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Sun Aug 21, 2011 6:23 am     Reply with quote

Your #use spi line is completely wrong. Get rid of it. Just #include mmcsd.c after the MMCSD pin definitions and see how that goes.
_________________
Andrew
ranga_ccs



Joined: 11 Aug 2011
Posts: 3

View user's profile Send private message

File was not creating in SD card .
PostPosted: Thu Aug 25, 2011 9:42 am     Reply with quote

Hi Andrewg,
I removed #use spi and I already included mmcsd.h file but the problem was not resolved.

I’m not able to create file and directories in my MMCSD memory card by using fat and mmcsd drivers of CCS compiler. I'm calling mk_file function(fat driver function) in config_file_open()function in my source code(memory_fat.c). mk_file was returning 0xFF value but it has to return 0x00 if it was successfully completed.
With my understanding mk_file was getting 0xff value from mk_file ->set_file_name ->make_short_file_name function.

Sometimes it was continuously waiting in the mk_file ->set_file_name -> get_next_free_entry function.

I copied my main part of source code and header file:

source code:
Code:

int config_file_open()
{
        int i,k=0;
        int k1=0;
        int config_init=99;
        int config_mkfile=2;
        int config_openfile=90;
        int config_readfile=77;
        char wcmd[2] = "r";
        for(i=0;i<50;i++)
          {
              temp_buff[i]='\0';   
          }
        k=0;   
        while((config_init != 0)&&(k<3))
        {
                config_init = fat_init();                  //init the fat32 file system
                k++;
        }
        if(config_init != 0)
                return 0;                          //On fail return 0
 
        strcpy(temp_buff,"/config.txt");
        k=0;
        while((config_mkfile != 0)&&(k<3)) 
        {
                config_mkfile = mk_file(temp_buff);                     //Create empty file
                k++;
        }
}


Header file:

Code:

#include <18F67J10.h>

#device  ICD=TRUE
#device  adc=8

#FUSES   NOWDT                    //No Watch Dog Timer
#FUSES   WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES   HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES   DEBUG                    //Debug mode for use with ICD
#FUSES   NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES   STVREN                   //Stack full/underflow will cause reset
#FUSES   NOPROTECT                //Code not protected from reading
#FUSES   FCMEN                    //Fail-safe clock monitor enabled
#FUSES   IESO                     //Internal External Switch Over mode enabled


//#use delay(clock=8000000)
#use delay(oscillator=8Mhz,clock=32Mhz)
//UART CONFIGURATIONS
#use rs232(baud=4800,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=U1)
#use rs232(baud=9600,parity=N,xmit=PIN_G1,rcv=PIN_G2,bits=8,stream=U2)

/******************************SD CARD ******************************/

#ifndef MMCSD_PIN_SCL

#define MMCSD_PIN_SCL     PIN_D6 //o
#define MMCSD_PIN_SDI     PIN_D5 //i
#define MMCSD_PIN_SDO     PIN_D4 //o
#define MMCSD_PIN_SELECT  PIN_D7 //o

#endif

Please give us some direction on this.

Thanks
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Thu Aug 25, 2011 10:28 pm     Reply with quote

Run chkdsk on the card to make sure there's no obvious detectable errors on it. Apart from that, you're going to have to trace through the code to the point where it's getting stuck.

It's possible there's a bug in the drivers. I've not used the drivers for writing (yet).

If you don't want to debug the CCS drivers, then you'll have to try some other drivers. Lots of people here (but not me) have used the drivers from Brush Electronics ( http://www.brushelectronics.com/ ).

One day I'll get around to trying out the writing code, but not for a while.
_________________
Andrew
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