|
|
View previous topic :: View next topic |
Author |
Message |
SpoonBilly
Joined: 25 May 2010 Posts: 16
|
PIC18F2553 and SD Card using ex_mmcsd.c |
Posted: Tue May 25, 2010 1:53 am |
|
|
I am not new to PIC18F2553 and CCS compiler, but I am new to PIC+SD/MMC. It is interesting to find that example is available and a lot of people are discussing about it. I gave the "ex_mmcsd.c" a try, and constantly check the SD card memory content using WinHex. I have been successfully read and write data from and into the SD card, but I found out that there is a 0x10E00 shift of the address. For example, if I am to read the data from address 0x00000000, I have to use address = 0x00010E00 to actually read the correct value. Anyone have any idea about this? Thanks.
Details:
Compiler Version: PCWHD 4.093
SD card capacity: 2GB (SanDisk)
SD card cluster size: 512 Byte
SD card file system: FAT32
PIC18F2553 Clock: 20MHz
PIC18F2553 Voltage: 3.3V
Code: | #include <18F2553.h>
#fuses NOWDT, HS, NOPROTECT
#use delay(clock = 20000000)
#use rs232(baud = 57600, xmit = PIN_A0, rcv = PIN_A1, invert)
#include <stdlib.h> // for atoi32
//meda library, a compatable media library is required for FAT.
#use fast_io(b)
#use fast_io(c)
#define MMCSD_PIN_SCL PIN_B1 //o
#define MMCSD_PIN_SDI PIN_B0 //i
#define MMCSD_PIN_SDO PIN_C7 //o
#define MMCSD_PIN_SELECT PIN_C6 //o
#include <mmcsd1.c> // modified mmcsd.c
#include <input.c>
void main(void)
{
BYTE value, value_r, value_w, cmd;
int32 address;
printf("\r\n\nex_mmcsd.c\r\n\n");
if (mmcsd_init())
{
printf("Could not init the MMC/SD!!!!");
while(TRUE);
}
for(address = 0x00010E00; address <= 0x00010E0F; address++)
{
mmcsd_read_byte(address, &value) ;
printf("Add, %lX , Val, %X\n\r", address, value) ;
}
do {
} while (TRUE);
} |
Part of the mmcsd.c was modified as such to fit with hardware SPI of PIC18F2553 and saved as mmcsd1.c:
Code: | #ifndef MMCSD_PIN_SCL
#define MMCSD_PIN_SCL PIN_B1 //o
#define MMCSD_PIN_SDI PIN_B0 //i
#define MMCSD_PIN_SDO PIN_C7 //o
#define MMCSD_PIN_SELECT PIN_C6 //o
#endif |
This is what I observed from WinHex:
_offset__|__value
00000000 EB
00000001 58
00000002 90
00000003 4D
00000004 53
00000005 44
00000006 4F
00000007 53
00000008 35
00000009 2E
0000000A 30
0000000B 00
0000000C 02
0000000D 01
0000000E 7E
0000000F 18
This is what I got from Terminal:
2ex_mmcsd.c
Add, 00010E00 , Val, EB
Add, 00010E01 , Val, 58
Add, 00010E02 , Val, 90
Add, 00010E03 , Val, 4D
Add, 00010E04 , Val, 53
Add, 00010E05 , Val, 44
Add, 00010E06 , Val, 4F
Add, 00010E07 , Val, 53
Add, 00010E08 , Val, 35
Add, 00010E09 , Val, 2E
Add, 00010E0A , Val, 30
Add, 00010E0B , Val, 00
Add, 00010E0C , Val, 02
Add, 00010E0D , Val, 01
Add, 00010E0E , Val, 7E
Add, 00010E0F , Val, 18
Update: 20100525
Tried it with a 1GB SD card (Apacer), FAT32 and cluster size 512 byte. The address shift is 0x0001F200. |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Tue May 25, 2010 10:05 am |
|
|
There is a physical address and a logical address. The logical address is retrieved from the boot record. FAT ( Microsoft copyright) if you were to ask them is probably using logical addresses. Even though Microsoft is the only lawful owner of FAT technology on any platform much information is available in the public domain. Microsoft has made FAT licensing available for $250,000. |
|
|
gogu2000
Joined: 27 Oct 2010 Posts: 3
|
Re: PIC18F2553 and SD Card using ex_mmcsd.c |
Posted: Tue Nov 09, 2010 10:01 am |
|
|
Hello, Please tell me what is your SPI clock. I use this code in a 18f4550 and I have some problem. Address in Winhex is at Offset column? TY. |
|
|
SpoonBilly
Joined: 25 May 2010 Posts: 16
|
Re: PIC18F2553 and SD Card using ex_mmcsd.c |
Posted: Tue Nov 09, 2010 7:08 pm |
|
|
gogu2000 wrote: | Hello, Please tell me what is your SPI clock. I use this code in a 18f4550 and I have some problem. Address in Winhex is at Offset column? TY. |
Not sure what do you mean by SPI clock, I don't think I modified any SPI setting. I'm using 20MHz crystal and delay(clock = 20000000).
Yes. Address in Winhex is at Offset column. |
|
|
|
|
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
|