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

SD card write use by elm chan library or anyway?

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



Joined: 21 Sep 2011
Posts: 11

View user's profile Send private message

SD card write use by elm chan library or anyway?
PostPosted: Fri Oct 07, 2011 2:00 am     Reply with quote

hi all,

My microcontroller is pic18f452.

I want to write GPS data to SD card. I read to GPS data, there isn't problem read gps data. But how can i write GPS datas to SD card.

Everybody says use to elm chan library. I look this library but this is soo complex.
http://elm-chan.org/fsw/ff/00index_e.html

How can i use to elm chan lib. Or i can use to other library, it's not different.

Thanks.
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Oct 07, 2011 2:26 am     Reply with quote

I sell an implementation of the elm library that has been ported to CCS. It comes with the full source for two sample applications including a real time data logger application with a DOS like command line demonstrating the use of the library.

Note however this is a full file system. You would use this if you wanted to exchange files between Windows (or other FAT based file systems) with a PIC.

I forgot to add, a possible better choice of PIC to use for file system type data loggers would be the PIC18F4620. It is pin compatible to the PIC18F452 but has more RAM making it better suited to supporting files systems for data acquisition, processing and logging applications.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
mcn



Joined: 21 Sep 2011
Posts: 11

View user's profile Send private message

PostPosted: Fri Oct 07, 2011 3:14 am     Reply with quote

Thanks asmallri,

But I just write opened .txt files sd card. And your price is soo much expensive for me Smile
mcn



Joined: 21 Sep 2011
Posts: 11

View user's profile Send private message

PostPosted: Fri Oct 14, 2011 6:47 am     Reply with quote

Hello again,

so, I am using this library now.

http://read.pudn.com/downloads97/sourcecode/embed/397863/SD_MMC/HDD%20Driver.c__.htm

and my code is here:

Code:

#include <18F452.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,parity=N,stop=1,ERRORS)

#use fast_io(a)
#use fast_io(c)
#define led pin_a0


#include <stdlib.h>
#include "hdd.c"

char ch;
char receive[250];
int receiveLength=0;
int k=0;
int j=0;
int x;
char ch2;
int8 uydu;
int8 rec2[100];
int reclen=0;
char data[]={"86"};


char timest[9];
char boylamst[9];

float time,boylam;

int r1,error,error0,error1;
int16 rec_no;
int16 index,rec_size;
int32 offset;
char fname[32],buff0[MMC_BUFF_SIZE+1],buff1[MMC_BUFF_SIZE+1];
char c;




void kart_init()
{

///////// init MMC ////////////////////////////////////////
error=init_MMC(1000);
if (error>0) {
output_high(pin_b5);
//goto mmc_exit;
}
output_high(pin_b6);
delay_ms(100);
output_low(pin_b6);

printf("\n\r MMC initialized \n\r");
rec_size=MMC_BUFF_SIZE;

//strcpy(fname,"HOME\\HOME.TXT");
strcpy(fname,"erb.txt");
rec_size=MMC_BUFF_SIZE;
error0=open_file(0,fname,rec_size);


//Dosyayı burda açıyor


if (error0>0) {
printf("\n\r fopen as 0 failed error=%U\n\r",error);
output_high(pin_b5);
//goto mmc_exit;
}
else printf("\n\r opened as 0 file %s with rec size %lu \n\r",fname,rec_size);
output_high(pin_b6);
delay_ms(100);
output_low(pin_b6);


}




void serilasyon()
{
while(true)
         {
            ch=getchar();
            receive[receiveLength]=ch;
            receiveLength++;         
                if(ch=='C')
               {
               break;}
               
                        }   
           
         
         
         
       
         while(true)
         {
             ch2=getchar();
                rec2[reclen]=ch2;
                reclen++;
                 if(ch2=='$')
                 {break;}
                 
                 // if(reclen==100)
                 // {break;}               
               
          }   
           
                 
         
       reclen=0;
         receiveLength=0;
}



void main()
{
setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_adc(ADC_OFF);
   setup_adc_ports(NO_ANALOGS);
   disable_interrupts(global);
   disable_interrupts(int_rda);

 set_tris_a(0x00);
 set_tris_c(0b10010011); //c7=rx I, c6=tx O, c5 SDO O,c4 SDI I
 
 output_a(0x00);
 
printf("\r\n**** GPS LOGGER **** ");
printf("\r\n");
Delay_ms(1000);
printf("\r\Now initializing SD kart  ");
printf("\r\n");
Delay_ms(3000);


SETUP_SPI (SPI_MASTER |  SPI_SS_DISABLED |SPI_H_TO_L| SPI_CLK_DIV_16 | SPI_XMIT_L_TO_H);


buff0[MMC_BUFF_SIZE]=0;
buff1[MMC_BUFF_SIZE]=0;
rec_no=0;

 
 
 
kart_init();

while(1)
{
output_toggle(led);

   serilasyon();
     
   printf("Timet:%c      ",timest);
   
   for(j=0;j<9;j++)
   {
     timest[j]=rec2[j+1]; 
      }
   time=atof(timest);
   
   printf("\r\n%f",time);
   

   error0=file_write(0,timest);


}
}


I want to write to SD card time from the GPS.I read the GPS data and i cap the time.but my problem is write to sd card.

i create the text file when SD card is connecting to computer.text file name is "erb.txt".When SD card connecting to my circuit,pic read to gps data,and sending time to serial port and write SD card.

But when i open to erb.txt on the computer,i see pic18f452 write to just last time. (for ex: 152358.02)Circuit is repeatedly write on the last data.And i just see last time data when i open the erb.txt at the computer.

I want to write all time data to sd card.

How can i solve this problem?

My connecting diagram like this:





Uploaded with ImageShack.us

[/img]
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Oct 14, 2011 7:09 am     Reply with quote

Couple of problems...

1) usually the LF series of PICs are good for 3 volt operation, so is the 18F452 you're using rated for 3 volt operation? Be sure to read the Dc characteristics section....

2) In your main program, you never attempt to write to the SD card..

3) If this is just a Proteus simulation you MUST tell us ! The schematic has several errors,so if real hardware is wired up exactly as dhown, it'll never work!

4) You've got a real mess of code 'bits' with no knowledge that they work. Perhaps where you got the library from has working test code ?
mcn



Joined: 21 Sep 2011
Posts: 11

View user's profile Send private message

PostPosted: Fri Oct 14, 2011 7:52 am     Reply with quote

temronic;
Couple of problems...

1) usually the LF series of PICs are good for 3 volt operation, so is the 18F452 you're using rated for 3 volt operation? Be sure to read the Dc characteristics section....

i use the 3.4 volt for pic,gps and max232.And working all.


2) In your main program, you never attempt to write to the SD card..


write comute is here in the while of my code: "error0=file_write(0,timest); "

3) If this is just a Proteus simulation you MUST tell us ! The schematic has several errors,so if real hardware is wired up exactly as dhown, it'll never work!

This schematic is just show.I create the real circuit and i try the real.I don't use proteus and simulation.

4) You've got a real mess of code 'bits' with no knowledge that they work. Perhaps where you got the library from has working test code ?

I got this code were library from.
[/b]
mcn



Joined: 21 Sep 2011
Posts: 11

View user's profile Send private message

PostPosted: Sun Oct 23, 2011 1:59 pm     Reply with quote

my problem is continue Confused

How can i solve this problem?
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sun Oct 23, 2011 6:35 pm     Reply with quote

Your schematic says you are running the PIC with a 10MHz crystal but your code implies 20MHz. A standard PIC18F will not run reliably at 3.4 volts at 20MHz. A 20deg C it may run, at 22 deg c it may not run. It might run on a Wednesday, but not on a Thursday etc.

There is nowhere in your code when you close the file or flush the file system buffers. If you remove a card without the file system being synchronized then data and control structures could be (and likely would be) still sitting in RAM. Removing the card prematurely can corrupt the file system on the card.

This is the same for any product implementing a FAT file system. It is why camera manufactures tell you not to remove a card that may be being written to. It is the same reason you should use device manager when removing USB flash drives from PC's and other devices.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
mcn



Joined: 21 Sep 2011
Posts: 11

View user's profile Send private message

PostPosted: Mon Oct 24, 2011 12:45 am     Reply with quote

asmallri;
I use to 20 mhz crystal on my circuit.
I understand voltage problem.

And looking my library and i can't find "close file" code?

How can i do that?
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Oct 24, 2011 12:58 am     Reply with quote

mcn wrote:
asmallri;
I use to 20 mhz crystal on my circuit.
I understand voltage problem.

And looking my library and i can't find "close file" code?

How can i do that?


Get yourself a decent library.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
mcn



Joined: 21 Sep 2011
Posts: 11

View user's profile Send private message

PostPosted: Mon Oct 24, 2011 1:14 am     Reply with quote

I understood asmallri,

Well, where can I get decent library?
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Oct 24, 2011 1:29 am     Reply with quote

mcn wrote:
I understood asmallri,

Well, where can I get decent library?


See my first post in this thread.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
mcn



Joined: 21 Sep 2011
Posts: 11

View user's profile Send private message

PostPosted: Mon Oct 24, 2011 1:33 am     Reply with quote

I know,but this cost expensive for me...
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Oct 24, 2011 7:55 am     Reply with quote

mcn wrote:
temronic;
1) usually the LF series of PICs are good for 3 volt operation, so is the 18F452 you're using rated for 3 volt operation? Be sure to read the Dc characteristics section....

i use the 3.4 volt for pic,gps and max232.And working all.
Running the PIC at lower than specified voltages is tricky, especially at the higher frequencies. So why run it at a high 20MHz when 10MHz would suffice? I think you are taking unnecessary risks.

Code:
SETUP_SPI (SPI_MASTER |  SPI_SS_DISABLED |SPI_H_TO_L| SPI_CLK_DIV_16 | SPI_XMIT_L_TO_H);
I'm surprised your SD card is doing anything as this configuration is invalid. SPI_SS_DISABLED is a slave parameter and should never be used for a SPI master. Change to:
Code:
SETUP_SPI (SPI_MASTER | SPI_H_TO_L| SPI_CLK_DIV_16 | SPI_XMIT_L_TO_H);
or, even better:
Code:
#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)

SETUP_SPI (SPI_MASTER | SPI_MODE_3 | SPI_CLK_DIV_16);


Quote:
so, I am using this library now.
http://read.pudn.com/downloads97/sourcecode/embed/397863/SD_MMC/HDD%20Driver.c__.htm
Nice find, but this is a driver with hardly any references in Google so it will be hard to find support for it. The original posting is from 2004 with the mentioning that the code is not finished and the original website is gone. Maybe not such a good choice for your project.

The cause for your file only showing the latest data has to do with the used SD library. The file_write function is strange and difficult to use. I don't understand all details but it looks like you have to specify the maximum file size in the file_open() function and then the file_write() only does an update of the entire file. So it is up to your program to collect all data in an internal buffer and write the whole file at once. Not an ideal solution. You could modify the SD library but seems to me like a waste of time to revive an old unused library.

You were asking for other SD libraries:
- Andrew's library is known to work and can be used directly with the CCS compiler. However,quality comes at a price, it is not free.
- ELM that you have found is also good, but as fas as I know no-one ever put in the effort to port it to CCS. A lot of work and quiet large for the small PIC memory.
- CCS offers a simple FAT32 library. Easy to use and free, but contains some bugs in formatting the card. Workarounds have been posted in this forum but requires some Googling to find the threads.
- The Code Library of this forum contains at least two FAT32 drivers. This might be your best bet because the code is actively supported by the users of this forum.
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