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

SD card (raw mod)

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



Joined: 08 Jan 2010
Posts: 2
Location: Italy

View user's profile Send private message

SD card (raw mod)
PostPosted: Fri Jan 08, 2010 7:55 am     Reply with quote

Hi to all,
I'm an Italian student. I'm working to a project for my electronic engineering thesis. I must store every data string that I get to a sd card. I use the sd card as a storage memory (raw), therefore I think that no is necessary to use Fat16 or 32 system (is correct?).
I make an example: I included the mmcsd.c driver and I used the mmcsd_write_byte for storage a character. After, I read this character with mmcsd_read_byte and I receive the data correctly. A this point I tryed to store a character string of 10 byte using the function mmcsd_write_data(a, n, p), but when I try to receive the data with mmcsd_read_data, I receive nothing.

Please you can help me?

Best regards
Demetrio
ckielstra



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

View user's profile Send private message

Re: SD card (raw mod)
PostPosted: Fri Jan 08, 2010 9:13 am     Reply with quote

demetrix80 wrote:
I must store every data string that I get to a sd card. I use the sd card as a storage memory (raw), therefore I think that no is necessary to use Fat16 or 32 system (is correct?).
Yes, this is correct, you can do without a file system.

For the problems in storing and reading of the string data I don't know without further information. A possible problem could be the third parameter, check this to be a pointer.

If you don't know how to solve the problem it is best when you post a small program demonstrating your problem. Make the program small, max. 20 lines, and post the complete program including #fuses so we can copy/paste it directly in our compiler.
demetrix80



Joined: 08 Jan 2010
Posts: 2
Location: Italy

View user's profile Send private message

PostPosted: Fri Jan 08, 2010 12:46 pm     Reply with quote

Hi ckielstra, thanks for reply.
The code for test the sd write/read is below:
Code:

#include "C:\Users\Demetrio\Documents\PIC-C\sd card\sd.h"
  #include <float.h>
  #include <math.h>
  #include <stdio.h>
  #include <string.h>
  #include <mmcsd.c>

void main()
{
   int32 address=0;
   int16 b;
   char *dato="Test";
   char *rec;
 
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_16);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);
   mmcsd_init();

   // TODO: USER CODE!!

while(true)
{
  b=strlen(dato);
 
  mmcsd_write_data(address, b, dato);
 
  delay_ms(1000);

  mmcsd_read_data(address, b, &car);
 
  printf("%s\n\r", *car);

  delay_ms(1000);
}

}

The fuses is:
Code:

#include <18F4455.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV21                   //Brownout reset at 2.1V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL12                    //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4                  //System Clock by 4
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES VREGEN                   //USB voltage regulator enabled
#FUSES ICPRT                    //ICPRT enabled

#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

Idea I've resolved using a "for" cicle, reading every single character, with mmcsd_read_byte function, and copying into a string, but this not the best solution Rolling Eyes . Ideally use the mmcsd_read_data.
Follow my solution:
Code:

for (i=0; i<=b; i++)
  {
    a=address+i;
    mmcsd_read_byte(a, &rec);
    car[i]=rec;
  }
 
  car[i+1]='\0';

  printf("%s\n\r", car);

Best regards
Demetrio
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