|
|
View previous topic :: View next topic |
Author |
Message |
demetrix80
Joined: 08 Jan 2010 Posts: 2 Location: Italy
|
SD card (raw mod) |
Posted: Fri Jan 08, 2010 7:55 am |
|
|
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
|
Re: SD card (raw mod) |
Posted: Fri Jan 08, 2010 9:13 am |
|
|
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
|
|
Posted: Fri Jan 08, 2010 12:46 pm |
|
|
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) |
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 . 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 |
|
|
|
|
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
|