View previous topic :: View next topic |
Author |
Message |
matt1971
Joined: 26 Oct 2008 Posts: 15
|
SD Card / FAT offset question |
Posted: Fri Oct 31, 2008 8:40 pm |
|
|
I have an SD card, formatted FAT16 on a PC. I'm just doing some tests on read/writes to it and one of the tests is to find the volume name on the card.
When I search for the volume name ('MYDATA') on the PC with winhex, it comes back at offset 249856. Yet when I sequentially search the SD card on the pic, it comes back at offset 377344.
Should the two offsets be the same, or am I missing something? |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Fri Oct 31, 2008 9:39 pm |
|
|
The keyword here is offset. Offset with respect to what?
The PIC may well be offset from physical sector 0 (i.e the real sector) and the other could be an offset from the partition or from the end of the directory structure. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
![](templates/subSilver/images/spacer.gif) |
matt1971
Joined: 26 Oct 2008 Posts: 15
|
|
Posted: Sat Nov 01, 2008 4:49 am |
|
|
Well, if I read from the SD card using mmcsd_read_data, my offset is an int32 based value, starting at 0. When I use this function and read the first 5 bytes I get :
EB 58 90 4D 53 44 4F 53 35
When I look at the first 5 bytes in hexedit, I get :
EB 3C 90 4D 53 44 4F 53 35
So I assume the "offset" in both cases is the same, since the data is more or less the same. But doing this experiment shows that the values I read are not exactly the same, which points to some sort of problem with mmcsd.c.
My test program is :
Code: |
#include <18F4685.h>
#fuses NOWDT, HS, NOPROTECT
#use delay(clock=20M)
#use rs232(baud=9600, UART1)
//media library, a compatable media library is required for FAT.
#use fast_io(c)
#define MMCSD_PIN_SCL PIN_C3 //o
#define MMCSD_PIN_SDI PIN_C4 //i org PIN_C4
#define MMCSD_PIN_SDO PIN_C5 //o org PIN_C5
#define MMCSD_PIN_SELECT PIN_C2 //o org PIN_C2
#include <mmcsd.c>
#include "lcd_driver.h"
void main(void)
{
int32 i = 0;
char data;
// Initialise LCD
lcd_init();
// Initialise the SD lib
mmcsd_init();
printf(lcd_putc, "Data : ");
for (i=0; i < 10; i++) {
mmcsd_read_byte(i, &data);
printf(lcd_putc, "%X,", data);
}
while(1);
}
|
This is for a PIC18F4685, CCS 4.057. I know my compiler is quite old now, have there been significant changes to mmcsd.c between .057 and .082 ? |
|
![](templates/subSilver/images/spacer.gif) |
crystal_lattice
Joined: 13 Jun 2006 Posts: 164
|
|
Posted: Sat Nov 01, 2008 6:57 am |
|
|
The PIC will tell you the the physical address but Winhex will give you the logical address (not very logical... i know ) I use a program called FlexHEX www.heaventools.com it has various options/modes in which you can view/load a drive/partition. |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Sat Nov 01, 2008 11:05 am |
|
|
crystal_lattice wrote: | The PIC will tell you the the physical address but win hex will give you the logical address (not very logical... i know ) i use a program called flex |
This is what I was trying to tell Matt - obviously not as clearly as you did. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
![](templates/subSilver/images/spacer.gif) |
matt1971
Joined: 26 Oct 2008 Posts: 15
|
|
Posted: Sat Nov 01, 2008 2:18 pm |
|
|
Thanks for both your help! I'll investigate further. I still dont think the mmcsd.c driver is working properly though. |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Nov 01, 2008 8:10 pm |
|
|
I never tested the mmcsd.c driver, but in v4.057 it contains a bug when it configures the SPI bus for mode 2 while the SD cards only support mode 0 or 3.
Change in mmcsd.c Code: | #use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, IDLE=1, stream=mmcsd_spi) | to
Code: | #use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, mode=0, stream=mmcsd_spi, FORCE_HW)
|
|
|
![](templates/subSilver/images/spacer.gif) |
matt1971
Joined: 26 Oct 2008 Posts: 15
|
|
Posted: Sun Nov 02, 2008 6:26 am |
|
|
I've tried a number of different #USE_SPI settings and none seem to alter that I dont read the correct values from the SD Card. the "FORCE_HW" isnt supported in 4.057
I'm guessing the only way forward on this is to buy a maintenance upgrade to the latest compiler ? |
|
![](templates/subSilver/images/spacer.gif) |
matt1971
Joined: 26 Oct 2008 Posts: 15
|
|
Posted: Sun Nov 02, 2008 6:46 am |
|
|
Having done further tests on this using flexhex, it seems that mmcd.c library looks only at the "Physical" layer (obvious really), and that the "real" boot sector needs to be read from the "logical layer"
So the obvious question now is how to read the logical layer, and not the physical one?
What ultimately concerns me though, is that I'm trying to read/write a FAT drive. Looking at the fat.c driver, it's using the same mmcd.c byte read functions I am, so the fat_init function will NEVER get the correct values it needs. This may explain why so many folds are having problems with the fat.c driver ? |
|
![](templates/subSilver/images/spacer.gif) |
|